Skip to content

Commit

Permalink
feat: macro conditionals for wifi connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bissas committed Mar 10, 2024
1 parent 1e6f535 commit 6a9d2f9
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions src/handler/deploii_handler_WiFi_WS.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#include "deploii_handler.h"

/*
Deploii handler for communication using WiFI and WebSockets
Deploii handler for communication using WiFI and WebSockets
*/

/*
Constants
*/
#define Deploii_WIFI_RECONNECT_TIME 1000

/*
Helper function declarations
*/
void connectWiFi(const char* ssid, const char* pwd);

/*
Class definitions
*/

DeploiiHandlerWiFiWS::DeploiiHandlerWiFiWS() : _ws() {
Expand All @@ -22,9 +36,7 @@ void DeploiiHandlerWiFiWS::connect(
const int port,
const char* url,
bool ssl) {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pwd);
while (WiFi.status() != WL_CONNECTED) delay(1000);
connectWiFi(ssid, pwd);

char authHeader[40];
sprintf(authHeader, "%s%s", "Authorization: ", boardID);
Expand All @@ -34,4 +46,26 @@ void DeploiiHandlerWiFiWS::connect(
_ws.beginSSL(host, port, url);
else
_ws.begin(host, port, url);
}
}

/*
Helper function definitions
*/

#ifdef ESP32

void connectWiFi(const char* ssid, const char* pwd) {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pwd);
while (WiFi.status() != WL_CONNECTED) delay(Deploii_WIFI_RECONNECT_TIME);
}

#endif

#ifdef ARDUINO

void connectWiFi(const char* ssid, const char* pwd) {
while (WiFi.begin(ssid, pwd) != WL_CONNECTED) delay(Deploii_WIFI_RECONNECT_TIME);
}

#endif

0 comments on commit 6a9d2f9

Please sign in to comment.