Skip to content

Commit

Permalink
Release v1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Aug 20, 2020
1 parent 31d26b3 commit 3810fc3
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CMakeListsUser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_target(
UPLOAD_FS_ALL
COMMAND platformio.exe run --target uploadfs
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/sblantipodi/arduino_bootstrapper.git"
},
"version": "1.6.0",
"version": "1.7.0",
"examples": "examples/*.cpp",
"exclude": "tests",
"frameworks": "arduino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bootstrapper
version=1.6.0
version=1.7.0
author=Davide Perini <[email protected]>
maintainer=Davide Perini <[email protected]>
sentence=A client library for MQTT messaging.
Expand Down
6 changes: 4 additions & 2 deletions src/BootstrapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void BootstrapManager::drawInfoPage(String softwareVersion, String author) {
}
display.setCursor(0, effectiveOffset);
display.setTextSize(1);
display.print(WIFI_DEVICE_NAME); display.print(F(" "));
display.print(deviceName); display.print(F(" "));
display.println(softwareVersion);
display.println("by " + author);
display.println(F(""));
Expand All @@ -245,7 +245,7 @@ void BootstrapManager::drawInfoPage(String softwareVersion, String author) {
// send the state of your controller to the mqtt queue
void BootstrapManager::sendState(const char *topic, JsonObject objectToSend, String version) {

objectToSend["Whoami"] = WIFI_DEVICE_NAME;
objectToSend["Whoami"] = deviceName;
objectToSend["IP"] = microcontrollerIP;
objectToSend["MAC"] = MAC;
objectToSend["ver"] = version;
Expand Down Expand Up @@ -412,6 +412,7 @@ DynamicJsonDocument BootstrapManager::readSPIFFS(String filename) {
bool BootstrapManager::isWifiConfigured() {

if (wifiManager.isWifiConfigured()) {
deviceName = DEVICE_NAME;
microcontrollerIP = IP_MICROCONTROLLER;
qsid = SSID;
qpass = PASSWORD;
Expand All @@ -429,6 +430,7 @@ bool BootstrapManager::isWifiConfigured() {
#endif
if (mydoc.containsKey("qsid")) {
Serial.println("Storage OK, restoring WiFi and MQTT config.");
deviceName = helper.getValue(mydoc["deviceName"]);
microcontrollerIP = helper.getValue(mydoc["microcontrollerIP"]);
qsid = helper.getValue(mydoc["qsid"]);
qpass = helper.getValue(mydoc["qpass"]);
Expand Down
8 changes: 8 additions & 0 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <ESP8266WebServer.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <mDNS.h>
#include <HTTPClient.h>
#include <WebServer.h>
#endif
#include <Adafruit_SSD1306.h>
Expand Down Expand Up @@ -60,6 +62,7 @@ extern Adafruit_SSD1306 display;
#ifndef WIFI_DEVICE_NAME
#define WIFI_DEVICE_NAME "ArduinoBootstrapper"
#endif
const char* const DEVICE_NAME = WIFI_DEVICE_NAME;

// Port for the OTA firmware uplaod
#ifndef MICROCONTROLLER_OTA_PORT
Expand Down Expand Up @@ -118,4 +121,9 @@ const int MQTT_PORT = MQTT_SERVER_PORT;
#define MQTT_MAX_PACKET_SIZE 1024
#endif

// MQTT Keep Alive
#ifndef MQTT_KEEP_ALIVE
#define MQTT_KEEP_ALIVE 60
#endif

#endif
1 change: 1 addition & 0 deletions src/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int yoffset = 150;
String haVersion = "";
String IP = "";
String MAC = "";
String deviceName = "XXX";
String microcontrollerIP = "XXX";
String qsid = "XXX";
String qpass = "XXX";
Expand Down
1 change: 1 addition & 0 deletions src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern int yoffset;

extern String haVersion;
extern String MAC;
extern String deviceName;
extern String microcontrollerIP;
extern String qsid;
extern String qpass;
Expand Down
3 changes: 2 additions & 1 deletion src/QueueManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void QueueManager::setupMQTTQueue(void (*callback)(char*, byte*, unsigned int))
helper.getValue(mqttIP,'.',3).toInt()), mqttPort.toInt());
mqttClient.setCallback(callback);
mqttClient.setBufferSize(MQTT_MAX_PACKET_SIZE);
mqttClient.setKeepAlive(MQTT_KEEP_ALIVE);

}

Expand Down Expand Up @@ -58,7 +59,7 @@ void QueueManager::mqttReconnect(void (*manageDisconnections)(), void (*manageQu
manageHardwareButton();

// 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)
if (mqttClient.connect(WIFI_DEVICE_NAME, helper.string2char(mqttuser), helper.string2char(mqttpass), 0, 1, 0, 0, 1)) {
if (mqttClient.connect(helper.string2char(deviceName), helper.string2char(mqttuser), helper.string2char(mqttpass), 0, 1, 0, 0, 1)) {

helper.smartPrintln(F(""));
helper.smartPrintln(F("CONNECTED"));
Expand Down
26 changes: 17 additions & 9 deletions src/WifiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ void WifiManager::setupWiFi(void (*manageDisconnections)(), void (*manageHardwar
helper.getValue(IP_DNS,'.',2).toInt(),
helper.getValue(IP_DNS,'.',3).toInt()));
#if defined(ESP8266)
WiFi.hostname(WIFI_DEVICE_NAME);
WiFi.hostname(helper.string2char(deviceName));
// 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.
WiFi.setOutputPower(WIFI_POWER);
#elif defined(ESP32)
WiFi.setHostname(WIFI_DEVICE_NAME);
#endif
WiFi.setHostname(helper.string2char(deviceName));
btStop();
#endif
// Start wifi connection
WiFi.begin(qsid.c_str(), qpass.c_str());

#if defined(ESP32)
WiFi.setSleep(false);
#endif
// loop here until connection
while (WiFi.status() != WL_CONNECTED) {

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

// No authentication by default
ArduinoOTA.setPassword((const char *)helper.string2char(OTApass));
Expand Down Expand Up @@ -297,20 +300,22 @@ void WifiManager::createWebServer() {
content += "</h1>";
content += htmlString;
content += "<br><br><form method='get' action='setting' id='form1'>";
content += "<label for='deviceName'>Device Name</label><input type='text' id='deviceName' name='deviceName' maxlength='25'>";
content += "<label for='microcontrollerIP'>IP ADDRESS</label><input type='text' id='microcontrollerIP' name='microcontrollerIP'>";
content += "<label for='ssid'>SSID</label><input type='text' id='ssid' name='ssid'>";
content += "<label for='pass'>WIFI PASSWORD</label><input type='password' id='pass' name='pass'>";
content += "<label for='OTApass'>OTA PASSWORD</label><input type='password' id='OTApass' name='OTApass'>";
content += "<label for='mqttIP'>MQTT SERVER IP</label><input type='text' id='mqttIP' name='mqttIP'>";
content += "<label for='mqttPort'>MQTT SERVER PORT</label><input type='text' id='mqttPort' name='mqttPort'>";
content += "<label for='mqttuser'>MQTT USERNAME</label><input type='text' id='mqttuser' name='mqttuser'>";
content += "<label for='mqttpass'>MQTT PASSWORD</label><input type='password' id='mqttpass' name='mqttpass'>";
content += "</form><br><br><button type='submit' form='form1' value='Submit' class='button button3'>STORE CONFIG</button><br><br><br></div></body>";
content += "<label for='mqttuser'>MQTT SERVER USERNAME</label><input type='text' id='mqttuser' name='mqttuser'>";
content += "<label for='mqttpass'>MQTT SERVER PASSWORD</label><input type='password' id='mqttpass' name='mqttpass'>";
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>";
content += "</html>";
server.send(200, "text/html", content);
});

server.on("/setting", []() {
String deviceName = server.arg("deviceName");
String microcontrollerIP = server.arg("microcontrollerIP");
String qsid = server.arg("ssid");
String qpass = server.arg("pass");
Expand All @@ -320,8 +325,10 @@ void WifiManager::createWebServer() {
String mqttuser = server.arg("mqttuser");
String mqttpass = server.arg("mqttpass");

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) {
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) {

Serial.println("deviceName");
Serial.println(deviceName);
Serial.println("microcontrollerIP");
Serial.println(microcontrollerIP);
Serial.println("qsid");
Expand All @@ -340,6 +347,7 @@ void WifiManager::createWebServer() {
Serial.println(mqttpass);

DynamicJsonDocument doc(1024);
doc["deviceName"] = deviceName;
doc["microcontrollerIP"] = microcontrollerIP;
doc["qsid"] = qsid;
doc["qpass"] = qpass;
Expand Down
3 changes: 3 additions & 0 deletions src/WifiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <LittleFS.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <mDNS.h>
#include <HTTPClient.h>
#include <WiFiUdp.h>
#include <WebServer.h>
#include "SPIFFS.h"
#endif
Expand Down

0 comments on commit 3810fc3

Please sign in to comment.