works so far

This commit is contained in:
Wolfgang Hottgenroth 2017-08-21 10:47:48 +02:00
parent b92451eb98
commit 62e98675d8
6 changed files with 205 additions and 33 deletions

View File

@ -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.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/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/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/operation=replace
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.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/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/operation=replace
environment/project/io.sloeber.core.toolChain.release.936970421/JANTJE.EXTRA.C.COMPILE/value=

View File

@ -3,7 +3,9 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include "defines.h"
#include "configuration.h"
#end raw
@ -12,10 +14,22 @@ tConfigBlock configBlock;
const uint32_t MAGIC = 0xC0DE0001;
extern ESP8266WebServer webServer;
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"
"<html lang=\"en\">"
" <head>"
@ -31,7 +45,20 @@ void configServeIndex() {
" <td>"
" <label for\"$configItem.key\">$configItem.label</label>"
" </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>"
" </tr>"
@ -45,8 +72,9 @@ void configServeIndex() {
" </table>"
" </form>"
" </body>"
"</html>"
);
"</html>";
webServer.send(200, "text/html", buffer);
#ifdef DEBUG
@ -62,9 +90,31 @@ void configServeGetConfiguration() {
arg = webServer.arg("$configItem.key");
Serial.print("$configItem.key");
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 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");
}
@ -72,11 +122,9 @@ void showConfiguration() {
Serial.println("Configuration is");
#for $configItem in $configItems
#if $configItem.label != "_"
Serial.print("$configItem.key = ");
Serial.println(configBlock.$configItem.key);
#end if
#end for
Serial.println("---");

View File

@ -22,12 +22,10 @@ ADC_MODE(ADC_VCC);
#define CONFIG_SWITCH 4
bool configMode = false;
const uint16_t EEPROM_ADDR = 0;
uint32_t startTime = 0;
@ -41,8 +39,24 @@ void setup() {
#endif
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));
@ -50,7 +64,7 @@ void setup() {
#ifdef DEBUG
Serial.println("Configuration mode");
#endif
digitalWrite(LED_PIN, HIGH);
setupConfiguration();
} else {
#ifdef DEBUG
@ -60,6 +74,7 @@ void setup() {
showConfiguration();
#endif
digitalWrite(LED_PIN, LOW);
setupProduction();
}

View File

@ -2,7 +2,9 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include "defines.h"
#include "configuration.h"
@ -10,10 +12,22 @@ tConfigBlock configBlock;
const uint32_t MAGIC = 0xC0DE0001;
extern ESP8266WebServer webServer;
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"
"<html lang=\"en\">"
" <head>"
@ -27,7 +41,14 @@ void configServeIndex() {
" <td>"
" <label for\"wifiSsid\">Wifi SSID</label>"
" </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>"
" </tr>"
@ -35,7 +56,14 @@ void configServeIndex() {
" <td>"
" <label for\"wifiKey\">Wifi Key</label>"
" </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>"
" </tr>"
@ -43,7 +71,14 @@ void configServeIndex() {
" <td>"
" <label for\"mqttBroker\">MQTT Broker</label>"
" </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>"
" </tr>"
@ -51,7 +86,14 @@ void configServeIndex() {
" <td>"
" <label for\"mqttUser\">MQTT Username</label>"
" </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>"
" </tr>"
@ -59,7 +101,14 @@ void configServeIndex() {
" <td>"
" <label for\"mqttPass\">MQTT Password</label>"
" </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>"
" </tr>"
@ -67,7 +116,14 @@ void configServeIndex() {
" <td>"
" <label for\"mqttClientId\">MQTT ClientId</label>"
" </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>"
" </tr>"
@ -75,7 +131,14 @@ void configServeIndex() {
" <td>"
" <label for\"mqttTopic\">MQTT Topic</label>"
" </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>"
" </tr>"
@ -83,7 +146,13 @@ void configServeIndex() {
" <td>"
" <label for\"mqttPort\">MQTT Port</label>"
" </td><td>"
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\""
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\" ";
buffer += " value=\"";
buffer += configBlock.mqttPort;
buffer += "\"";
buffer +=
" />"
" </td>"
" </tr>"
@ -91,7 +160,13 @@ void configServeIndex() {
" <td>"
" <label for\"measurePeriod\">Measure Period</label>"
" </td><td>"
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\""
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\" ";
buffer += " value=\"";
buffer += configBlock.measurePeriod;
buffer += "\"";
buffer +=
" />"
" </td>"
" </tr>"
@ -103,8 +178,9 @@ void configServeIndex() {
" </table>"
" </form>"
" </body>"
"</html>"
);
"</html>";
webServer.send(200, "text/html", buffer);
#ifdef DEBUG
@ -118,30 +194,56 @@ void configServeGetConfiguration() {
arg = webServer.arg("wifiSsid");
Serial.print("wifiSsid");
Serial.println(arg);
strcpy(configBlock.wifiSsid, arg.c_str());
arg = webServer.arg("wifiKey");
Serial.print("wifiKey");
Serial.println(arg);
strcpy(configBlock.wifiKey, arg.c_str());
arg = webServer.arg("mqttBroker");
Serial.print("mqttBroker");
Serial.println(arg);
strcpy(configBlock.mqttBroker, arg.c_str());
arg = webServer.arg("mqttUser");
Serial.print("mqttUser");
Serial.println(arg);
strcpy(configBlock.mqttUser, arg.c_str());
arg = webServer.arg("mqttPass");
Serial.print("mqttPass");
Serial.println(arg);
strcpy(configBlock.mqttPass, arg.c_str());
arg = webServer.arg("mqttClientId");
Serial.print("mqttClientId");
Serial.println(arg);
strcpy(configBlock.mqttClientId, arg.c_str());
arg = webServer.arg("mqttTopic");
Serial.print("mqttTopic");
Serial.println(arg);
strcpy(configBlock.mqttTopic, arg.c_str());
arg = webServer.arg("mqttPort");
Serial.print("mqttPort");
Serial.println(arg);
configBlock.mqttPort = atoi(arg.c_str());
arg = webServer.arg("measurePeriod");
Serial.print("measurePeriod");
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");
}
@ -149,6 +251,9 @@ void configServeGetConfiguration() {
void showConfiguration() {
Serial.println("Configuration is");
Serial.print("magic = ");
Serial.println(configBlock.magic);
Serial.print("wifiSsid = ");
Serial.println(configBlock.wifiSsid);

View File

@ -8,9 +8,14 @@
#ifndef DEFINES_H_
#define DEFINES_H_
#define DEBUG
//#define SLEEP
// #define DEBUG
#define SLEEP
#define EEPROM_ADDR 0
#define CONFIG_SWITCH 4
#define LED_PIN 14
#define ONE_WIRE_BUS 2

View File

@ -22,7 +22,6 @@
WiFiClientSecure espClient;
PubSubClient client(espClient);
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
@ -161,7 +160,7 @@ void loopProduction() {
Serial.println("Sleeping");
#endif
client.disconnect();
ESP.deepSleep(configBlock.sleepTime * 1000000);
ESP.deepSleep(configBlock.measurePeriod * 1000000);
#endif
}