Hi, first post. Let me know if this is not the correct category to ask for.
I have been doing a small personal Project with a Finger Print Sensor and some Web socket functionality.
Everything was working as expected until I deploy the web socket server to Azure.
It seems my DOIT ESP32 DEVKIT V1 board cannot connect to the Web socket Server.
I'm using the Web Sockets library.
#include <WiFi.h>
#include <WebSocketsClient.h>
#include <HardwareSerial.h>
#include <HTTPClient.h>
String deviceName = "ESP-FG-TNT";
char *ssid = "mySsid";
char *pass = "dummyPass";
String domain = "flowcontrol9a.azurewebsites.net";
int port = 80;
int wifiStatus = WL_IDLE_STATUS;
void connectWifi() {
WiFi.begin(ssid, pass);
while (wifiStatus != WL_CONNECTED) {
wifiStatus = WiFi.waitForConnectResult();
}
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
Serial.println("[WIFI] WiFi connected!");
Serial.print("[WIFI] IP address: ");
Serial.println(WiFi.localIP());
}
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
String sPayload;
switch(type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED:
Serial.printf("[WSc] Connected to url: %s\n", payload);
// send message to server when Connected
// webSocket.sendTXT("CONNECTED");
break;
case WStype_TEXT:
//Code here
break;
case WStype_BIN:
break;
case WStype_ERROR:
case WStype_FRAGMENT_TEXT_START:
case WStype_FRAGMENT_BIN_START:
case WStype_FRAGMENT:
case WStype_FRAGMENT_FIN:
break;
}
}
void connectSocket() {
webSocket.beginSSL(domain, port, "/webSocket/" + deviceName);
webSocket.onEvent(webSocketEvent);
webSocket.setReconnectInterval(3000);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.println("[STARTUP] Starting!...");
connectWifi();
connectSocket();
}
void loop() {
wifiStatus = WiFi.status();
if(wifiStatus != WL_CONNECTED) connectWifi();
webSocket.loop();
}
I got the following on the serial monitor.
[WSc] Disconnected!
What could be occurring since I tried to connect from postman and it worked! Kinda annoying because it works on localhost.
I appreciate it if you can give advice on the correct way to connect to a web socket.
