Skip to content

Commit 8375ee1

Browse files
committed
WebSockets: Use webSocketsIsConnected() instead of websocketConnected
1 parent d9a487d commit 8375ee1

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ void webServerVerifyTables() {}
304304
bool wifiAfterCommand(int cmdIndex){return false;}
305305
bool webServerIsRunning() {return false;}
306306

307+
//----------------------------------------
308+
// Web Sockets
309+
//----------------------------------------
310+
311+
bool webSocketsIsConnected() (return false;}
312+
307313
#endif // COMPILE_AP
308314

309315
//======================================================================

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ bool savePossibleSettings = true; // Save possible vs. available settings. See r
430430
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
431431
#ifdef COMPILE_WIFI
432432
int packetRSSI;
433-
RTK_WIFI wifi(false); // wifi(false); is non-verbose. For verbose, change to wifi(true);
433+
RTK_WIFI wifi(false); // wifi(false); is non-verbose. For verbose, change to wifi(true);
434434
#endif // COMPILE_WIFI
435435

436436
// WiFi Globals - For other module direct access
@@ -708,7 +708,6 @@ char *incomingSettings;
708708
int incomingSettingsSpot;
709709
unsigned long timeSinceLastIncomingSetting;
710710
unsigned long lastDynamicDataUpdate;
711-
bool websocketConnected = false;
712711

713712
#ifdef COMPILE_WIFI
714713
#ifdef COMPILE_AP

Firmware/RTK_Everywhere/States.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ void stateUpdate()
521521
#ifdef COMPILE_WIFI
522522
#ifdef COMPILE_AP
523523
// Handle dynamic requests coming from web config page
524-
if (websocketConnected == true)
524+
if (webSocketsIsConnected() == true)
525525
{
526526
// Update the coordinates on the AP page
527527
if ((millis() - lastDynamicDataUpdate) > 1000)

Firmware/RTK_Everywhere/WebSockets.ino

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const int webSocketsStackSize = 1024 * 20; // Needs to be large enough
1818

1919
static int last_ws_fd;
2020
// httpd_req_t *last_ws_req;
21+
static bool webSocketsConnected;
2122
static httpd_handle_t webSocketsHandle;
2223

2324
//----------------------------------------
@@ -137,7 +138,7 @@ static esp_err_t webSocketsHandler(httpd_req_t *req)
137138
if (settings.debugWebServer == true)
138139
systemPrintf("Handshake done, the new ws connection was opened with fd %d\r\n", last_ws_fd);
139140

140-
websocketConnected = true;
141+
webSocketsConnected = true;
141142
lastDynamicDataUpdate = millis();
142143
webSocketsSendString(settingsCSV);
143144

@@ -236,13 +237,21 @@ static esp_err_t webSocketsHandler(httpd_req_t *req)
236237
systemPrintln("Client closed or refreshed the web page");
237238

238239
createSettingsString(settingsCSV);
239-
websocketConnected = false;
240+
webSocketsConnected = false;
240241
}
241242

242243
rtkFree(buf, "Payload buffer (buf)");
243244
return ret;
244245
}
245246

247+
//----------------------------------------
248+
// Determine if webSockets is connected to a client
249+
//----------------------------------------
250+
bool webSocketsIsConnected()
251+
{
252+
return webSocketsConnected;
253+
}
254+
246255
//----------------------------------------
247256
// Send the formware version via web sockets
248257
//----------------------------------------
@@ -270,7 +279,7 @@ void webSocketsSendSettings(void)
270279
//----------------------------------------
271280
void webSocketsSendString(const char *stringToSend)
272281
{
273-
if (!websocketConnected)
282+
if (!webSocketsConnected)
274283
{
275284
systemPrintf("webSocketsSendString: not connected - could not send: %s\r\n", stringToSend);
276285
return;
@@ -360,7 +369,7 @@ bool webSocketsStart(void)
360369
//----------------------------------------
361370
void webSocketsStop()
362371
{
363-
websocketConnected = false;
372+
webSocketsConnected = false;
364373

365374
if (webSocketsHandle != nullptr)
366375
{

Firmware/RTK_Everywhere/menuFirmware.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void otaUpdate()
884884
// is requesting the firmware update via those interfaces, thus we attempt an update
885885
// only once, stopping the state machine on failure
886886

887-
if (websocketConnected)
887+
if (webSocketsIsConnected())
888888
{
889889
// Report failed connection to web client
890890
webSocketsSendString((char *)"newFirmwareVersion,NO_INTERNET,");
@@ -941,7 +941,7 @@ void otaUpdate()
941941
{
942942
otaRequestFirmwareVersionCheck = false;
943943

944-
if (websocketConnected)
944+
if (webSocketsIsConnected())
945945
{
946946
char newVersionCSV[40];
947947
snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,%s,",
@@ -966,7 +966,7 @@ void otaUpdate()
966966
else
967967
{
968968
systemPrintln("Version Check: Firmware is up to date. No new firmware available.");
969-
if (websocketConnected)
969+
if (webSocketsIsConnected())
970970
webSocketsSendString((char *)"newFirmwareVersion,CURRENT,");
971971

972972
otaUpdateStop();
@@ -976,7 +976,7 @@ void otaUpdate()
976976
{
977977
// Failed to get version number
978978
systemPrintln("Failed to get version number from server.");
979-
if (websocketConnected)
979+
if (webSocketsIsConnected())
980980
webSocketsSendString((char *)"newFirmwareVersion,NO_SERVER,");
981981

982982
// Report failure over the CLI
@@ -995,7 +995,7 @@ void otaUpdate()
995995
{
996996
otaUpdateStop();
997997

998-
if (websocketConnected)
998+
if (webSocketsIsConnected())
999999
webSocketsSendString((char *)"gettingNewFirmware,ERROR,");
10001000

10011001
// Report failure over the CLI
@@ -1009,7 +1009,7 @@ void otaUpdate()
10091009
otaUpdateFirmware();
10101010

10111011
// Update triggers ESP.restart(). If we get this far, the firmware update has failed
1012-
if (websocketConnected)
1012+
if (webSocketsIsConnected())
10131013
webSocketsSendString((char *)"gettingNewFirmware,ERROR,");
10141014

10151015
// Report failure over the CLI

0 commit comments

Comments
 (0)