more files moved and adjusted to new structure

This commit is contained in:
2019-11-18 16:19:15 +01:00
parent 3fcd00a8a9
commit 44fc14085e
8 changed files with 57 additions and 185 deletions

View 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"

106
sketch/application.cpp Normal file
View File

@ -0,0 +1,106 @@
/*
* production.cpp
*
* Created on: Aug 20, 2017
* Author: wn
*/
#include "defines.h"
#define MQTT_MAX_PACKET_SIZE 256
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "configuration.h"
WiFiClientSecure espClient;
PubSubClient client(espClient);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
extern uint32_t startTime;
void setupApplication() {
mqttSetup()
sensors.begin();
#ifdef DEBUG
uint8_t num = sensors.getDeviceCount();
Serial.print("device count: ");
Serial.println(num);
#endif
sensors.setResolution(12);
}
void read_thermometer() {
sensors.requestTemperatures();
float t = sensors.getTempCByIndex(0);
#ifdef DEBUG
Serial.print(t);
Serial.println();
#endif
int16_t t1 = (int)t;
int16_t t2 = (int)((t - t1)*100);
uint16_t vcc = ESP.getVcc();
uint16_t v1 = vcc / 1000;
uint16_t v2 = (vcc - v1 * 1000);
#ifdef DEBUG
Serial.print(vcc);
Serial.println();
#endif
uint32_t duration = millis() - startTime;
//char topic[128];
//snprintf(topic, 127, "IoT/espThermometer2/%s/measurement", WiFi.macAddress().c_str());
char payload[128];
snprintf(payload, 127, "{\"location\":\"%s\", \"temperature\":%d.%d, \"battery\":%d.%d, \"duration\":%ld}", configBlock.mqttClientId, t1, t2, v1, v2, duration);
#ifdef DEBUG
Serial.println(payload);
#endif
client.publish(configBlock.mqttTopic, payload, true);
}
void loopApplication() {
static uint32_t lastMillis = 0;
mqttLoop();
uint32_t currentMillis = millis();
if (currentMillis - lastMillis > 1000) {
lastMillis = currentMillis;
read_thermometer();
#ifdef SLEEP
#ifdef DEBUG
Serial.println("Sleeping");
#endif
client.disconnect();
ESP.deepSleep(configBlock.measurePeriod * 1000000);
#endif
}
}

16
sketch/application.h Normal file
View 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
View 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();
}