Github Devices Community Docs Blog

Recommended config for using esp32 gpio <-> mqtt?

Hi,
I like to ask what is the recommended configuration if I just want to use gpio pins as inputs. Typically connected to dry contacts, like magnetic door contacts, in the esp32 and send status changes via mqtt?

What to select/enable in

  • platformio.ini (is default_envs = esp32dev-all correct ?)
  • User_config.h (is #define ZsensorGPIOInput “GPIOInput” //ESP8266, Arduino, ESP32 correct ?)

Kind regards, Walter

Hi,

Yes you can use esp32dev-all and remove all the zgateways and zsensor except ZsensorGPIOInput.
You don’t need to modify user_config.h unless you want to apply special parameters.

Thank you very much!

I managed to partly make it work, I have no problems setting output pins on/off but instead of the recommended command ‘{“pin”:15,“cmd”:0}’ I actually have to use ‘{“pin”:15,“state”:0}’
EDIT: seems I used an old version, after project update I now use “cmd”

For inputs I have no success so far so I must be missing something in the project configuration I suspect. Only thing I can see is incoming mqtt messages like “{“adc”:64}”, “{“adc”:0}” etc

  • what gpio pin is used for adc? I have no input named A0 on my esp32

So still to solve is to make the gpio inputs reacting when changing from high/low and vice versa and status changes being reported via mqtt. When I try I do not see anything in the serial monitor either

Question is if I have missed something???

Kind regards, Walter

User_config.h

/-------------DEFINE THE MODULES YOU WANT BELOW----------------/
#define ZactuatorONOFF “ONOFF” //ESP8266, Arduino, ESP32, Sonoff RF Bridge
#define ZsensorADC “ADC” //ESP8266, Arduino, ESP32
#define ZsensorGPIOInput “GPIOInput” //ESP8266, Arduino, ESP32

platformio.ini

[env:esp32dev-all]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp.lib_deps}
build_flags =
${com-esp.build_flags}
‘-DZactuatorONOFF=“ONOFF”’
‘-DZsensorADC=“ADC”’
‘-DZsensorGPIOInput=“GPIOInput”’
‘-DGateway_Name=“OpenMQTTGateway_ESP32_ALL”’

Hello,

Could indicate your esp32 model please ?

You can check in config_ONOFF.h that the pin used correspond to the one you are using.
You can also specify it directly into platformio.ini.

Thank you,

This is the esp32 model I have (see picture)

So what gpio pin do you think is used for adc?
(EDIT: I found out, it is the Sensor VN (GPIO39), next to D34)

It was actually in the config_GPIOinput.h I had to change, so now it is working fine with the input I use

Just thinking, in this code part, would it be possible to add support for several input pins? Right now it can only support one single pin?

/*-------------------PIN DEFINITIONS----------------------*/
#ifndef GPIOInput_PIN
  #if defined(ESP8266) || defined(ESP32)
    #define GPIOInput_PIN 14
  #else
    #define GPIOInput_PIN 7
  #endif
#endif

Great if you found it out!