Menu

ESPNOW not transferring data

2022-07-15
2022-07-17
  • Leonard Royles

    Leonard Royles - 2022-07-15

    Hi Robert,
    Firmware from latest 129-04 but same with earlier releases. I have two modules,

    Master has Examples mysqmplus-128-35-EX1-01 set up with Station Mode, Static IP, etc and has GPS, MLX90614, TSL2591 and RTC. All working and values displaying via Win10 management window as well as web page. BME280 specifically not defined.

    Slave has Examples myESP32DB-BME280-EX1-v06 also set up with Station Mode, Static IP etc. Has just BME280 enabled although there are other sensors present but not selected.

    If I start both up with ESPNOW disabled then I see both boards at their IP address websites. Sensors all working. Master showing BME280's as presets. If I enable ESPNOW then after a short interval the Slave loses its web presence.
    Master serial monitor shows a ESPNOW data rcv'd message if Slave restarted but no data change for Master, still displays preset values. Master serial monitor shows a repeat of 'parse_gga start', 'parse_gll start', 'parse_rmc start', 'parse_gsa start' messages......
    I have double checked MAC address for both modules using my router info and standalone programs. I have run tutorial ESPNOW programs successfully but don't seem to get mySQM+ ESPNOW running.

    Examples myESP32DB-BME280-EX1-v06 has a compiler error if I use myBME280e, so changed to myBME280d, compiles and seems to work OK. Is this perhaps implicated?
    Line 642 mybme280.readData();
    exit status 1 'class bme280e' has no member named 'readData'; did you mean 'read8'?

    Any pointers please?
    Thanks
    Len

     
    • brownrb

      brownrb - 2022-07-16

      Hi Len

      I would probably try mySQMPLUS-120-EX1-01 on the master instead of the 128

      the myESP32DB-BME280-EX1-v06 is trying to use mybme280d
      I attach this

      Since we are now at v129, and thery are still at 120, hmmm
      Since then mysqm+ has migrated away from mybme280x libraries
      The esp32DB daughter board code did not.

      " If I enable ESPNOW then after a short interval the Slave loses its web presence. "

      Have not seen this myself. It may have something to do with the WiFI channel.

      esp now tries to use the same wifi channel as the controller. It does have issues running on channels 2 upwards. And espnow declarations must preceed any references to wifi
      hence in the main .ino file you see this

      #if defined(ENABLEESPNOW)
      #include <esp_now.h>
      #endif
      
      #include <Arduino.h>
      #include <WiFiServer.h>
      #include <WiFiClient.h>
      

      noting that include for esp_now must come first.

      The purpose of this code in setup() is to get the channel for espnow
      wifichannel = 0; // channel information
      // If "channel" is 0, there will be an all-channel scan; otherwise, there will be a specific-channel scan.
      wifichannel = WiFi.channel(); // save channel number

      and this little snippet of code in the main firmware file myespnow
      // register the slave device
      memcpy(slavedevice.peer_addr, slave_macaddress, 6);
      slavedevice.channel = wifichannel;
      slavedevice.encrypt = false;

      sets up espnow to use the channel. The very early code did not have that in setup() and we noticed that espnow was flaky at best. We had better results when that code was added. We meaning others on a test group at the time. And from memory success was only found on channel 0

      I do know a user that has used espnow between devices for some time, but I believe they migrated to JSON instead. I will try and find out.

      Note that the espnow takes over the wifi side and uses its own method of sending a message to a master (or slave). The same frequency is used BUT is not a WiFI type signal.

      Yes, there are issues with espnow that you have discovered. Espnow works great between all the devices, but, when Wifi is added, then they are all competing for bandwidth on the same frequencies

      The JSON method is much better, range is about the same, and because it uses Wifi there are not any competition issues.

      Master serial monitor shows a ESPNOW data rcv'd message if Slave restarted but no data change for Master, still displays preset values. Master serial monitor shows a repeat of 'parse_gga start', 'parse_gll start', 'parse_rmc start', 'parse_gsa start' messages......

      yes, would indicate that the debug output of gps messages is enabled

      in file mydefines.h change the enabling of debug messages

      // Remove comment to enable initialise messages to Serial port       
      //#define INITMSGDEBUG       1
      // Remove comment to enable info messages to Serial Port (non critical errors)
      //#define INFOMSGDEBUG       1
      // Remove comment to enable initialise messages to Serial port       
      //#define WARNINGMSGDEBUG    1
      // Remove comment to enable error messages to Serial port
      //#define ERRORMSGDEBUG      1  
      

      that will tuen off the messages

       
  • Leonard Royles

    Leonard Royles - 2022-07-16

    Interestingly one of the standalone ESPNOW (not wifi) tutorials only worked when the channel number was either 0 or 1. My home 2.4ghz channel is currently channel 3 because of conflicts. Trying it on 1 made no difference to the mySQM+ operation.

     
  • Leonard Royles

    Leonard Royles - 2022-07-16

    If I enable the ESPNOW debug on the Master I get:
    init espnow
    ESPNOW init
    Ok
    slave device add ok
    ESPNOW callback added

    .................... etc in the serial monitor.

    On the Slave in mydefines debug I get:
    process page done
    STARTED
    Sending message via ESPNOW now
    Data send successful
    Send successful
    Sending message via ESPNOW now
    Data send successful
    Sending message via ESPNOW now
    Data send successful
    Sending message via ESPNOW now
    Data send successful
    Sending message via ESPNOW now
    Data send successful
    Sending message via ESPNOW now
    Data send successful

    However I only get one message on Master of:
    ESPNOW data rcv'd

     
    • brownrb

      brownrb - 2022-07-16

      check the main ino file

          case state_espnowcheck:
      #if defined(ENABLEESPNOW)
            if ( slavemessagereceived == true )                               // process any communication from espnow
            {
              ambient  = slavemessage.temperature;
              humidity = slavemessage.humidity;
              pressure = slavemessage.pressure;
              dewpoint = slavemessage.dewpoint;
              // Note: after processing the message, set the flag to false
              slavemessagereceived = false;
            }
      #endif // #if defined(ENABLEESPNOW)
            MainStateMachine = state_ntpclientupdate;
            break;
      

      and make sure that the line
      slavemessagereceived = false;
      is there. you can also add a serial.println here like

        if ( slavemessagereceived == true )                               // process any communication from espnow
        {
        Serial.println("master: espnow msg arrived");
          ambient  = slavemessage.temperature;
          humidity = slavemessage.humidity;
          pressure = slavemessage.pressure;
          dewpoint = slavemessage.dewpoint;
          // Note: after processing the message, set the flag to false
          slavemessagereceived = false;
        }
      

      ~~~

       
    • brownrb

      brownrb - 2022-07-17

      I cant see the time information for these messages

      Please zip up the files you are using for slave and master and send them to me

      regards
      Robert

       
  • brownrb

    brownrb - 2022-07-16

    I seem to recall that one can print things out, (change DebugPrint to Serial.print) like

    // callback for receiving data via ESPNOW from SLAVE device
    void espnow_datareceived(const uint8_t *mac_addr, const uint8_t *recdata, int len)
    {
      DebugPrintln("Data received via ESPNOW");
      memcpy(&slavemessage, recdata, sizeof(slavemessage));
      DebugPrint("Bytes received: ");
      DebugPrintln(len);
      DebugPrint("From: ");
      // there are 12 bytes in the mac address
      for ( int lp = 0; lp < 6; lp++ )
      {
        byte c = mac_addr[lp];
        if ( c == 0x00 )
        {
          DebugPrint("00");
        }
        else if ( c < 0x10 )
        {
          DebugPrint("0");
          DebugPrint(c, HEX);
        }
        else
        {
          DebugPrint(c, HEX);
        }
        DebugPrint(" ");
      }
      DebugPrintln();
    
    }
    

    I would be temped to also do that to the daughter board sending of espnow, to verify that it is actually sending the data over and over (it might be a null message?)

     
  • Leonard Royles

    Leonard Royles - 2022-07-16

    Added print messages to Slave, I get 7 or 8 success and then rest unsuccessful:
    Data send successful
    Sending message via ESPNOW now
    Ambient: 23.96
    Humidity: 48.09
    Data send successful
    Data send successful
    Sending message via ESPNOW now
    Ambient: 23.96
    Humidity: 48.09
    Data send successful
    Data send successful
    Sending message via ESPNOW now
    Ambient: 23.96
    Humidity: 48.07
    Data send NOT successful
    Data send NOT successful
    Sending message via ESPNOW now
    Ambient: 23.97
    Humidity: 48.07
    Data send NOT successful
    Data send NOT successful
    Sending message via ESPNOW now
    Ambient: 23.97
    Humidity: 48.07
    Data send NOT successful
    Data send NOT successful

    Tried print messages for Master but never got anything regarding successful data transfer.

    I guess it's time to move on, I will have a go at the JSON stuff instead!
    Many Thanks for your help
    Regards
    Len

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.