1

I am facing problems while connecting to my SocketIo server through my ESP8266. I have my ESP connected to my Wifi and my Node Server is running on localhost. I have the following code in ESP8266

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <SocketIoClient.h>


//192.168.1.37 --My IP Address

SocketIoClient webSocket;

const char* ssid     = "ssid";      // SSID
const char* password = "pass";        // Password
const char* host = "192.168.1.37";        // Server IP (localhost)
const int   port = 8080;                  // Server Port
const char* url = "http://localhost:8080/test";

void event(const char * payload, size_t length) {
  Serial.println("Message");
}

void setup() {
  Serial.begin(115200);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);     // 5ms Delay
    Serial.print(".");

  }

  Serial.print("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("Connecting To Socket");
  webSocket.on("event", event);
  webSocket.begin("192.168.1.37", 8080);

}

void loop() {

  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
     delay(3000);    //Send a request every 3 seconds  
     webSocket.loop();
     Serial.println("Retrying ....");
}

Also my Server side code is in JavaScript.

var io = socket(server);
io.on('connection', (socket) => {
    console.log('made socket connection', socket.id);
    socket.on("ESP", function(data){
        socket.emit('Hi ESP, ESP called', data);
        console.log("Socket Working !");
    });
    console.log('made socket connection', socket.id);
    socket.on("connect", function(data){
        socket.emit('Hi ESP connect called', data);
        console.log("Socket Working !");
    });

});

But i keep on receiving this output in the Serial Monitor. Also there is no request received on my server.

11:37:09.729 -> ..........WiFi connected
11:37:14.129 -> IP address: 
11:37:14.129 -> 192.168.1.13
11:37:14.129 -> Connecting To Socket
11:37:17.245 -> Retrying ....
11:37:17.245 -> [SIoC] Disconnected!
11:37:17.245 -> [SIoC] event disconnected not found. 1 events available
11:37:20.230 -> Retrying ....
11:37:20.230 -> [SIoC] Disconnected!
11:37:20.230 -> [SIoC] event disconnected not found. 1 events available

3 Answers 3

3

i have same issue

[SIoC] Disconnected!
[SIoC] Connected to url: /socket.io/?transport=websocket
[SIoC] Disconnected!
[SIoC] Disconnected!
[SIoC] Disconnected!

i change server side socket io config to this :

const io = require("socket.io")(server, {
cors: {
 origin: "*",
 methods: ["GET", "POST"],
 transports: ["websocket", "polling"],
 credentials: true,
},
 allowEIO3: true,
});

and Fix !

Sign up to request clarification or add additional context in comments.

1 Comment

brilliant thanks! where did you get this answer from?
0

I have faced the same issue. It is fixed when I changed the socket.io version to ^2.3.0 Change the socket io version to ^2.3.0 in package.json, delete node modules and reinstall the packages using npm install command

Comments

0

I had the same issue and changed:

WiFi.begin(ssid, password);

to

WiFiMulti.addAP(ssid, pass);

and it connects fine.

PS: I used <SocketIOclient.h>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.