diff --git a/EspThermometer2.h b/EspThermometer2.h deleted file mode 100644 index 7711278..0000000 --- a/EspThermometer2.h +++ /dev/null @@ -1,22 +0,0 @@ -// Only modify this file to include -// - function definitions (prototypes) -// - include files -// - extern variable definitions -// In the appropriate section - -#ifndef _EspThermometer2_H_ -#define _EspThermometer2_H_ -#include "Arduino.h" -//add your includes for the project EspThermometer2 here - - -//end of add your includes here - - -//add your function definitions for the project EspThermometer2 here - - - - -//Do not add code below this line -#endif /* _EspThermometer2_H_ */ diff --git a/configurationMode.cpp b/configurationMode.cpp deleted file mode 100644 index 9b2c863..0000000 --- a/configurationMode.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * configurationMode.cpp - * - * Created on: Aug 20, 2017 - * Author: wn - */ - -#include "defines.h" - -#include -#include -#include -#include - - -#include "configurationMode.h" -#include "configuration.h" - - -const char* CONFIG_SSID = "espTherm"; - - -ESP8266WebServer webServer(80); - - - -void configServeNotFound() { - webServer.send(404, "text/plain", "page not found"); -#ifdef DEBUG - Serial.println("page not found served"); -#endif -} - - - -void setupConfigurationNetwork() { - WiFi.mode(WIFI_AP); - WiFi.softAP(CONFIG_SSID); -#ifdef DEBUG - Serial.println("AP started"); -#endif -} - -void setupConfigurationServer() { - webServer.on("/", configServeIndex); - webServer.on("/config", configServeGetConfiguration); - webServer.onNotFound(configServeNotFound); - webServer.begin(); -#ifdef DEBUG - Serial.println("Webserver started"); -#endif -} - -void loopConfiguration() { - webServer.handleClient(); -} - - - diff --git a/configurationMode.h b/configurationMode.h deleted file mode 100644 index 59f5e19..0000000 --- a/configurationMode.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * configurationMode.h - * - * Created on: Aug 20, 2017 - * Author: wn - */ - -#ifndef CONFIGURATIONMODE_H_ -#define CONFIGURATIONMODE_H_ - - - -void setupConfigurationNetwork(); -void setupConfigurationServer(); -void loopConfiguration(); - - -#endif /* CONFIGURATIONMODE_H_ */ diff --git a/productionMode.h b/productionMode.h deleted file mode 100644 index 305ba93..0000000 --- a/productionMode.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * productionMode.h - * - * Created on: Aug 20, 2017 - * Author: wn - */ - -#ifndef PRODUCTIONMODE_H_ -#define PRODUCTIONMODE_H_ - - -void setupProduction(); -void loopProduction(); - - -#endif /* PRODUCTIONMODE_H_ */ diff --git a/sketch/ConfigDataStructure.py b/sketch/ConfigDataStructure.py new file mode 100644 index 0000000..ce942c2 --- /dev/null +++ b/sketch/ConfigDataStructure.py @@ -0,0 +1,16 @@ +configItems = [ + {"label":"_", "key":"magic", "type":"I", "default": ""}, + {"label":"Wifi SSID", "key":"wifiSsid", "type":"C", "length":32, "default":"test"}, + {"label":"Wifi Key", "key":"wifiKey", "type":"C", "length":64, "default":"geheim"}, + {"label":"MQTT Broker", "key":"mqttBroker", "type":"C", "length":64, "default":"broker.hottis.de"}, + {"label":"MQTT Username", "key":"mqttUser", "type":"C", "length":32, "default":"esp1"}, + {"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim"}, + {"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"changeThis"}, + {"label":"MQTT Topic", "key":"mqttTopic", "type":"C", "length":64, "default":"IoT/espThermometer2/measurement"}, + {"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":8883}, + {"label":"Measure Period", "key":"measurePeriod", "type":"I", "default":300} +] + +magic = 0xC0DE0076 +appName = "ESP8266 based Thermometer" + diff --git a/productionMode.cpp b/sketch/application.cpp similarity index 54% rename from productionMode.cpp rename to sketch/application.cpp index 6b71cb9..24e1af5 100644 --- a/productionMode.cpp +++ b/sketch/application.cpp @@ -28,39 +28,9 @@ DallasTemperature sensors(&oneWire); extern uint32_t startTime; -void setup_wifi() { - delay(10); - WiFi.mode(WIFI_STA); - // We start by connecting to a WiFi network -#ifdef DEBUG - Serial.println(); - Serial.print("Connecting to "); - Serial.println(configBlock.wifiSsid); -#endif - - WiFi.begin(configBlock.wifiSsid, configBlock.wifiKey); - - while (WiFi.status() != WL_CONNECTED) { - delay(50); -#ifdef DEBUG - Serial.print("."); -#endif - } - -#ifdef DEBUG - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); -#endif -} - - - -void setupProduction() { - setup_wifi(); - client.setServer(configBlock.mqttBroker, configBlock.mqttPort); +void setupApplication() { + mqttSetup() sensors.begin(); #ifdef DEBUG @@ -72,42 +42,6 @@ void setupProduction() { sensors.setResolution(12); } -void reconnect() { - // Loop until we're reconnected - while (!client.connected()) { -#ifdef DEBUG - Serial.print("Attempting MQTT connection..."); -#endif - // Attempt to connect - //char clientId[128]; - //snprintf(clientId, 127, "esp%s", WiFi.macAddress().c_str()); - if (client.connect(configBlock.mqttClientId, configBlock.mqttUser, configBlock.mqttPass)) { -#ifdef DEBUG - Serial.println("connected"); -#endif - // Once connected, publish an announcement... - //client.publish("IoT/espThermometer/status", "hello world"); - } else { -#ifdef DEBUG - Serial.print("failed, rc="); - Serial.print(client.state()); - Serial.println(" try again in 5 seconds"); -#endif - // Wait 5 seconds before retrying - delay(5000); - } - } -} - - -void mqtt_connect() { - if (!client.connected()) { - reconnect(); - } - client.loop(); -} - - void read_thermometer() { sensors.requestTemperatures(); @@ -144,9 +78,9 @@ void read_thermometer() { } -void loopProduction() { +void loopApplication() { static uint32_t lastMillis = 0; - mqtt_connect(); + mqttLoop(); uint32_t currentMillis = millis(); if (currentMillis - lastMillis > 1000) { diff --git a/sketch/application.h b/sketch/application.h new file mode 100644 index 0000000..0305589 --- /dev/null +++ b/sketch/application.h @@ -0,0 +1,16 @@ +/* + * application.h + * + * Created on: Aug 20, 2017 + * Author: wn + */ + +#ifndef APPLICATION_H_ +#define APPLICATION_H_ + + +void setupApplication(); +void loopApplication(); + + +#endif /* APPLICATION_H_ */ diff --git a/sketch/sketch.ino b/sketch/sketch.ino new file mode 100644 index 0000000..edacb3b --- /dev/null +++ b/sketch/sketch.ino @@ -0,0 +1,21 @@ +// Do not remove the include below +// #include "rgbled.h" +#include "Arduino.h" + + +#include + +//The setup function is called once at startup of the sketch +void setup() +{ +// Add your initialization code here + mainSetup(); +} + +// The loop function is called in an endless loop +void loop() +{ +//Add your repeated code here + mainLoop(); +} +