Skip to content

Commit 3810fc3

Browse files
committed
Release v1.7.0
1 parent 31d26b3 commit 3810fc3

File tree

10 files changed

+44
-14
lines changed

10 files changed

+44
-14
lines changed

CMakeListsUser.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ add_custom_target(
2828
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2929
)
3030

31+
add_custom_target(
32+
UPLOAD_FS_ALL
33+
COMMAND platformio.exe run --target uploadfs
34+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
35+
)
36+

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.6.0",
9+
"version": "1.7.0",
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.6.0
2+
version=1.7.0
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void BootstrapManager::drawInfoPage(String softwareVersion, String author) {
226226
}
227227
display.setCursor(0, effectiveOffset);
228228
display.setTextSize(1);
229-
display.print(WIFI_DEVICE_NAME); display.print(F(" "));
229+
display.print(deviceName); display.print(F(" "));
230230
display.println(softwareVersion);
231231
display.println("by " + author);
232232
display.println(F(""));
@@ -245,7 +245,7 @@ void BootstrapManager::drawInfoPage(String softwareVersion, String author) {
245245
// send the state of your controller to the mqtt queue
246246
void BootstrapManager::sendState(const char *topic, JsonObject objectToSend, String version) {
247247

248-
objectToSend["Whoami"] = WIFI_DEVICE_NAME;
248+
objectToSend["Whoami"] = deviceName;
249249
objectToSend["IP"] = microcontrollerIP;
250250
objectToSend["MAC"] = MAC;
251251
objectToSend["ver"] = version;
@@ -412,6 +412,7 @@ DynamicJsonDocument BootstrapManager::readSPIFFS(String filename) {
412412
bool BootstrapManager::isWifiConfigured() {
413413

414414
if (wifiManager.isWifiConfigured()) {
415+
deviceName = DEVICE_NAME;
415416
microcontrollerIP = IP_MICROCONTROLLER;
416417
qsid = SSID;
417418
qpass = PASSWORD;
@@ -429,6 +430,7 @@ bool BootstrapManager::isWifiConfigured() {
429430
#endif
430431
if (mydoc.containsKey("qsid")) {
431432
Serial.println("Storage OK, restoring WiFi and MQTT config.");
433+
deviceName = helper.getValue(mydoc["deviceName"]);
432434
microcontrollerIP = helper.getValue(mydoc["microcontrollerIP"]);
433435
qsid = helper.getValue(mydoc["qsid"]);
434436
qpass = helper.getValue(mydoc["qpass"]);

src/Configuration.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <ESP8266WebServer.h>
2828
#elif defined(ESP32)
2929
#include <WiFi.h>
30+
#include <mDNS.h>
31+
#include <HTTPClient.h>
3032
#include <WebServer.h>
3133
#endif
3234
#include <Adafruit_SSD1306.h>
@@ -60,6 +62,7 @@ extern Adafruit_SSD1306 display;
6062
#ifndef WIFI_DEVICE_NAME
6163
#define WIFI_DEVICE_NAME "ArduinoBootstrapper"
6264
#endif
65+
const char* const DEVICE_NAME = WIFI_DEVICE_NAME;
6366

6467
// Port for the OTA firmware uplaod
6568
#ifndef MICROCONTROLLER_OTA_PORT
@@ -118,4 +121,9 @@ const int MQTT_PORT = MQTT_SERVER_PORT;
118121
#define MQTT_MAX_PACKET_SIZE 1024
119122
#endif
120123

124+
// MQTT Keep Alive
125+
#ifndef MQTT_KEEP_ALIVE
126+
#define MQTT_KEEP_ALIVE 60
127+
#endif
128+
121129
#endif

src/Helpers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int yoffset = 150;
3131
String haVersion = "";
3232
String IP = "";
3333
String MAC = "";
34+
String deviceName = "XXX";
3435
String microcontrollerIP = "XXX";
3536
String qsid = "XXX";
3637
String qpass = "XXX";

src/Helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern int yoffset;
3939

4040
extern String haVersion;
4141
extern String MAC;
42+
extern String deviceName;
4243
extern String microcontrollerIP;
4344
extern String qsid;
4445
extern String qpass;

src/QueueManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void QueueManager::setupMQTTQueue(void (*callback)(char*, byte*, unsigned int))
3131
helper.getValue(mqttIP,'.',3).toInt()), mqttPort.toInt());
3232
mqttClient.setCallback(callback);
3333
mqttClient.setBufferSize(MQTT_MAX_PACKET_SIZE);
34+
mqttClient.setKeepAlive(MQTT_KEEP_ALIVE);
3435

3536
}
3637

@@ -58,7 +59,7 @@ void QueueManager::mqttReconnect(void (*manageDisconnections)(), void (*manageQu
5859
manageHardwareButton();
5960

6061
// Attempt to connect to MQTT server with QoS = 1 (pubsubclient supports QoS 1 for subscribe only, published msg have QoS 0 this is why I implemented a custom solution)
61-
if (mqttClient.connect(WIFI_DEVICE_NAME, helper.string2char(mqttuser), helper.string2char(mqttpass), 0, 1, 0, 0, 1)) {
62+
if (mqttClient.connect(helper.string2char(deviceName), helper.string2char(mqttuser), helper.string2char(mqttpass), 0, 1, 0, 0, 1)) {
6263

6364
helper.smartPrintln(F(""));
6465
helper.smartPrintln(F("CONNECTED"));

src/WifiManager.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,18 @@ void WifiManager::setupWiFi(void (*manageDisconnections)(), void (*manageHardwar
8282
helper.getValue(IP_DNS,'.',2).toInt(),
8383
helper.getValue(IP_DNS,'.',3).toInt()));
8484
#if defined(ESP8266)
85-
WiFi.hostname(WIFI_DEVICE_NAME);
85+
WiFi.hostname(helper.string2char(deviceName));
8686
// Set wifi power in dbm range 0/0.25, set to 0 to reduce PIR false positive due to wifi power, 0 low, 20.5 max.
8787
WiFi.setOutputPower(WIFI_POWER);
8888
#elif defined(ESP32)
89-
WiFi.setHostname(WIFI_DEVICE_NAME);
90-
#endif
89+
WiFi.setHostname(helper.string2char(deviceName));
90+
btStop();
91+
#endif
9192
// Start wifi connection
9293
WiFi.begin(qsid.c_str(), qpass.c_str());
93-
94+
#if defined(ESP32)
95+
WiFi.setSleep(false);
96+
#endif
9497
// loop here until connection
9598
while (WiFi.status() != WL_CONNECTED) {
9699

@@ -140,7 +143,7 @@ void WifiManager::setupOTAUpload() {
140143
//OTA SETUP
141144
ArduinoOTA.setPort(OTA_PORT);
142145
// Hostname defaults to esp8266-[ChipID]
143-
ArduinoOTA.setHostname(WIFI_DEVICE_NAME);
146+
ArduinoOTA.setHostname(helper.string2char(deviceName));
144147

145148
// No authentication by default
146149
ArduinoOTA.setPassword((const char *)helper.string2char(OTApass));
@@ -297,20 +300,22 @@ void WifiManager::createWebServer() {
297300
content += "</h1>";
298301
content += htmlString;
299302
content += "<br><br><form method='get' action='setting' id='form1'>";
303+
content += "<label for='deviceName'>Device Name</label><input type='text' id='deviceName' name='deviceName' maxlength='25'>";
300304
content += "<label for='microcontrollerIP'>IP ADDRESS</label><input type='text' id='microcontrollerIP' name='microcontrollerIP'>";
301305
content += "<label for='ssid'>SSID</label><input type='text' id='ssid' name='ssid'>";
302306
content += "<label for='pass'>WIFI PASSWORD</label><input type='password' id='pass' name='pass'>";
303307
content += "<label for='OTApass'>OTA PASSWORD</label><input type='password' id='OTApass' name='OTApass'>";
304308
content += "<label for='mqttIP'>MQTT SERVER IP</label><input type='text' id='mqttIP' name='mqttIP'>";
305309
content += "<label for='mqttPort'>MQTT SERVER PORT</label><input type='text' id='mqttPort' name='mqttPort'>";
306-
content += "<label for='mqttuser'>MQTT USERNAME</label><input type='text' id='mqttuser' name='mqttuser'>";
307-
content += "<label for='mqttpass'>MQTT PASSWORD</label><input type='password' id='mqttpass' name='mqttpass'>";
308-
content += "</form><br><br><button type='submit' form='form1' value='Submit' class='button button3'>STORE CONFIG</button><br><br><br></div></body>";
310+
content += "<label for='mqttuser'>MQTT SERVER USERNAME</label><input type='text' id='mqttuser' name='mqttuser'>";
311+
content += "<label for='mqttpass'>MQTT SERVER PASSWORD</label><input type='password' id='mqttpass' name='mqttpass'>";
312+
content += "</form><br><br><button type='submit' form='form1' value='Submit' class='button button3'>STORE CONFIG</button><br><br><p>All fields are required, please double check them before submit or you will need to reflash.</p><br></div></body>";
309313
content += "</html>";
310314
server.send(200, "text/html", content);
311315
});
312316

313317
server.on("/setting", []() {
318+
String deviceName = server.arg("deviceName");
314319
String microcontrollerIP = server.arg("microcontrollerIP");
315320
String qsid = server.arg("ssid");
316321
String qpass = server.arg("pass");
@@ -320,8 +325,10 @@ void WifiManager::createWebServer() {
320325
String mqttuser = server.arg("mqttuser");
321326
String mqttpass = server.arg("mqttpass");
322327

323-
if (microcontrollerIP.length() > 0 && qsid.length() > 0 && qpass.length() > 0 && OTApass.length() > 0 && mqttIP.length() > 0 && mqttPort.length() > 0 && mqttuser.length() > 0 && mqttpass.length() > 0) {
328+
if (deviceName.length() > 0 && microcontrollerIP.length() > 0 && qsid.length() > 0 && qpass.length() > 0 && OTApass.length() > 0 && mqttIP.length() > 0 && mqttPort.length() > 0 && mqttuser.length() > 0 && mqttpass.length() > 0) {
324329

330+
Serial.println("deviceName");
331+
Serial.println(deviceName);
325332
Serial.println("microcontrollerIP");
326333
Serial.println(microcontrollerIP);
327334
Serial.println("qsid");
@@ -340,6 +347,7 @@ void WifiManager::createWebServer() {
340347
Serial.println(mqttpass);
341348

342349
DynamicJsonDocument doc(1024);
350+
doc["deviceName"] = deviceName;
343351
doc["microcontrollerIP"] = microcontrollerIP;
344352
doc["qsid"] = qsid;
345353
doc["qpass"] = qpass;

src/WifiManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <LittleFS.h>
3030
#elif defined(ESP32)
3131
#include <WiFi.h>
32+
#include <mDNS.h>
33+
#include <HTTPClient.h>
34+
#include <WiFiUdp.h>
3235
#include <WebServer.h>
3336
#include "SPIFFS.h"
3437
#endif

0 commit comments

Comments
 (0)