hello im trying to make this simple program to work
#include <SocketIoClient.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
SocketIoClient webSocket;
void checkHeap() {
Serial.print("heap: ");
Serial.println(ESP.getFreeHeap());
}
void ConnectedToIO(const char* payload, size_t length) {
Serial.printf("connected to webSocket\n");
for (int i = 0; i < 128; i++) {
checkHeap();
webSocket.emit("helloUser", "{ \"id\": \"abc\"}\0");
delay(1000);
}
}
void event(const char* payload, size_t length) {
USE_SERIAL.printf("got message: %s\n", payload);
}
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
wifi_set_sleep_type(NONE_SLEEP_T);
pinMode(LED_BUILTIN, OUTPUT);
for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("xxxxxx", "xxxxx");
webSocket.on("connect", ConnectedToIO);
webSocket.begin("192.168.1.102", 1337);
}
void loop() {
while (WiFiMulti.run() == WL_CONNECTED) {
webSocket.loop();
}
}
i am using GitHub - timum-viw/socket.io-client: A socket.io-client implementation for ESP8266 and Arduino as socketio library
at the begining this program worked correct but now it does not emit the message
it does trying to emit 128 requests then it restarts it self and the messages are sent while it restarts it self
example:
[SIoC] add packet 42["helloUser",{ "id": "abc"}]
heap: 42048
[SIoC] add packet 42["helloUser",{ "id": "abc"}]
heap: 42008
[SIoC] add packet 42["helloUser",{ "id": "abc"}]
heap: 41968
[SIoC] add packet 42["helloUser",{ "id": "abc"}]
heap: 41928
[SIoC] add packet 42["helloUser",{ "id": "abc"}]
[SIoC] Disconnected!
[SIoC] Connected to url: /socket.io/?transport=websocket
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted
[SIoC] packet "42["helloUser",{ "id": "abc"}]" emitted