esp8266 connection problem

For the discussion of Arduino related topics.

Moderator: phalanx

Post Reply
ragavaraaj
Posts: 1
Joined: Mon Jan 07, 2019 7:23 am

esp8266 connection problem

Post by ragavaraaj » Mon Jan 07, 2019 7:31 am

Hi, i am using ratchet as my websocket server which is based on php and now i am trying to connect it with my esp8266 i tried everything i cant make it work i checked the working of ratchet separately that is with the browser it works perfectly but it always says disconnected in esp8266

can u pls tell me wt is wrong with my code or is the ratchet has to be configured differently for esp8266 ??

arduino code :

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include <Hash.h>

WebSocketsClient webSocket;

#define USE_SERIAL Serial

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

switch(type) {
case WStype_DISCONNECTED:
USE_SERIAL.printf("[WSc] Disconnected!\n");

break;
case WStype_CONNECTED: {
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);

// send message to server when Connected
webSocket.sendTXT("Connected");
}
break;
case WStype_TEXT:
USE_SERIAL.printf("[WSc] get text: %s\n", payload);

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

// send data to server
// webSocket.sendBIN(payload, length);
break;
}

}

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

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

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

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

const char* ssid = "........";
const char* password = "........";

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

// server address, port and URL
webSocket.begin("192.x.x.x", 9000, "/");

// event handler
webSocket.onEvent(webSocketEvent);

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

}

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

Post Reply