I have a problem with painless mesh with ADC read whenever I change the potentiometer value in a node mesh network . the network becomes lagging and disconnected. i read on the painless_mesh that delay can make the mesh disconnect and I think that the response to this problem So
How can I fix it ??
here is the gateway code // gateway is the name of the node of esp32 that connected to PC
#include "painlessMesh.h"
#include <Arduino_JSON.h>
#define MESH_PREFIX "Mesh_username"
#define MESH_PASSWORD "mesh_password"
#define MESH_PORT 5555
#define RXD2 16
#define TXD2 17
//String comand ;
#define Analoge_Pin 0
int Node = 1;
String temp_readings;
static int num_comand;
int SENSOR_VLAUE = 0 ;
int sensor_data;
int sel = 0 ;
String sendingmassge;
Scheduler userScheduler;
painlessMesh mesh;
//String obtain_readings () ;
void sendmsg() ;
int nuorder = 0 ;
//int trnsfer_string_to_number_comand(String Enter_String)
//{
// int count = 0, num_comand, tempnum, timper, res, power;
// num_comand = 0;
// if (Enter_String[0] != '\0')
// {
// while (Enter_String[count] != '\0')
// {
// count++;
// }
// tempnum = count - 2 ;
// count = 0 ;
// while (comand[count] != '\0')
// {
//
// timper = comand[count] - '0';
// power = pow(10, (tempnum - count));
// num_comand += (timper * power);
// count++;
// }
// return num_comand;
// }
//}
/*String obtain_readings ()
{
//printf("\nstring comand = %d\n ",num_comand);
JSONVar jsonReadings;
jsonReadings["Node"] = Node;///={"Node":Node,"Temperature":sensor_data}
SENSOR_VLAUE = analogRead(Analoge_Pin);
sensor_data = map(SENSOR_VLAUE, 0, 1023, 0, 100);
jsonReadings["Node1"] = sel;
jsonReadings["Temperature"] = sensor_data ;///sensor value <<<--------
temp_readings = JSON.stringify(jsonReadings);
return temp_readings;
}*/
Task taskSendmsg( TASK_SECOND * 1 , TASK_FOREVER, &sendmsg );
void sendmsg() {
// String msg = obtain_readings();
// mesh.sendBroadcast(msg);
}
void receivedCallback( uint32_t from, String &msg ) {
//Serial.printf("Received from %u msg=%s\n", from, msg.c_str());
JSONVar json_object = JSON.parse(msg.c_str());
int node = json_object["Node"];
double temp = json_object["Temperature"];
Serial.print("person No: ");
Serial.println(node);
Serial.print("\n\r");
Serial.print("pulse rate : ");
Serial.print(temp);
Serial.print("\n\r");
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
mesh.setDebugMsgTypes( ERROR | STARTUP );
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
userScheduler.addTask( taskSendmsg );
taskSendmsg.enable();
}
void loop() {
mesh.update();
// comand = Serial.readString( );//num_comand
// num_comand = trnsfer_string_to_number_comand(comand);
// switch(num_comand)
// {
// case 1 :
// sel = 1 ;
// break;
// default : sel = 0 ;
// }
}
///////////////////////////////////////////////////////////////////////////////////////////
and here is the Sensor node as esp8266 that has a problem
#include "painlessMesh.h"
#include <Arduino_JSON.h>
#define MESH_PREFIX "Mesh_username"
#define MESH_PASSWORD "mesh_password"
#define MESH_PORT 5555
String comand ;
#define Analoge_Pin 0
int Node = 1;
String temp_readings;
int SENSOR_VLAUE = 0 ;
int sensor_data;
Scheduler userScheduler;
painlessMesh mesh;
String obtain_readings () ;
void sendmsg() ;
void ADC_f();
//int trnsfer_string_to_number_comand(String Enter_String)
//{
// int count = 0, num_comand, tempnum, timper, res, power;
// num_comand = 0;
// if (Enter_String[0] != '\0')
// {
// while (Enter_String[count] != '\0')
// {
// count++;
// }
// tempnum = count - 2 ;
// count = 0 ;
// while (comand[count] != '\0')
// {
//
// timper = comand[count] - '0';
// power = pow(10, (tempnum - count));
// num_comand += (timper * power);
// count++;
// }
//
// return num_comand;
// }
//}
String obtain_readings ()
{
JSONVar jsonReadings;
jsonReadings["Node"] = Node;
jsonReadings["Temperature"] = sensor_data ;///sensor value <<<--------
temp_readings = JSON.stringify(jsonReadings);
return temp_readings;
}
Task taskSendmsg( TASK_SECOND * 1 , TASK_FOREVER, &sendmsg );
Task ADC_massage( TASK_SECOND * 1 , TASK_FOREVER, &ADC_f );
void sendmsg() {
String msg = obtain_readings();
mesh.sendBroadcast(msg);
}
void ADC_f()
{
SENSOR_VLAUE = analogRead(Analoge_Pin);
sensor_data = map(SENSOR_VLAUE, 0, 1023, 0, 100);
}
void receivedCallback( uint32_t from, String &msg ) {
//Serial.printf("Received from %u msg=%s\n", from, msg.c_str());
JSONVar json_object = JSON.parse(msg.c_str());
int node = json_object["Node"];
int rev_order = json_object["Node1"];
String revedorder ;
double temp = json_object["Temperature"];
Serial.print("person No: ");
Serial.println(node);
Serial.print("\n\r");
Serial.print("pulse rate : ");
Serial.print(temp);
Serial.print("\n\r");
printf("\norder = %d \n",rev_order);
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
void setup() {
Serial.begin(115200);
mesh.setDebugMsgTypes( ERROR | STARTUP );
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
//mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
userScheduler.addTask( taskSendmsg );
userScheduler.addTask( ADC_massage );
taskSendmsg.enable();
ADC_massage.enable();
}
void loop() {
comand = Serial.readString( );//num_comand
mesh.update();
}