more files moved and adjusted to new structure
This commit is contained in:
parent
3fcd00a8a9
commit
44fc14085e
@ -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_ */
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* configurationMode.cpp
|
||||
*
|
||||
* Created on: Aug 20, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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_ */
|
@ -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_ */
|
16
sketch/ConfigDataStructure.py
Normal file
16
sketch/ConfigDataStructure.py
Normal file
@ -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"
|
||||
|
@ -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) {
|
16
sketch/application.h
Normal file
16
sketch/application.h
Normal file
@ -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_ */
|
21
sketch/sketch.ino
Normal file
21
sketch/sketch.ino
Normal file
@ -0,0 +1,21 @@
|
||||
// Do not remove the include below
|
||||
// #include "rgbled.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#include <main.h>
|
||||
|
||||
//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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user