-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket.io 2.0 Compatibility #40
Comments
Hi, I may try when time permits to check v2.x |
No it does not. At least not as is. I spent half day trying to get it to work, with no success. As soon as i read this post and realized i was running 2.0.1 socket io, i downgraded to 1.4.5 and everything worked great. |
I ordered an ESP32 and will be adding support for this new CPU + socket.io 2.x when I receive it. Thanks for your patience |
Hi, |
Hi, I tried with socket.IO v2.2.0, and now on v2.0.3.. I can't make it work :( 2 days I'm on this and I can't figure it out.. Thanks for your help, On ESP32S
On Node :
In 'index.html' :
|
With the default example, I was experiencing timeout after 20-30 seconds. Then in the JS side (own custom nodejs), I changed the configuration of the server "pingInterval" and "pingTimeout" to one minute and set a timer to trigger a client.heartbeat(1) every 55 seconds. Now it works. |
Thanks, I will try ASAP your solution ;) |
I changed the 'pingTimeout' and 'pingInterval' at 60 000 but with no effect!
|
Snippet of my server code (v.2.2.0, nodejs v.10.4.0): const express = require("express");
const app = express();
const http = require("http").Server(app);
const io = require("socket.io")(http, {
pingInterval: 60000,
pingTimeout: 5000
});
...
io.on("connection", function(socket) {
console.log("Client connected");
socket.on("disconnect", function(reason) {
console.log("Client disconnected: " + reason);
});
// other handlers
...
// finally
http.listen(PORT, () => console.log(`Listening on ${PORT}`)); and for the ESP32S side: #define ESP32
#include <SocketIOClient.h>
SocketIOClient client;
const unsigned char LED_BUILTIN = 2;
const char *ssid = "";
const char *password = "";
char host[] = "your host";
int port = your port;
int i = 0;
hw_timer_t *timer = NULL;
volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t isrCounter = 0;
volatile uint32_t lastIsrAt = 0;
uint32_t isrCount = 0, isrTime = 0;
void IRAM_ATTR onTimer()
{
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
isrCounter++;
lastIsrAt = millis();
portEXIT_CRITICAL_ISR(&timerMux);
// Give a semaphore that we can check in the loop
xSemaphoreGiveFromISR(timerSemaphore, NULL);
// It is safe to use digitalRead/Write here if you want to toggle an output
}
extern String RID;
extern String Rname;
extern String Rcontent;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(9600);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
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");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (!client.connect(host, port))
{
Serial.println("Connection failed");
return;
}
if (client.connected())
{
Serial.println("Connected");
// Create semaphore to inform us when the timer has fired
timerSemaphore = xSemaphoreCreateBinary();
timer = timerBegin(0, 80, true); // Timer0, 80 prescaler, count up
timerAttachInterrupt(timer, &onTimer, true); // timer, callback, edge
timerAlarmWrite(timer, 1000000, true); // timer, count to interrupt at, reload
timerAlarmEnable(timer);
}
}
void loop()
{
// If Timer has fired
if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE)
{
// Read the interrupt count and time
portENTER_CRITICAL(&timerMux);
isrCount = isrCounter;
isrTime = lastIsrAt;
portEXIT_CRITICAL(&timerMux);
// Print it
Serial.print("onTimer no. ");
Serial.print(isrCount);
Serial.print(" at ");
Serial.print(isrTime);
Serial.println(" ms");
if (isrCount % 55 == 0)
{
client.heartbeat(1); // Keep connection alive by sending heartbeat every 55 seconds.
}
}
if (i < 1)
{
Serial.println("************************************** ");
client.send("message", "message", "Some message sent once!");
Serial.println("************************************** ");
i++;
}
if (client.monitor())
{
Serial.println(RID);
if (RID == "message" && Rname == "message")
{
Serial.print("Contents:");
Serial.println(Rcontent);
}
else if (RID == "message" && Rname == "things")
{
Serial.print("Some amount of things ");
Serial.print(Rcontent); // Value of things
Serial.println(" unit of things.");
client.send("message", "message", "Response to things");
}
}
} Hope this helps you, I don't have time for much else right now. |
Thanks for your response, but I did not work with Socket.IO v2.2.0 and Node v10.4.0 with my ESP32S :(
|
Hi,
Silly question, but I wonder if this work with socket.io v2.0. Or should I use socket.io v.1 only on the server?
The text was updated successfully, but these errors were encountered: