configuration also in production mode, sensing after reconnect handling

This commit is contained in:
Wolfgang Hottgenroth
2018-02-01 16:25:14 +01:00
parent ef210ab477
commit 88736f288b
8 changed files with 73 additions and 42 deletions

View File

@ -184,10 +184,10 @@ environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.DTS
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.DTS/value=0 environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.DTS/value=0
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/value=1517307730 environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.LOCAL/value=1517501856
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/value=1517304130 environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.UTC/value=1517498256
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/value=3600 environment/project/io.sloeber.core.toolChain.release.547546691/A.EXTRA.TIME.ZONE/value=3600
@ -466,10 +466,10 @@ environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.BOARD_NAM
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.BOARD_NAME/value=NodeMCU 1.0 (ESP-12E Module) environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.BOARD_NAME/value=NodeMCU 1.0 (ESP-12E Module)
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/value=/dev/ttyUSB0 environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.COM_PORT/value=/dev/ttyUSB1
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}///////////////////////////////////// environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}//////////////////////////////////////////////////////////////////////////////////////////////////////
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/operation=replace environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/operation=replace
environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/value= environment/project/io.sloeber.core.toolChain.release.547546691/JANTJE.EXTRA.ALL/value=

View File

@ -125,8 +125,9 @@ void showConfiguration() {
Serial.println("Configuration is"); Serial.println("Configuration is");
#for $configItem in $configItems #for $configItem in $configItems
Serial.print("$configItem.key = "); Serial.print("$configItem.key = <");
Serial.println(configBlock.$configItem.key); Serial.print(configBlock.$configItem.key);
Serial.println(">");
#end for #end for

View File

@ -44,7 +44,8 @@ void setup() {
Serial.println("Configuration mode"); Serial.println("Configuration mode");
#endif #endif
digitalWrite(LED_PIN, LOW); digitalWrite(LED_PIN, LOW);
setupConfiguration(); setupConfigurationNetwork();
setupConfigurationServer();
} else { } else {
#ifdef DEBUG #ifdef DEBUG
Serial.println("Production mode"); Serial.println("Production mode");
@ -55,6 +56,7 @@ void setup() {
digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN, HIGH);
setupProduction(); setupProduction();
setupConfigurationServer();
} }
#ifdef DEBUG #ifdef DEBUG
@ -66,6 +68,7 @@ void loop() {
if (configMode) { if (configMode) {
loopConfiguration(); loopConfiguration();
} else { } else {
loopConfiguration();
loopProduction(); loopProduction();
} }
} }

View File

@ -325,50 +325,65 @@ void configServeGetConfiguration() {
void showConfiguration() { void showConfiguration() {
Serial.println("Configuration is"); Serial.println("Configuration is");
Serial.print("magic = "); Serial.print("magic = <");
Serial.println(configBlock.magic); Serial.print(configBlock.magic);
Serial.println(">");
Serial.print("wifiSsid = "); Serial.print("wifiSsid = <");
Serial.println(configBlock.wifiSsid); Serial.print(configBlock.wifiSsid);
Serial.println(">");
Serial.print("wifiKey = "); Serial.print("wifiKey = <");
Serial.println(configBlock.wifiKey); Serial.print(configBlock.wifiKey);
Serial.println(">");
Serial.print("mqttBroker = "); Serial.print("mqttBroker = <");
Serial.println(configBlock.mqttBroker); Serial.print(configBlock.mqttBroker);
Serial.println(">");
Serial.print("mqttUser = "); Serial.print("mqttUser = <");
Serial.println(configBlock.mqttUser); Serial.print(configBlock.mqttUser);
Serial.println(">");
Serial.print("mqttPass = "); Serial.print("mqttPass = <");
Serial.println(configBlock.mqttPass); Serial.print(configBlock.mqttPass);
Serial.println(">");
Serial.print("mqttClientId = "); Serial.print("mqttClientId = <");
Serial.println(configBlock.mqttClientId); Serial.print(configBlock.mqttClientId);
Serial.println(">");
Serial.print("mqttPort = "); Serial.print("mqttPort = <");
Serial.println(configBlock.mqttPort); Serial.print(configBlock.mqttPort);
Serial.println(">");
Serial.print("mqttTopic = "); Serial.print("mqttTopic = <");
Serial.println(configBlock.mqttTopic); Serial.print(configBlock.mqttTopic);
Serial.println(">");
Serial.print("mqttDebugTopic = "); Serial.print("mqttDebugTopic = <");
Serial.println(configBlock.mqttDebugTopic); Serial.print(configBlock.mqttDebugTopic);
Serial.println(">");
Serial.print("mqttBaselineTopic = "); Serial.print("mqttBaselineTopic = <");
Serial.println(configBlock.mqttBaselineTopic); Serial.print(configBlock.mqttBaselineTopic);
Serial.println(">");
Serial.print("debugMode = "); Serial.print("debugMode = <");
Serial.println(configBlock.debugMode); Serial.print(configBlock.debugMode);
Serial.println(">");
Serial.print("period = "); Serial.print("period = <");
Serial.println(configBlock.period); Serial.print(configBlock.period);
Serial.println(">");
Serial.print("calibrationTimeout = "); Serial.print("calibrationTimeout = <");
Serial.println(configBlock.calibrationTimeout); Serial.print(configBlock.calibrationTimeout);
Serial.println(">");
Serial.print("threshold = "); Serial.print("threshold = <");
Serial.println(configBlock.threshold); Serial.print(configBlock.threshold);
Serial.println(">");
Serial.println("---"); Serial.println("---");

View File

@ -33,13 +33,15 @@ void configServeNotFound() {
void setupConfiguration() { void setupConfigurationNetwork() {
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.softAP(CONFIG_SSID); WiFi.softAP(CONFIG_SSID);
#ifdef DEBUG #ifdef DEBUG
Serial.println("AP started"); Serial.println("AP started");
#endif #endif
}
void setupConfigurationServer() {
webServer.on("/", configServeIndex); webServer.on("/", configServeIndex);
webServer.on("/config", configServeGetConfiguration); webServer.on("/config", configServeGetConfiguration);
webServer.onNotFound(configServeNotFound); webServer.onNotFound(configServeNotFound);

View File

@ -10,7 +10,8 @@
void setupConfiguration(); void setupConfigurationNetwork();
void setupConfigurationServer();
void loopConfiguration(); void loopConfiguration();

View File

@ -8,7 +8,7 @@
#ifndef DEFINES_H_ #ifndef DEFINES_H_
#define DEFINES_H_ #define DEFINES_H_
//#define DEBUG #define DEBUG
#define EEPROM_ADDR 0 #define EEPROM_ADDR 0
@ -17,9 +17,14 @@
// These both pins are connected via a 470k resistor. // These both pins are connected via a 470k resistor.
// The insulated touchpad is connected to pin TOUCH_PIN_RECEIVE. // The insulated touchpad is connected to pin TOUCH_PIN_RECEIVE.
#if 1
#define TOUCH_PIN_RECEIVE 16 #define TOUCH_PIN_RECEIVE 16
#define TOUCH_PIN_SEND 5 #define TOUCH_PIN_SEND 5
#endif
#if 0
#define TOUCH_PIN_RECEIVE 0
#define TOUCH_PIN_SEND 2
#endif
#endif /* DEFINES_H_ */ #endif /* DEFINES_H_ */

View File

@ -105,6 +105,10 @@ void setupProduction() {
void loopProduction() { void loopProduction() {
bool reconnected = mqtt_connect(); bool reconnected = mqtt_connect();
static uint32_t reconnectTime = 0;
if (reconnected) {
reconnectTime = millis();
}
@ -137,7 +141,7 @@ void loopProduction() {
uint32_t currentMillis = millis(); uint32_t currentMillis = millis();
if ((currentMillis - lastMillis > configBlock.period) && (! reconnected)) { if ((currentMillis - lastMillis > configBlock.period) && (currentMillis - reconnectTime > 1000)) {
lastMillis = currentMillis; lastMillis = currentMillis;
uint32_t chargeCntAvg = chargeCntSum / senseCnt; uint32_t chargeCntAvg = chargeCntSum / senseCnt;