[Solved] MySensors WiFi Gateway with NODE-MCU ESP8266 and Capacitive Soil Moisture Sensor : first steps, first errors

  • Hi everyone,

    here I am (again, sorry 😛 ) asking for your guidance.

    After my initial post about “general ideas” with MySensors and I moved on to the next phase: buying all the components.

    I bought two things to start familiarize with this project:

    • A NODE-MCU ESP8266 Development Board vers. 1.0 T
    • A Capacitive Soil Moisture Sensor by DFROBOT V. 1.0

    The idea is to use the NODE-MCU ESP8266 as a WiFi Gateway to collect data from sensor and send it to a controller.

    I divided the project in various stages so to easily troubleshoot problems:

    1st stage: Setting up the NODE-MCU with Capacitive Sensor and reading data
    2nd stage: Setting up the MySensors Wi-Fi Gateway on the NODE-MCU and obtaining “calibrated” data from sensor
    3rd stage: Acquiring the data from stage 2 remotely.

    Thanks to all the guides and tutorial here I’ve been able to set-up my Arduino IDE software with the library to use the NODE-MCU ESP8266 board.

    Following the DFROBOT product tutorial I’ve been able to obtain RAW data from the sensor with this sketch:

    void setup() {
      // put your setup code here, to run once:
    Serial.begin(9600); // open serial port, set the baud rate as 9600 bps
    void loop() {
      // put your main code here, to run repeatedly:
      int val;
      val = analogRead(0); //connect sensor to Analog 0
      Serial.print(val); //print the value to serial port

    Now the problem, for me that I’m a total novice to this, is how to set-up the gateway for doing the same thing.

    I tried with this sketch, also including the calibration needed to obtain usable values from the sensor but I only come up with an error that I could not understand.

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_GATEWAY_ESP8266
    #define MY_ESP8266_SSID "mywifissid"
    #define MY_ESP8266_PASSWORD "mywifipassword"
    // Enable UDP communication
    #define MY_USE_UDP
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_ESP8266_HOSTNAME "sensor-gateway"
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,0,200
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    // The port to keep open on node server mode
    #define MY_PORT 5003
    // How many clients should be able to connect to this gateway (default 1)
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 75
    // Enable inclusion mode
    // Enable Inclusion mode button on gateway
    // Set inclusion mode duration (in seconds)
    // Digital pin used for inclusion mode button
    // Set blinking period
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    // Flash leds on rx/tx/err
    // Led pins used if blinking feature is enabled above
    //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    #if defined(MY_USE_UDP)
    #include <WiFiUdp.h>
    #include <ESP8266WiFi.h>
    #define CHILD_ID 0
    #include <MySensors.h>
    // values needed for calibrating the sensor output
    int AirValue = 694;
    int WaterValue = 344;
    int intervals = (AirValue - WaterValue)/3; 
    int soilMoistureValue = 0;
    MyMessage msg(CHILD_ID, V_LEVEL);
    unsigned long SLEEP_TIME = 30000;
    int sensorPin = A0;
    void presentation()
    	// Present locally attached sensors here
      present(CHILD_ID, S_MOISTURE);
    void loop()
    	// Send locally attached sensors data here
    int soilMoistureValue;
    soilMoistureValue = analogRead(sensorPin);
    if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
      send(msg.set("Very WET"));
    else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
    else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))

    When compiling this code using the MySensors Library v. 2.1.1 ,I receive an error code: I'm sure it's because I'm doing something wrong out of inexperience so I hope if someone among the most experienced users here could help me out...

  • Mod

    @Neo-Mod posting the actual error could be very useful 😉

  • Mod

    Was the error

    error: no match for 'operator[]' (operand types are 'inputBuffer' and 'int')

    in that case, my google-fu took me to https://github.com/mysensors/MySensors/issues/369 which has been fixed in 2.2.0-beta.

    Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Micke\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi 
    Using library MySensors at version 2.2.0-beta in folder: R:\Documents\Arduino\libraries\MySensors 
    Using library EEPROM at version 1.0 in folder: C:\Users\Micke\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\EEPROM 
    Sketch uses 236,893 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
    Global variables use 32,944 bytes (40%) of dynamic memory, leaving 48,976 bytes for local variables. Maximum is 81,920 bytes.

    So either use 2.2.0-beta or wait for the next stable release.

  • Oh my...sorry, my mistake! I forgot to paste it on the message, thank you for your patience.

    Here it is the error: there are some small parts in italian at the end regarding the WiFi Library used. If needed I can translate those.

    Arduino:1.8.3 (Windows 10), Scheda:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, 9600, 4M (3M SPIFFS)"
    In file included from D:\NeoMod\Documents\Arduino\libraries\MySensors/MySensors.h:200:0,
                     from D:\NeoMod\Documents\Arduino\prova_gateway\prova_gateway.ino:135:
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportAvailable()':
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:302:35: error: no match for 'operator[]' (operand types are 'inputBuffer' and 'int')
       _ethernetServer.read(inputString[0].string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:303:14: error: no match for 'operator[]' (operand types are 'inputBuffer' and 'int')
       inputString[0].string[packet_size] = 0;
    In file included from D:\NeoMod\Documents\Arduino\libraries\MySensors/MySensors.h:28:0,
                     from D:\NeoMod\Documents\Arduino\prova_gateway\prova_gateway.ino:135:
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:304:55: error: no match for 'operator[]' (operand types are 'inputBuffer' and 'int')
       debug(PSTR("UDP packet received: %s\n"), inputString[0].string);
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MySensorsCore.h:90:40: note: in definition of macro 'debug'
     #define debug(x,...) hwDebugPrint(x, ##__VA_ARGS__)   //!< debug, to be removed (follow-up PR)
    In file included from D:\NeoMod\Documents\Arduino\libraries\MySensors/MySensors.h:200:0,
                     from D:\NeoMod\Documents\Arduino\prova_gateway\prova_gateway.ino:135:
    D:\NeoMod\Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:305:58: error: no match for 'operator[]' (operand types are 'inputBuffer' and 'int')
       const bool ok = protocolParse(_ethernetMsg, inputString[0].string);
    Più di una libreria trovata per "WiFiUdp.h"
    Usata: C:\Users\deimo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi
    Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
    Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
    Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
    Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
    exit status 1
    Errore durante la compilazione per la scheda NodeMCU 1.0 (ESP-12E Module).

  • @mfalkvidd thank you! I didn't noticed that among the whole log, my ignorance about this just kicked-in. Thank you again fo your help, I'll read on how to set the beta library and compile again.