|
@@ -1,3 +1,18 @@
|
|
|
+#include <FS.h> //this needs to be first, or it all crashes and burns...
|
|
|
+
|
|
|
+#include <ESP8266WiFi.h>
|
|
|
+
|
|
|
+//web config portal
|
|
|
+#include <ESP8266WebServer.h>
|
|
|
+#include <DNSServer.h>
|
|
|
+#include <WiFiManager.h>
|
|
|
+
|
|
|
+//Configuration saving
|
|
|
+#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//ticker flag for saving data
|
|
|
bool flag_SaveConfig = false;
|
|
|
|
|
@@ -6,9 +21,9 @@ Ticker tkConfig ;
|
|
|
bool flag_ConfigPortal = false;
|
|
|
int timeout = 30000;
|
|
|
|
|
|
-char UKI_NAME[40];
|
|
|
-char UKI_UDP_PORT[6] = "9000";
|
|
|
-char UKI_UDP_IP[16] = "192.168.10.100";
|
|
|
+char ESP_NAME[40];
|
|
|
+char UDP_PORT[6] = "9000";
|
|
|
+char UDP_IP[16] = "192.168.10.100";
|
|
|
|
|
|
|
|
|
|
|
@@ -50,9 +65,9 @@ void ReadConfig() {
|
|
|
if (json.success()) {
|
|
|
Serial.println("\nparsed json");
|
|
|
|
|
|
- strcpy(UKI_NAME, json["UKI_NAME"]);
|
|
|
- strcpy(UKI_UDP_PORT, json["UKI_UDP_PORT"]);
|
|
|
- strcpy(UKI_UDP_IP, json["UKI_UDP_IP"]);
|
|
|
+ strcpy(ESP_NAME, json["ESP_NAME"]);
|
|
|
+ strcpy(UDP_PORT, json["UDP_PORT"]);
|
|
|
+ strcpy(UDP_IP, json["UDP_IP"]);
|
|
|
|
|
|
|
|
|
}
|
|
@@ -76,9 +91,9 @@ void WriteConfig() {
|
|
|
Serial.println("saving config");
|
|
|
DynamicJsonBuffer jsonBuffer;
|
|
|
JsonObject& json = jsonBuffer.createObject();
|
|
|
- json["UKI_NAME"] = UKI_NAME;
|
|
|
- json["UKI_UDP_PORT"] = UKI_UDP_PORT;
|
|
|
- json["UKI_UDP_IP"] = UKI_UDP_IP;
|
|
|
+ json["ESP_NAME"] = ESP_NAME;
|
|
|
+ json["UDP_PORT"] = UDP_PORT;
|
|
|
+ json["UDP_IP"] = UDP_IP;
|
|
|
|
|
|
File configFile = SPIFFS.open("/config.json", "w");
|
|
|
if (!configFile) {
|
|
@@ -103,7 +118,7 @@ void StartConfigAP(){
|
|
|
|
|
|
flag_ConfigPortal = false; //reset flag
|
|
|
|
|
|
- // detach all tickers (redLed, blueLed, OTA, wifimgr, UKI_UDP)
|
|
|
+ // detach all tickers (redLed, blueLed, OTA, wifimgr, UDP)
|
|
|
redLedState (1, 500);
|
|
|
blueLedState (1,500);
|
|
|
detachOTA();
|
|
@@ -117,9 +132,9 @@ void StartConfigAP(){
|
|
|
// The extra parameters to be configured (can be either global or just in the setup)
|
|
|
// After connecting, parameter.getValue() will get you the configured value
|
|
|
// id/name placeholder/prompt default length
|
|
|
- WiFiManagerParameter custom_UKI_NAME("name", "UKI NAME", UKI_NAME, 40);
|
|
|
- WiFiManagerParameter custom_UKI_UDP_PORT("port", "UKI udp port", UKI_UDP_PORT, 5);
|
|
|
- WiFiManagerParameter custom_UKI_UDP_IP("ip", "UKI udp IP", UKI_UDP_IP, 32);
|
|
|
+ WiFiManagerParameter custom_ESP_NAME("name", "ESP NAME", ESP_NAME, 40);
|
|
|
+ WiFiManagerParameter custom_UDP_PORT("port", " UDP port", UDP_PORT, 5);
|
|
|
+ WiFiManagerParameter custom_UDP_IP("ip", "UDP IP", UDP_IP, 32);
|
|
|
|
|
|
//Local intialization. Once its business is done, there is no need to keep it around
|
|
|
WiFiManager wifiManager;
|
|
@@ -128,9 +143,9 @@ void StartConfigAP(){
|
|
|
wifiManager.setSaveConfigCallback(saveConfigCallback);//set config save notify callback
|
|
|
|
|
|
//add all your parameters here
|
|
|
- wifiManager.addParameter(&custom_UKI_NAME);
|
|
|
- wifiManager.addParameter(&custom_UKI_UDP_PORT);
|
|
|
- wifiManager.addParameter(&custom_UKI_UDP_IP);
|
|
|
+ wifiManager.addParameter(&custom_ESP_NAME);
|
|
|
+ wifiManager.addParameter(&custom_UDP_PORT);
|
|
|
+ wifiManager.addParameter(&custom_UDP_IP);
|
|
|
|
|
|
//it starts an access point with the specified name
|
|
|
//here "AutoConnectAP"
|
|
@@ -144,7 +159,7 @@ void StartConfigAP(){
|
|
|
//while (!flag_connected) {
|
|
|
redLedState (1, 100);
|
|
|
blueLedState (-1, 100);
|
|
|
- if (!wifiManager.startConfigPortal(UKI_NAME)) {
|
|
|
+ if (!wifiManager.startConfigPortal(ESP_NAME)) {
|
|
|
Serial.println("failed to connect, restarting config portal");
|
|
|
delay(2000);
|
|
|
//reset and try again
|
|
@@ -158,13 +173,13 @@ void StartConfigAP(){
|
|
|
|
|
|
|
|
|
//if you get here you have connected to the WiFi
|
|
|
- Serial.println("connected to UKI wifi");
|
|
|
+ Serial.println("connected to wifi");
|
|
|
blueLedState(0,500);
|
|
|
|
|
|
//read updated parameters
|
|
|
- strcpy(UKI_NAME, custom_UKI_NAME.getValue());
|
|
|
- strcpy(UKI_UDP_PORT, custom_UKI_UDP_PORT.getValue());
|
|
|
- strcpy(UKI_UDP_IP, custom_UKI_UDP_IP.getValue());
|
|
|
+ strcpy(ESP_NAME, custom_ESP_NAME.getValue());
|
|
|
+ strcpy(UDP_PORT, custom_UDP_PORT.getValue());
|
|
|
+ strcpy(UDP_IP, custom_UDP_IP.getValue());
|
|
|
|
|
|
WriteConfig();
|
|
|
Serial.println("Restarting");
|