GPIO.read() not working

  1. My goal is:I am using ESP32. I am working with inbuilt led on GPIO 2. I want to read the level of pin.
  2. My actions are:
let led = 2;
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
GPIO.write(led, 0);
Timer.set(1000, true, function(){
print(GPIO.read(led)==0);
 if (GPIO.read(led)==0){
GPIO.write(led, 0);
 }
else{
GPIO.write(led, 1);
 }}, null);
  1. The result I see is: the print statement only printing ‘0’ on console although led light is on.
  2. My expectation & question is: what’s wrong with code and why GPIO.read() not working properly?

GPIO.read does not read a output.
You need to export mgos_gpio_read_out into mJS.
Export custom function

I am new to mongoose os development, can you please explain in detail?
thanks in advance.

Read export custom function first.

just one doubt, what is

extern "C"

declaration in main.c ?