Check websocket connection
This commit is contained in:
@ -4,9 +4,6 @@
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
// The url parameter to send the message to the local server
|
||||
constexpr char messageUrlParameter[] = "m";
|
||||
|
||||
SesameController::SesameController(uint16_t localWebServerPort, uint8_t remoteDeviceCount) :
|
||||
storage(remoteDeviceCount), localWebServer(localWebServerPort) {
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "controller.h"
|
||||
#include "config.h"
|
||||
|
||||
SesameController controller(localWebServerPort, remoteDeviceCount);
|
||||
SesameController controller(localPort, remoteDeviceCount);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(serialBaudRate);
|
||||
|
@ -12,7 +12,7 @@ void ServerConnection::configure(ServerConfiguration configuration, ServerConnec
|
||||
}
|
||||
|
||||
void ServerConnection::connect() {
|
||||
if (socketIsConnected) {
|
||||
if (webSocket.isConnected()) {
|
||||
return;
|
||||
}
|
||||
if (controller == NULL) {
|
||||
@ -29,6 +29,10 @@ void ServerConnection::connect() {
|
||||
webSocket.setReconnectInterval(configuration.reconnectTime);
|
||||
}
|
||||
|
||||
void ServerConnection::disconnect() {
|
||||
webSocket.disconnect();
|
||||
}
|
||||
|
||||
void ServerConnection::loop() {
|
||||
webSocket.loop();
|
||||
}
|
||||
@ -36,11 +40,9 @@ void ServerConnection::loop() {
|
||||
void ServerConnection::webSocketEventHandler(WStype_t type, uint8_t * payload, size_t length) {
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
socketIsConnected = false;
|
||||
Serial.println("[INFO] Socket disconnected.");
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
socketIsConnected = true;
|
||||
webSocket.sendTXT(configuration.key);
|
||||
Serial.printf("[INFO] Socket connected to url: %s\n", payload);
|
||||
webSocket.enableHeartbeat(pingInterval, pongTimeout, disconnectTimeoutCount);
|
||||
|
Reference in New Issue
Block a user