ESP8266 painlessmesh + WebSocketsClient help

Hello guys
i have a problem with my script and i eat my days with it
i’m trying to make a esp8266 mesh with painless mesh, all set, all works as i would like, but i would like to add a webpage to log all the data and change the parameters of nodes so i’ve ended up trying to add a WebSocketsClient to create a socket client and connect to a socketserver created in php.

First i’ve tried if the socket server works with WebSocketsClient library, and yes, it works all fine and dandy but when i add the WebSocketsClient to the mesh script…well…i get lots of disconnects

Can please anybody who have experience with painless mesh hint me how can i fix it because i have no idea, i guess the mess disconnects the socket every time when it’s some activity on it, but that’s only my guess and i have no idea how to fix it

My setup should have structure as this

Bridge(includes the mesh root and creates the web socket client)
Nodes(just simple mesh nodes)

What i’m trying to do is to get the data from nodes, store it in a list in bridge and send it to socket every time is there a change on mesh or bridge request it

Working socket client script

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include “ArduinoJson.h”

#include <WebSocketsClient.h>

#include <Hash.h>

ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
DynamicJsonDocument doc(2048);

int increment = 0;
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %s\n", payload);

// send message to server when Connected
webSocket.sendTXT("{“type”:“usermsg”,“name”:“ESP”,“message”:“i’m here”,“color”:"#CF0000"}");
}
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
deserializeJson(doc, payload);
if (doc[“type”] != “system”) {
if (doc[“name”] != “ESP”) {
increment++;
webSocket.sendTXT("{“type”:“usermsg”,“name”:“ESP”,“message”:“i’m here #” + String(increment) + “”,“color”:"#CF0000"}");

}
}

// send message to server
// webSocket.sendTXT(“message here”);
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
hexdump(payload, length);

// send data to server
// webSocket.sendBIN(payload, length);
break;
case WStype_PING:
// pong will be send automatically
Serial.printf("[WSc] get ping\n");
break;
case WStype_PONG:
// answer to a ping we send
Serial.printf("[WSc] get pong\n");
break;
}

}

void setup() {
// Serial.begin(921600);
Serial.begin(115200);

//Serial.setDebugOutput(true);
Serial.setDebugOutput(true);

Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t–) {
Serial.printf("[SETUP] BOOT WAIT %d…\n", t);
Serial.flush();
delay(1000);
}

WiFiMulti.addAP(“xxxx”, “xxxx”);

//WiFi.disconnect();
while (WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}

// server address, port and URL
webSocket.begin(“192.168.100.100”, 9000, “/proiect.kyme32.ro/socket/server.php”);

// event handler
webSocket.onEvent(webSocketEvent);

// use HTTP Basic Authorization this is optional remove if not needed
//webSocket.setAuthorization(“user”, “Password”);

// try ever 5000 again if connection has failed
webSocket.setReconnectInterval(5000);

// start heartbeat (optional)
// ping server every 15000 ms
// expect pong from server within 3000 ms
// consider connection disconnected if pong is not received 2 times
//webSocket.enableHeartbeat(15000, 3000, 2);

}

void loop() {
webSocket.loop();
}

painless mesh + websocketclient

#include “painlessMesh.h”
#include <WebSocketsClient.h>

#define MESH_PREFIX “meshid”
#define MESH_PASSWORD “meshpass”
#define MESH_PORT 5555

#define STATION_SSID “xxxx”
#define STATION_PASSWORD “xxxx”
#define STATION_PORT 5555
uint8_t station_ip[4] = {192, 168, 100, 150}; // IP of the server
int increment = 0;

DynamicJsonDocument doc(2048);
painlessMesh mesh;
WebSocketsClient webSocket;

void setup() {
Serial.begin(115200);
mesh.setDebugMsgTypes(ERROR | STARTUP | COMMUNICATION);
mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT, WIFI_AP_STA, 6 );
mesh.stationManual(STATION_SSID, STATION_PASSWORD, STATION_PORT, station_ip);
mesh.setRoot(true);
mesh.setContainsRoot(true);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onReceive(&receivedCallback);

webSocket.begin(“192.168.100.100”, 9000, “/socket/server.php”);
webSocket.onEvent(webSocketEvent);
webSocket.setReconnectInterval(1000);
}

void loop() {
webSocket.loop();
mesh.update();
}

void receivedCallback( uint32_t from, String &msg ) {
Serial.printf(“bridge: Received from %u msg=%s\n”, from, msg.c_str());
}
void changedConnectionCallback() {
mesh.sendBroadcast(“GIVE DATA”);
}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket.sendTXT("{“type”:“usermsg”,“name”:“ESP”,“message”:“i’m here”,“color”:"#CF0000"}");
}
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
deserializeJson(doc, payload);
if (doc[“type”] != “system”) {
if (doc[“name”] != “ESP”) {
increment++;
webSocket.sendTXT("{“type”:“usermsg”,“name”:“ESP”,“message”:“i’m here #” + String(increment) + “”,“color”:"#CF0000"}");

}
}
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
hexdump(payload, length);
break;
case WStype_PING:
Serial.printf("[WSc] get ping\n");
break;
case WStype_PONG:
Serial.printf("[WSc] get pong\n");
break;
}

}

i’ve attashed the console logs from painlessmesh +websocket client script

is there any solution to add websocket to painless mesh?
thank you!

logs.txt (18.9 KB)