WiFi mesh using ESP8266 Arduino library EasyMesh (receiving problem).

Actually, I am making the network using two ESPs at present. One has sensor BME280 connected and the other one receives the data. The problem is the routine mesh.sendBroadcast(something) evaluates to TRUE but on the receiver side I don’t see anything. On my serial monitor I see only blank stuffs which actually scrolls down. Do I receive anything? actually void receivedCallback cannot be checked weather it is TRUE or FALSE.

What could I do to check weather I receive something on receiver ESP? Any Idea?

Any Idea?

Must Be A Problem In Your Code.

I am sure that my my transmitter is sending the message but my receiver ESP is not receiving it so I am uploading the receiver code… There are some functions which are called when something is received…

//The file ON the Client ESP side to receive the sensor data sent from the server side.
  
#include <easyMesh.h>
#include <easyMeshSync.h>
#include <SimpleList.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define   MESH_PREFIX     "WKI"
#define   MESH_PASSWORD   "WKI1234"
#define   MESH_PORT       5555

Adafruit_BME280 bme; // I2C

const char* ssid = "AndroidAP";
const char* password = "sadbhavna12";

uint32_t ID;
String msg,msg1,msg2,msg3,msg4,msgFinal,xyz;

// Web Server on port 80
WiFiServer server(80);

easyMesh mesh;

static void (*receivedCallback)( uint32_t ID, String &msg);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);
  Wire.begin(D3, D4);
  Wire.setClock(100000);
  mesh.setDebugMsgTypes( ERROR | STARTUP );  // set before init() so that you can see startup messages

  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT);  
  ID=system_get_chip_id();  
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  mesh.setReceiveCallback(receivedCallback);  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
     
}


void loop() {

  // put your main code here, to run repeatedly:
  mesh.update();
  void newConnectionCallback( bool adopt );             
  delay(100);
//  void receivedCallback( uint32_t ID, String &xyz) ;
  void receivedCallback( uint32_t ID, String &msgFinal);
    //Serial.printf("startHere: Received from %d",ID);
    Serial.println(msgFinal);//I see only blank screen on my serial monior which scrolls down.....!!!
    
  msg=msgFinal.substring(0,7);
  msg1=msgFinal.substring(7,13);
  msg2=msgFinal.substring(13,19);
  msg3=msgFinal.substring(19,26);
  msg4=msgFinal.substring(26,32);
  Serial.println(xyz);
 
   // Listenning for new clients
  WiFiClient client = server.available();
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {
//            getWeather();
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head><META HTTP-EQUIV=\"refresh\" CONTENT=\"15\"></head>");
            client.println("<body><h1>ESP8266 Weather Web Server</h1>");
            client.println("<table border=\"2\" width=\"456\" cellpadding=\"10\"><tbody><tr><td>");
            client.println("<h3>Temperature = ");
            client.println(msg);
            client.println("&deg;F</h3><h3>Humidity = ");
            client.println(msg1);
            client.println("%</h3><h3>Approx. Dew Point = ");
            client.println(msg2);
            client.println("&deg;F</h3><h3>Pressure = ");
            client.println(msg3);
            client.println("hPa (");
            client.println(xyz);
            client.println("Inch)</h3></td></tr></tbody></table></body></html>");  
            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
}

I have checked some examples and tried to find the mistakes. There is a confussion in my mind regarding the callback routines setReceiveCallback which is bassically there for receiving data. Meanwhile I am uploading two codes one is with error. the error is as follows

receivedCallback was not declared in this scope.

But the other code also doesnot declare receivedCallback but it compiles without error.

//The file ON the Client ESP side to receive the sensor data sent from the server side.
  
#include <easyMesh.h>
#include <easyMeshSync.h>
#include <SimpleList.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define   MESH_PREFIX     "WKI"
#define   MESH_PASSWORD   "WKI1234"
#define   MESH_PORT       5555

//Adafruit_BME280 bme; // I2C

const char* ssid = "AndroidAP";
const char* password = "sadbhavna12";

uint32_t ID;
String msg,msg1,msg2,msg3,msg4,msgFinal,xyz;

// Web Server on port 80
WiFiServer server(80);

easyMesh mesh;

//static void (*receivedCallback)( uint32_t ID, String &msgFinal);[color=red]IF I DECLARE THIS THEN NO ERROR BUT I WANT TO COMMENT IT FOR DEBUGGING PURPOSE[/color]
static void (*newConnectionCallback);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);
  Wire.begin(D3, D4);
  Wire.setClock(100000);
  mesh.setDebugMsgTypes( ERROR | STARTUP );  // set before init() so that you can see startup messages

  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT);  
  ID=system_get_chip_id();  
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  mesh.setReceiveCallback( &receivedCallback );  [color=red]//ERROR IS HERE[/color]
 // mesh.setNewConnectionCallback(newConnectionCallback);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
     
}

void receivedCallback( uint32_t ID, String &msgFinal);

void loop() {

  // put your main code here, to run repeatedly:
  mesh.update();
  void newConnectionCallback( bool adopt );             
  delay(100);
//  void receivedCallback( uint32_t ID, String &xyz) ;
  
    delay(100);

    //Serial.printf("startHere: Received from %d",ID);
    //Serial.println(msgFinal);
    
  msg=msgFinal.substring(0,7);
  msg1=msgFinal.substring(7,13);
  msg2=msgFinal.substring(13,19);
  msg3=msgFinal.substring(19,26);
  msg4=msgFinal.substring(26,32);
  Serial.println(xyz);
   Serial.println(msg);

   // Listenning for new clients
  WiFiClient client = server.available();
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {
//            getWeather();
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head><META HTTP-EQUIV=\"refresh\" CONTENT=\"15\"></head>");
            client.println("<body><h1>ESP8266 Weather Web Server</h1>");
            client.println("<table border=\"2\" width=\"456\" cellpadding=\"10\"><tbody><tr><td>");
            client.println("<h3>Temperature = ");
            client.println(msg);
            client.println("&deg;F</h3><h3>Humidity = ");
            client.println(msg1);
            client.println("%</h3><h3>Approx. Dew Point = ");
            client.println(msg2);
            client.println("&deg;F</h3><h3>Pressure = ");
            client.println(msg3);
            client.println("hPa (");
            client.println(xyz);
            client.println("Inch)</h3></td></tr></tbody></table></body></html>");  
            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
}

Now the code without error

//************************************************************
// this is a simple example that uses the easyMesh library
//
// 1. blinks led once for every node on the mesh
// 2. blink cycle repeats every BLINK_PERIOD
// 3. sends a silly message to every node on the mesh at a random time betweew 1 and 5 seconds
// 4. prints anything it recieves to Serial.print
// 
//
//************************************************************
#include <easyMesh.h>

// some gpio pin that is connected to an LED... 
// on my rig, this is 5, change to the right number of your LED.
#define   LED             5       // GPIO number of connected LED

#define   BLINK_PERIOD    1000000 // microseconds until cycle repeat
#define   BLINK_DURATION  100000  // microseconds LED is on for

#define   MESH_PREFIX     "whateverYouLike"
#define   MESH_PASSWORD   "somethingSneeky"
#define   MESH_PORT       5555

easyMesh  mesh;

uint32_t sendMessageTime = 0;

void setup() {
  Serial.begin(115200);
    
  pinMode( LED, OUTPUT );

//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
  mesh.setDebugMsgTypes( ERROR | STARTUP );  // set before init() so that you can see startup messages

  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT );
  mesh.setReceiveCallback( &receivedCallback );//[color=red]HERE NO ERROR WHY? GIVE IT!![/color]
  mesh.setNewConnectionCallback( &newConnectionCallback );

  randomSeed( analogRead( A0 ) );  
}

void loop() {
  mesh.update();

  // run the blinky
  bool  onFlag = false;
  uint32_t cycleTime = mesh.getNodeTime() % BLINK_PERIOD;
  for ( uint8_t i = 0; i < ( mesh.connectionCount() + 1); i++ ) {
    uint32_t onTime = BLINK_DURATION * i * 2;    

    if ( cycleTime > onTime && cycleTime < onTime + BLINK_DURATION )
      onFlag = true;
  }
  digitalWrite( LED, onFlag );

  // get next random time for send message
  if ( sendMessageTime == 0 ) {
    sendMessageTime = mesh.getNodeTime() + random( 1000000, 5000000 );
  }

  // if the time is ripe, send everyone a message!
  if ( sendMessageTime != 0 && sendMessageTime < mesh.getNodeTime() ){
    String msg = "Hello from node ";
    msg += mesh.getChipId();
    mesh.sendBroadcast( msg );
    sendMessageTime = 0;
  }
}

void receivedCallback( uint32_t from, String &msg ) {
  Serial.printf("startHere: Received from %d msg=%s\n", from, msg.c_str());
}

void newConnectionCallback( bool adopt ) {
  Serial.printf("startHere: New Connection, adopt=%d\n", adopt);
}

I have been successful in being able to combine the examples of LogServer and LogClient, of the called development painlessMesh, that is an evolved version of easy_mesh, along with the client code that you offer.
The logclient sends simulated data from a sensor.

//************************************************************
// this is a simple example that uses the painlessMesh library to 
// setup a single node (this node) as a logging node
// The logClient example shows how to configure the other nodes
// to log to this server
//************************************************************
#include "painlessMesh.h"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>

#define   MESH_PREFIX     "urmeshserver"
#define   MESH_PASSWORD   "urpswdmesh"
#define   MESH_PORT       5555

const char* ssid = "urrouterssid";
const char* password = "urrouterpswd";
WiFiServer server(80);


painlessMesh  mesh;

// Send my ID every 10 seconds to inform others
Task logServerTask(10000, TASK_FOREVER, []() {
    DynamicJsonBuffer jsonBuffer;
    JsonObject& msg = jsonBuffer.createObject();
    msg["topic"] = "logServer";
    msg["nodeId"] = mesh.getNodeId();

    String str;
    msg.printTo(str);
    mesh.sendBroadcast(str);

    // log to serial
    msg.printTo(Serial);
    Serial.printf("\n");
});


void setup() { 

  Serial.begin(115200);         
  //mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE | DEBUG ); // all types on
  //mesh.setDebugMsgTypes( ERROR | CONNECTION | SYNC | S_TIME );  // set before init() so that you can see startup messages
  mesh.setDebugMsgTypes( ERROR | CONNECTION | S_TIME );  // set before init() so that you can see startup messages

  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT, STA_AP, AUTH_WPA2_PSK, 6 );
  mesh.onReceive(&receivedCallback);

  mesh.onNewConnection([](size_t nodeId) {
    Serial.printf("New Connection %u\n", nodeId);
  });

  mesh.onDroppedConnection([](size_t nodeId) {
    Serial.printf("Dropped Connection %u\n", nodeId);
  });

  // Add the task to the mesh scheduler
  mesh.scheduler.addTask(logServerTask);
  logServerTask.enable();

  Serial.print("Connecting to ");
  Serial.println(ssid); 
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}

void loop() {
    
  mesh.update(); 

   WiFiClient client = server.available();
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {
           client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head><META HTTP-EQUIV=\"refresh\" CONTENT=\"15\"></head>");
            client.println("<body><h1>ESP8266 Weather Web Server</h1>");
            client.println("</body></html>");  
            break;
        }
        }
    }
  }
}

void receivedCallback( uint32_t from, String &msg ) {
  Serial.printf("logServer: Received from %u msg=%s\n", from, msg.c_str());
}

Hello omguzman ,

I've tried your sketch , but all I get is a system crash on the server side .. ( exception .... ) .
I'm using mcunodes v.2 and rel 2.3 on arduino Ide .. ( both server and client )

My final target is a small mesh network exchanging logical values ( status/messages ) AND connected to home wireless router .

Can you give some hint / suggestion on how solve the issue ?