first working version
This commit is contained in:
parent
91c2841ef5
commit
78370e34dd
@ -184,10 +184,10 @@ environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.DT
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.DTS/value=3600
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.LOCAL/delimiter=\:
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.LOCAL/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.LOCAL/value=1524433102
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.LOCAL/value=1524511581
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.UTC/delimiter=\:
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.UTC/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.UTC/value=1524425902
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.UTC/value=1524504381
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.ZONE/delimiter=\:
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.ZONE/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/A.EXTRA.TIME.ZONE/value=3600
|
||||
@ -469,7 +469,7 @@ environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.COM_PORT
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.COM_PORT/value=/dev/ttyUSB5
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.ECLIPSE_LOCATION/delimiter=\:
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.ECLIPSE_LOCATION/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}/////////////////
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}/////////////////////////////////////
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.EXTRA.ALL/delimiter=\:
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.EXTRA.ALL/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1856809793/JANTJE.EXTRA.ALL/value=
|
||||
|
@ -19,11 +19,12 @@ configItems = [
|
||||
{"label":"MQTT Topic", "key":"mqttTopic", "type":"C", "length":64, "default":"IoT/RainSensor1/Value"},
|
||||
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RainSensor1/Debug"},
|
||||
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0},
|
||||
{"label":"Period", "key":"period", "type":"I", "default":300}
|
||||
{"label":"Period (s)", "key":"period", "type":"I", "default":5},
|
||||
{"label":"Debounce (us)", "key":"debounce", "type":"I", "default":300}
|
||||
]
|
||||
|
||||
|
||||
magic = 0xC0DE0003
|
||||
magic = 0xC0DE0004
|
||||
appName = "ESP8266 based RainSensor"
|
||||
confWifiSsid = "espconfig"
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = 3235774467;
|
||||
const uint32_t MAGIC = 3235774468;
|
||||
const char* CONFIG_SSID = "espconfig";
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
@ -39,7 +39,8 @@ void configServeIndex() {
|
||||
strcpy(configBlock.mqttTopic, "IoT/RainSensor1/Value");
|
||||
strcpy(configBlock.mqttDebugTopic, "IoT/RainSensor1/Debug");
|
||||
configBlock.debugMode = 0;
|
||||
configBlock.period = 500;
|
||||
configBlock.period = 5;
|
||||
configBlock.debounce = 300;
|
||||
}
|
||||
|
||||
if (! checkAuthentication()) {
|
||||
@ -244,7 +245,7 @@ void configServeIndex() {
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"period\">Period</label>"
|
||||
" <label for\"period\">Period (s)</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"period\" id=\"period\" ";
|
||||
|
||||
@ -252,6 +253,20 @@ void configServeIndex() {
|
||||
buffer += configBlock.period;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"debounce\">Debounce (us)</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"debounce\" id=\"debounce\" ";
|
||||
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.debounce;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
@ -307,6 +322,8 @@ void configServeGetConfiguration() {
|
||||
configBlock.debugMode = atoi(arg.c_str());
|
||||
arg = webServer.arg("period");
|
||||
configBlock.period = atoi(arg.c_str());
|
||||
arg = webServer.arg("debounce");
|
||||
configBlock.debounce = atoi(arg.c_str());
|
||||
|
||||
configBlock.magic = MAGIC;
|
||||
|
||||
@ -383,6 +400,10 @@ void showConfiguration() {
|
||||
Serial.print(configBlock.period);
|
||||
Serial.println(">");
|
||||
|
||||
Serial.print("debounce = <");
|
||||
Serial.print(configBlock.debounce);
|
||||
Serial.println(">");
|
||||
|
||||
|
||||
Serial.println("---");
|
||||
}
|
@ -13,6 +13,7 @@ typedef struct {
|
||||
char mqttDebugTopic[64];
|
||||
uint32_t debugMode;
|
||||
uint32_t period;
|
||||
uint32_t debounce;
|
||||
} tConfigBlock;
|
||||
|
||||
extern const uint32_t MAGIC;
|
||||
|
@ -13,6 +13,6 @@
|
||||
#define EEPROM_ADDR 0
|
||||
|
||||
#define CONFIG_SWITCH 0
|
||||
#define HALL_PIN 2
|
||||
#define HALL_PIN 13
|
||||
|
||||
#endif /* DEFINES_H_ */
|
||||
|
@ -27,7 +27,12 @@ PubSubClient client(espClient);
|
||||
|
||||
|
||||
void count() {
|
||||
cnt++;
|
||||
static uint32_t lastEvent = 0;
|
||||
uint32_t currentEvent = micros();
|
||||
if (currentEvent > (lastEvent + configBlock.debounce)) {
|
||||
lastEvent = currentEvent;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
void setup_wifi() {
|
||||
@ -124,7 +129,6 @@ void loopProduction() {
|
||||
|
||||
static uint32_t lastMillis = 0;
|
||||
uint32_t currentMillis = millis();
|
||||
|
||||
if (currentMillis > (lastMillis + (configBlock.period * 1000))) {
|
||||
lastMillis = currentMillis;
|
||||
|
||||
@ -134,10 +138,18 @@ void loopProduction() {
|
||||
cnt = 0;
|
||||
interrupts();
|
||||
|
||||
uint16_t battery = analogRead(A0);
|
||||
|
||||
#define BUF_SIZE 128
|
||||
char buf[BUF_SIZE];
|
||||
snprintf(buf, BUF_SIZE-1, "{\"value\":%ld, \"battery\":%ld}", myCnt, battery);
|
||||
client.publish(configBlock.mqttTopic, buf);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println(myCnt);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user