I am quite new to arduino. I want to develop a esp-32 client which can connect to my custom node socketio server. I have tried may libraries and many approaches, but none of them works. Everytime my esp-32 is just logging Disconnecting. Can anyone help me how can I connect my esp-32 to socketio server? I am attaching my esp code below:
#include <Arduino.h>
#include <WiFi.h>
#include <SocketIoClient.h>
const char *ssid = "Nord N100"; // Enter SSID
const char *password = "123456789"; // Enter Password
const char *websockets_server_host = "192.168.181.98"; // Enter server adress
const uint16_t websockets_server_port = 8080; // Enter server port
SocketIoClient webSocket;
void event(const char *payload, size_t length){
Serial.printf("got message: %s\n", payload);
}
void setup() {
Serial.begin(9600);
Serial.setDebugOutput(true);
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] BOOT WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
// Connect to wifi
WiFi.begin(ssid, password);
// Wait some time to connect to wifi
for (int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
Serial.print(".");
delay(1000);
}
// Check if connected to wifi
if (WiFi.status() != WL_CONNECTED) {
Serial.println("No Wifi!");
WiFi.disconnect();
WiFi.reconnect();
delay(500);
}
webSocket.on("event", event);
Serial.println("Connected to Wifi, Connecting to server.");
// try to connect to Websockets server
webSocket.begin("192.168.181.98", websockets_server_port, "/socket.io/?transport=websocket");
}
void loop() {
webSocket.loop();
delay(500);
}
what is your client/server attempting to do? e.g. transfer data from lient to server using a TCP protocol? what protocol?
give use more details of the application?
const char* ssid = "xxxxx";
const char* password = "xxxxxxxx";
const char* serverIP = "xxx.xxx.x.213";
const int serverPort = 3999; // The port you used for the server
WebSocketsClient webSocket;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
void webSocketEvent(WStype_t type, uint8_t* payload, size_t length) {
switch (type) {
case WStype_CONNECTED:
Serial.println("Connected to server");
break;
case WStype_TEXT:
Serial.print("Message from server: ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
break;
case WStype_DISCONNECTED:
Serial.println("Disconnected from server");
break;
}
}
With this code, I see the output of back to back a connection and no connection on the serial monitor, but nothing goes to the 213 ip address.
Hi, I have the same problem as you, I used the code in the example, it doesn't work, and I wrote my own based on the principle from the example, it doesn't work either. Could you help me? I have a web server with sockets on Flask