works so far
This commit is contained in:
parent
b92451eb98
commit
62e98675d8
@ -187,10 +187,10 @@ environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.DTS
|
|||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.DTS/value=3600
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.DTS/value=3600
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/delimiter=\:
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/delimiter=\:
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/operation=replace
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/operation=replace
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/value=1503268994
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.LOCAL/value=1503312196
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/delimiter=\:
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/delimiter=\:
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/operation=replace
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/operation=replace
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/value=1503261794
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.UTC/value=1503304996
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/delimiter=\:
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/delimiter=\:
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/operation=replace
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/operation=replace
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/value=3600
|
environment/project/io.sloeber.core.toolChain.release.936970421/A.EXTRA.TIME.ZONE/value=3600
|
||||||
@ -472,7 +472,7 @@ environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.COM_PORT/
|
|||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.COM_PORT/value=/dev/ttyUSB0
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.COM_PORT/value=/dev/ttyUSB0
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/delimiter=\:
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/delimiter=\:
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/operation=replace
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/operation=replace
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}/////////////////////////////////////////////////////////////////////////////////////////////
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/delimiter=\:
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/delimiter=\:
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/operation=replace
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/operation=replace
|
||||||
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/value=
|
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/value=
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#end raw
|
#end raw
|
||||||
|
|
||||||
@ -12,10 +14,22 @@ tConfigBlock configBlock;
|
|||||||
const uint32_t MAGIC = 0xC0DE0001;
|
const uint32_t MAGIC = 0xC0DE0001;
|
||||||
extern ESP8266WebServer webServer;
|
extern ESP8266WebServer webServer;
|
||||||
|
|
||||||
|
|
||||||
void configServeIndex() {
|
void configServeIndex() {
|
||||||
webServer.send(200, "text/html",
|
bool configValid = (configBlock.magic == MAGIC);
|
||||||
""
|
|
||||||
|
if (! configValid) {
|
||||||
|
#for $configItem in $configItems
|
||||||
|
#if $configItem.label != "_"
|
||||||
|
#if $configItem.type == "C"
|
||||||
|
strcpy(configBlock.$configItem.key, "$configItem.default");
|
||||||
|
#else if $configItem.type == "I"
|
||||||
|
configBlock.$configItem.key = $configItem.default;
|
||||||
|
#end if
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
}
|
||||||
|
|
||||||
|
String buffer =
|
||||||
"<!doctype html"
|
"<!doctype html"
|
||||||
"<html lang=\"en\">"
|
"<html lang=\"en\">"
|
||||||
" <head>"
|
" <head>"
|
||||||
@ -31,7 +45,20 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"$configItem.key\">$configItem.label</label>"
|
" <label for\"$configItem.key\">$configItem.label</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\""
|
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\" ";
|
||||||
|
|
||||||
|
#if $configItem.type == "C"
|
||||||
|
buffer += " size=\"$configItem.length\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.$configItem.key;
|
||||||
|
buffer += "\"";
|
||||||
|
#else if $configItem.type == "I"
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.$configItem.key;
|
||||||
|
buffer += "\"";
|
||||||
|
#end if
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -45,8 +72,9 @@ void configServeIndex() {
|
|||||||
" </table>"
|
" </table>"
|
||||||
" </form>"
|
" </form>"
|
||||||
" </body>"
|
" </body>"
|
||||||
"</html>"
|
"</html>";
|
||||||
);
|
|
||||||
|
webServer.send(200, "text/html", buffer);
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -62,9 +90,31 @@ void configServeGetConfiguration() {
|
|||||||
arg = webServer.arg("$configItem.key");
|
arg = webServer.arg("$configItem.key");
|
||||||
Serial.print("$configItem.key");
|
Serial.print("$configItem.key");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
#if $configItem.type == "C"
|
||||||
|
strcpy(configBlock.$configItem.key, arg.c_str());
|
||||||
|
#else if $configItem.type == "I"
|
||||||
|
configBlock.$configItem.key = atoi(arg.c_str());
|
||||||
|
#end if
|
||||||
#end if
|
#end if
|
||||||
#end for
|
#end for
|
||||||
|
|
||||||
|
configBlock.magic = MAGIC;
|
||||||
|
|
||||||
|
showConfiguration();
|
||||||
|
|
||||||
|
EEPROM.begin(512);
|
||||||
|
for (uint16_t i = 0; i < sizeof(configBlock); i++) {
|
||||||
|
char c = *(((char*)(&configBlock))+i);
|
||||||
|
Serial.print("write to eeprom: ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(c);
|
||||||
|
EEPROM.write(EEPROM_ADDR + i, c);
|
||||||
|
}
|
||||||
|
EEPROM.commit();
|
||||||
|
|
||||||
|
Serial.println("EEPROM saved");
|
||||||
|
|
||||||
webServer.send(200, "text/html", "configuration saved");
|
webServer.send(200, "text/html", "configuration saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +122,9 @@ void showConfiguration() {
|
|||||||
Serial.println("Configuration is");
|
Serial.println("Configuration is");
|
||||||
|
|
||||||
#for $configItem in $configItems
|
#for $configItem in $configItems
|
||||||
#if $configItem.label != "_"
|
|
||||||
Serial.print("$configItem.key = ");
|
Serial.print("$configItem.key = ");
|
||||||
Serial.println(configBlock.$configItem.key);
|
Serial.println(configBlock.$configItem.key);
|
||||||
|
|
||||||
#end if
|
|
||||||
#end for
|
#end for
|
||||||
|
|
||||||
Serial.println("---");
|
Serial.println("---");
|
||||||
|
@ -22,12 +22,10 @@ ADC_MODE(ADC_VCC);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define CONFIG_SWITCH 4
|
|
||||||
bool configMode = false;
|
bool configMode = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const uint16_t EEPROM_ADDR = 0;
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t startTime = 0;
|
uint32_t startTime = 0;
|
||||||
@ -41,8 +39,24 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
pinMode(CONFIG_SWITCH, INPUT_PULLUP);
|
pinMode(CONFIG_SWITCH, INPUT_PULLUP);
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
EEPROM.get(EEPROM_ADDR, configBlock);
|
|
||||||
|
EEPROM.begin(512);
|
||||||
|
for (uint16_t i = 0; i < sizeof(configBlock); i++) {
|
||||||
|
char x = EEPROM.read(EEPROM_ADDR + i);
|
||||||
|
Serial.print("read from eeprom: ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print((uint8_t)x);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(x);
|
||||||
|
*(((char*)(&configBlock))+i) = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Serial.print("Magic: ");
|
||||||
|
Serial.println(configBlock.magic);
|
||||||
|
|
||||||
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
||||||
|
|
||||||
@ -50,7 +64,7 @@ void setup() {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("Configuration mode");
|
Serial.println("Configuration mode");
|
||||||
#endif
|
#endif
|
||||||
|
digitalWrite(LED_PIN, HIGH);
|
||||||
setupConfiguration();
|
setupConfiguration();
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -60,6 +74,7 @@ void setup() {
|
|||||||
showConfiguration();
|
showConfiguration();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
digitalWrite(LED_PIN, LOW);
|
||||||
setupProduction();
|
setupProduction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
|
|
||||||
@ -10,10 +12,22 @@ tConfigBlock configBlock;
|
|||||||
const uint32_t MAGIC = 0xC0DE0001;
|
const uint32_t MAGIC = 0xC0DE0001;
|
||||||
extern ESP8266WebServer webServer;
|
extern ESP8266WebServer webServer;
|
||||||
|
|
||||||
|
|
||||||
void configServeIndex() {
|
void configServeIndex() {
|
||||||
webServer.send(200, "text/html",
|
bool configValid = (configBlock.magic == MAGIC);
|
||||||
""
|
|
||||||
|
if (! configValid) {
|
||||||
|
strcpy(configBlock.wifiSsid, "EG-WLAN");
|
||||||
|
strcpy(configBlock.wifiKey, "shae3sheuthai2oluNgiqueiyahyumeiphughi8jequeil6taethooyeik1joh5");
|
||||||
|
strcpy(configBlock.mqttBroker, "broker.hottis.de");
|
||||||
|
strcpy(configBlock.mqttUser, "esp1");
|
||||||
|
strcpy(configBlock.mqttPass, "geheim123");
|
||||||
|
strcpy(configBlock.mqttClientId, "espClient1");
|
||||||
|
strcpy(configBlock.mqttTopic, "IoT/espThermometer2/espTherm1/measurement");
|
||||||
|
configBlock.mqttPort = 8883;
|
||||||
|
configBlock.measurePeriod = 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
String buffer =
|
||||||
"<!doctype html"
|
"<!doctype html"
|
||||||
"<html lang=\"en\">"
|
"<html lang=\"en\">"
|
||||||
" <head>"
|
" <head>"
|
||||||
@ -27,7 +41,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"wifiSsid\">Wifi SSID</label>"
|
" <label for\"wifiSsid\">Wifi SSID</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"wifiSsid\" id=\"wifiSsid\""
|
" <input type=\"text\" name=\"wifiSsid\" id=\"wifiSsid\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"32\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.wifiSsid;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -35,7 +56,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"wifiKey\">Wifi Key</label>"
|
" <label for\"wifiKey\">Wifi Key</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"wifiKey\" id=\"wifiKey\""
|
" <input type=\"text\" name=\"wifiKey\" id=\"wifiKey\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"64\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.wifiKey;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -43,7 +71,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttBroker\">MQTT Broker</label>"
|
" <label for\"mqttBroker\">MQTT Broker</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttBroker\" id=\"mqttBroker\""
|
" <input type=\"text\" name=\"mqttBroker\" id=\"mqttBroker\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"64\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttBroker;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -51,7 +86,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttUser\">MQTT Username</label>"
|
" <label for\"mqttUser\">MQTT Username</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttUser\" id=\"mqttUser\""
|
" <input type=\"text\" name=\"mqttUser\" id=\"mqttUser\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"32\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttUser;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -59,7 +101,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttPass\">MQTT Password</label>"
|
" <label for\"mqttPass\">MQTT Password</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttPass\" id=\"mqttPass\""
|
" <input type=\"text\" name=\"mqttPass\" id=\"mqttPass\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"32\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttPass;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -67,7 +116,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttClientId\">MQTT ClientId</label>"
|
" <label for\"mqttClientId\">MQTT ClientId</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttClientId\" id=\"mqttClientId\""
|
" <input type=\"text\" name=\"mqttClientId\" id=\"mqttClientId\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"32\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttClientId;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -75,7 +131,14 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttTopic\">MQTT Topic</label>"
|
" <label for\"mqttTopic\">MQTT Topic</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttTopic\" id=\"mqttTopic\""
|
" <input type=\"text\" name=\"mqttTopic\" id=\"mqttTopic\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"64\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttTopic;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -83,7 +146,13 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"mqttPort\">MQTT Port</label>"
|
" <label for\"mqttPort\">MQTT Port</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\""
|
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\" ";
|
||||||
|
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttPort;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -91,7 +160,13 @@ void configServeIndex() {
|
|||||||
" <td>"
|
" <td>"
|
||||||
" <label for\"measurePeriod\">Measure Period</label>"
|
" <label for\"measurePeriod\">Measure Period</label>"
|
||||||
" </td><td>"
|
" </td><td>"
|
||||||
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\""
|
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\" ";
|
||||||
|
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.measurePeriod;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
" </tr>"
|
" </tr>"
|
||||||
@ -103,8 +178,9 @@ void configServeIndex() {
|
|||||||
" </table>"
|
" </table>"
|
||||||
" </form>"
|
" </form>"
|
||||||
" </body>"
|
" </body>"
|
||||||
"</html>"
|
"</html>";
|
||||||
);
|
|
||||||
|
webServer.send(200, "text/html", buffer);
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -118,30 +194,56 @@ void configServeGetConfiguration() {
|
|||||||
arg = webServer.arg("wifiSsid");
|
arg = webServer.arg("wifiSsid");
|
||||||
Serial.print("wifiSsid");
|
Serial.print("wifiSsid");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.wifiSsid, arg.c_str());
|
||||||
arg = webServer.arg("wifiKey");
|
arg = webServer.arg("wifiKey");
|
||||||
Serial.print("wifiKey");
|
Serial.print("wifiKey");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.wifiKey, arg.c_str());
|
||||||
arg = webServer.arg("mqttBroker");
|
arg = webServer.arg("mqttBroker");
|
||||||
Serial.print("mqttBroker");
|
Serial.print("mqttBroker");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.mqttBroker, arg.c_str());
|
||||||
arg = webServer.arg("mqttUser");
|
arg = webServer.arg("mqttUser");
|
||||||
Serial.print("mqttUser");
|
Serial.print("mqttUser");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.mqttUser, arg.c_str());
|
||||||
arg = webServer.arg("mqttPass");
|
arg = webServer.arg("mqttPass");
|
||||||
Serial.print("mqttPass");
|
Serial.print("mqttPass");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.mqttPass, arg.c_str());
|
||||||
arg = webServer.arg("mqttClientId");
|
arg = webServer.arg("mqttClientId");
|
||||||
Serial.print("mqttClientId");
|
Serial.print("mqttClientId");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.mqttClientId, arg.c_str());
|
||||||
arg = webServer.arg("mqttTopic");
|
arg = webServer.arg("mqttTopic");
|
||||||
Serial.print("mqttTopic");
|
Serial.print("mqttTopic");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
strcpy(configBlock.mqttTopic, arg.c_str());
|
||||||
arg = webServer.arg("mqttPort");
|
arg = webServer.arg("mqttPort");
|
||||||
Serial.print("mqttPort");
|
Serial.print("mqttPort");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
configBlock.mqttPort = atoi(arg.c_str());
|
||||||
arg = webServer.arg("measurePeriod");
|
arg = webServer.arg("measurePeriod");
|
||||||
Serial.print("measurePeriod");
|
Serial.print("measurePeriod");
|
||||||
Serial.println(arg);
|
Serial.println(arg);
|
||||||
|
configBlock.measurePeriod = atoi(arg.c_str());
|
||||||
|
|
||||||
|
configBlock.magic = MAGIC;
|
||||||
|
|
||||||
|
showConfiguration();
|
||||||
|
|
||||||
|
EEPROM.begin(512);
|
||||||
|
for (uint16_t i = 0; i < sizeof(configBlock); i++) {
|
||||||
|
char c = *(((char*)(&configBlock))+i);
|
||||||
|
Serial.print("write to eeprom: ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(c);
|
||||||
|
EEPROM.write(EEPROM_ADDR + i, c);
|
||||||
|
}
|
||||||
|
EEPROM.commit();
|
||||||
|
|
||||||
|
Serial.println("EEPROM saved");
|
||||||
|
|
||||||
webServer.send(200, "text/html", "configuration saved");
|
webServer.send(200, "text/html", "configuration saved");
|
||||||
}
|
}
|
||||||
@ -149,6 +251,9 @@ void configServeGetConfiguration() {
|
|||||||
void showConfiguration() {
|
void showConfiguration() {
|
||||||
Serial.println("Configuration is");
|
Serial.println("Configuration is");
|
||||||
|
|
||||||
|
Serial.print("magic = ");
|
||||||
|
Serial.println(configBlock.magic);
|
||||||
|
|
||||||
Serial.print("wifiSsid = ");
|
Serial.print("wifiSsid = ");
|
||||||
Serial.println(configBlock.wifiSsid);
|
Serial.println(configBlock.wifiSsid);
|
||||||
|
|
||||||
|
@ -8,9 +8,14 @@
|
|||||||
#ifndef DEFINES_H_
|
#ifndef DEFINES_H_
|
||||||
#define DEFINES_H_
|
#define DEFINES_H_
|
||||||
|
|
||||||
#define DEBUG
|
// #define DEBUG
|
||||||
//#define SLEEP
|
#define SLEEP
|
||||||
|
|
||||||
|
#define EEPROM_ADDR 0
|
||||||
|
|
||||||
|
#define CONFIG_SWITCH 4
|
||||||
|
#define LED_PIN 14
|
||||||
|
#define ONE_WIRE_BUS 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
WiFiClientSecure espClient;
|
WiFiClientSecure espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
|
|
||||||
#define ONE_WIRE_BUS 2
|
|
||||||
OneWire oneWire(ONE_WIRE_BUS);
|
OneWire oneWire(ONE_WIRE_BUS);
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
@ -161,7 +160,7 @@ void loopProduction() {
|
|||||||
Serial.println("Sleeping");
|
Serial.println("Sleeping");
|
||||||
#endif
|
#endif
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
ESP.deepSleep(configBlock.sleepTime * 1000000);
|
ESP.deepSleep(configBlock.measurePeriod * 1000000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user