Skip to content

Commit f5e24e5

Browse files
authored
Improv (#24)
Added a param `IMPROV_ENABLED` that can be used to specify the numbers of milliseconds where Improv WiFi is active, after that period web server is started.
1 parent b25b7d7 commit f5e24e5

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/sblantipodi/arduino_bootstrapper.git"
88
},
9-
"version": "1.12.9",
9+
"version": "1.12.10",
1010
"examples": "examples/*.cpp",
1111
"exclude": "tests",
1212
"frameworks": "arduino",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Bootstrapper
2-
version=1.12.9
2+
version=1.12.10
33
author=Davide Perini <[email protected]>
44
maintainer=Davide Perini <[email protected]>
55
sentence=A client library for MQTT messaging.

src/BootstrapManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
5353
bool rcpResponseSent = false;
5454
void BootstrapManager::bootstrapLoop(void (*manageDisconnections)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)()) {
5555

56-
#if (IMPROV_ENABLED)
56+
#if (IMPROV_ENABLED > 0)
5757
if (!rcpResponseSent && wifiManager.isConnected()) {
5858
rcpResponseSent = true;
5959
wifiManager.sendImprovRPCResponse(0x01, true);
@@ -569,13 +569,13 @@ bool BootstrapManager::isWifiConfigured() {
569569
// if no ssid available, launch web server to get config params via browser
570570
void BootstrapManager::launchWebServerForOTAConfig() {
571571

572-
#if (IMPROV_ENABLED)
572+
#if (IMPROV_ENABLED > 0)
573573
unsigned long timeNowStatus = 0;
574574
bool switchToWebServer = false;
575575
// If WiFi is not configured, handle improv packet for 15 seconds, then switch to settinigs managed by web server
576576
WiFi.disconnect();
577-
while ((WiFi.status() != WL_CONNECTED && !switchToWebServer) || improvePacketReceived) {
578-
if(millis() > timeNowStatus + 15000) {
577+
while (((WiFi.localIP()[0] == 0 && WiFi.status() != WL_CONNECTED) && !switchToWebServer) || improvePacketReceived) {
578+
if(millis() > timeNowStatus + IMPROV_ENABLED) {
579579
timeNowStatus = millis();
580580
switchToWebServer = true;
581581
}

src/Configuration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
extern Adafruit_SSD1306 display;
6060
#endif
6161

62+
// Values greater then 0 enables Improv for that milliseconds period
6263
#ifndef IMPROV_ENABLED
63-
#define IMPROV_ENABLED false
64+
#define IMPROV_ENABLED 0
6465
#endif
6566

6667
// SENSORNAME will be used as device network name

src/WifiManager.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,11 @@ void WifiManager::sendImprovInfoResponse() {
635635
//out[8] = 2; //Length (set below)
636636
out[9] = ImprovRPCType::Request_Info;
637637
//out[10] = 0; //Data len (set below)
638-
out[11] = 4; //Firmware len ("GLOW")
639-
out[12] = 'G';
640-
out[13] = 'W';
641-
out[14] = ' ';
642-
out[15] = ' ';
638+
out[11] = 4; //Firmware len ("FIRM")
639+
out[12] = 'F';
640+
out[13] = 'I';
641+
out[14] = 'R';
642+
out[15] = 'M';
643643
uint8_t lengthSum = 17;
644644
uint8_t vlen = sprintf_P(out + lengthSum, firmwareVersion.c_str());
645645
out[16] = vlen;
@@ -653,8 +653,8 @@ void WifiManager::sendImprovInfoResponse() {
653653
#endif
654654
out[lengthSum] = hlen;
655655
lengthSum += hlen + 1;
656-
//Use serverDescription if it has been changed from the default "GLOW", else mDNS name
657-
bool useMdnsName = (strcmp(serverDescription, "GLOW") == 0 && strlen(cmDNS) > 0);
656+
//Use serverDescription if it has been changed from the default "FIRM", else mDNS name
657+
bool useMdnsName = (strcmp(serverDescription, "FIRM") == 0 && strlen(cmDNS) > 0);
658658
strcpy(out + lengthSum + 1, useMdnsName ? cmDNS : serverDescription);
659659
uint8_t nlen = strlen(useMdnsName ? cmDNS : serverDescription);
660660
out[lengthSum] = nlen;
@@ -689,8 +689,8 @@ void WifiManager::parseWiFiCommand(char *rpcData) {
689689
sendImprovStateResponse(0x03, false); //provisioning
690690
improvActive = 2;
691691
DynamicJsonDocument doc(1024);
692-
String devName = String(random(0, 100000));
693-
doc["deviceName"] = "GLOW_WORM_" + devName;
692+
String devName = String(random(0, 90000));
693+
doc["deviceName"] = String(DEVICE_NAME) + "_" + devName;
694694
doc["microcontrollerIP"] = "DHCP";
695695
doc["qsid"] = clientSSID;
696696
doc["qpass"] = clientPass;
@@ -726,9 +726,8 @@ void WifiManager::parseWiFiCommand(char *rpcData) {
726726
}
727727
delay(DELAY_200);
728728
#endif
729-
delay(DELAY_2000);
730729
sendImprovRPCResponse(ImprovRPCType::Request_State);
731-
delay(DELAY_2000);
730+
delay(DELAY_200);
732731
sendImprovStateResponse(0x04, false);
733732
delay(DELAY_200);
734733
ESP.restart();
@@ -740,10 +739,10 @@ void WifiManager::handleImprovPacket() {
740739

741740
uint8_t header[6] = {'I', 'M', 'P', 'R', 'O', 'V'};
742741
bool timeout = false;
743-
uint8_t waitTime = 25;
744742
uint16_t packetByte = 0;
745743
uint8_t packetLen = 9;
746744
uint8_t checksum = 0;
745+
uint8_t waitTime = 25;
747746
uint8_t rpcCommandType = 0;
748747
char rpcData[128];
749748
rpcData[0] = 0;

0 commit comments

Comments
 (0)