I have an ESP-01 board and am trying to read the value of GPIO0. The SDK documentation says this:
GPIO_INPUT_GET(gpio_no)
but I don't understand what I should write in place of gpio_no. I have tried simply 0, GPIO0, BIT0, none of these work.
Also, what should I expect to receive? Do I need to mask the result?
This is my current code, the interrupt handler:
void gpio0_int_handler(uint32_t *args)
{
// Disable GPIO interrupts while we set them up
ETS_GPIO_INTR_DISABLE();
// Interrupt on NO edge
gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_DISABLE);
// Record status of button
int status;
status = GPIO_INPUT_GET(0);
uint32 gpio_status;
gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
MQTT_Client* client = (MQTT_Client*)args;
// Publish message to MQTT
if (status==0)
MQTT_Publish(client, "viktak/test", "Switch CLOSED.", 14, 2, 0);
else
MQTT_Publish(client, "viktak/test", "Switch OPEN.", 14, 2, 0);
os_delay_us(5000);
//clear interrupt status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
// Interrupt on any edge
gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_ANYEDGE);
// Enable GPIO interrupts
ETS_GPIO_INTR_ENABLE();
}
The interrupt handler (apart from testing for the GPIO state) works perfectly.
Any directions greatly appreciated
http://diy.viktak.com