Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Firmware/GPAD_API/GPAD_API/GPAD_API.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
* -- rlr, Oct. 24, 2022
*/

#include <array>

#include "alarm_api.h"
#include "GPAD_HAL.h"
#include "gpad_utility.h"
Expand Down Expand Up @@ -150,13 +152,14 @@ const char *mqtt_broker_name = "public.cloud.shiftr.io";
const char *mqtt_user = "public";
const char *mqtt_password = "public";

const size_t MAC_ADDRESS_STRING_LENGTH = 13;
// MQTT Topics, MAC plus an extention
// A MAC addresss treated as a string has 12 chars.
// The strings "_ALM" and "_ACK" have 4 chars.
// A null character is one other. 12 + 4 + 1 = 17
char subscribe_Alarm_Topic[17];
char publish_Ack_Topic[17];
char macAddressString[13];
char macAddressString[MAC_ADDRESS_STRING_LENGTH];

#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
Expand Down Expand Up @@ -484,11 +487,17 @@ void setup()
Serial.println(publish_Ack_Topic);
Serial.println("XXXXXXX");
#endif
// Setup SSID length is the length of the prefix, 'Krake_', which is 7
// plus the length of the MAC address string, MAC_ADDRESS_STRING_LENGTH
const size_t SETUP_SSID_LENGTH = 7 + MAC_ADDRESS_STRING_LENGTH;
char setupSsid[SETUP_SSID_LENGTH] = "Krake_";
strcat(setupSsid, macAddressString);

// We call this a second time to get the MAC on the screen
// clearLCD();
// req for Wifi Man and OTA
WiFiMan();

WiFiMan(setupSsid);
initLittleFS();
server.begin(); // Start server web socket to render pages
ElegantOTA.begin(&server);
Expand Down
17 changes: 14 additions & 3 deletions Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "WiFiManagerOTA.h"
#include <LittleFS.h>

const char *default_ssid = "ESP32-Setup"; // Default AP Name
const char *DEFAULT_SSID = "ESP32-Setup"; // Default AP Name
String ssid_wf = "";
String password_wf = "";
String ledState = "";
Expand Down Expand Up @@ -42,13 +42,24 @@ bool loadCredentials()
return true;
}

void WiFiMan()
void WiFiMan(const char *accessPointSsid)
{
WiFiManager wifiManager;

if (!loadCredentials())
{
if (!wifiManager.autoConnect(default_ssid))
boolean connectSuccess = false;

if (accessPointSsid == "")
{
connectSuccess = wifiManager.autoConnect(DEFAULT_SSID);
}
else
{
connectSuccess = wifiManager.autoConnect(accessPointSsid);
}

if (!connectSuccess)
{
Serial.println("Failed to connect. Restarting...");
ESP.restart();
Expand Down
4 changes: 2 additions & 2 deletions Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#include <FS.h>
#include <LittleFS.h>

extern const char *default_ssid;
extern const char *DEFAULT_SSID;
// extern String ssid;
// extern String password;
extern String ledState;
extern int WiFiLed;

void saveCredentials(const char *ssid, const char *password);
bool loadCredentials();
void WiFiMan();
void WiFiMan(const char *accessPointSsid);
void initLittleFS();
void initWiFi();
String processor(const String &var);
Expand Down