adding publish interval for sensor

This commit is contained in:
Robert van den Breemen 2021-03-14 21:58:35 +01:00
parent d7e70b4d74
commit 38ec4e4d5e
8 changed files with 60 additions and 37 deletions

View File

@ -97,6 +97,7 @@ bool settingLEDblink = true;
// GPIO Sensor Settings
bool settingGPIOSENSORSenabled = false;
int8_t settingGPIOSENSORSpin = 10;
int16_t settingGPIOSENSORSinterval = 5;
//Now load network suff
#include "networkStuff.h"

View File

@ -33,6 +33,8 @@
#define ON LOW
#define OFF HIGH
DECLARE_TIMER_SEC(timerpollsensor, settingGPIOSENSORSinterval, CATCH_UP_MISSED_TICKS);
//=====================================================================
void setup() {
// Serial is initialized by OTGWSerial. It resets the pic and opens serialdevice.
@ -62,25 +64,35 @@ void setup() {
blinkLED(LED1, 3, 100);
setLed(LED1, OFF);
OTGWSerial.println(F("Init Telenet"));
startTelnet(); // start the debug port 23
OTGWSerial.println(F("Init MDNS"));
startMDNS(CSTR(settingHostname));
OTGWSerial.println(F("Init LLMNR"));
startLLMNR(CSTR(settingHostname));
OTGWSerial.println(F("Init MQTT"));
startMQTT();
OTGWSerial.println(F("Init NTP"));
startNTP();
OTGWSerial.println(F("Init FSexplorer"));
setupFSexplorer();
OTGWSerial.println(F("Init WebServer"));
startWebserver();
OTGWSerial.println(F("Setup finished!\r\n"));
// After resetting the OTGW PIC never send anything to Serial for debug
// and switch to telnet port 23 for debug purposed.
// Setup the OTGW PIC
OTGWSerial.println(F("Reset OTGW"));
resetOTGW(); // reset the OTGW pic
OTGWSerial.println(F("Start OTGW Stream"));
startOTGWstream(); // start port 25238
OTGWSerial.println(F("Start for Pic"));
checkOTWGpicforupdate();
OTGWSerial.println(F("Start Init Sensor"));
initSensors(); // init DS18B20
OTGWSerial.println(F("Start init Watschdog"));
initWatchDog(); // setup the WatchDog
OTGWSerial.println(F("Finally done!"));
//Blink LED2 to signal setup done
setLed(LED1, OFF);
blinkLED(LED2, 3, 100);
@ -137,7 +149,7 @@ void doTaskEvery1s(){
//===[ Do task every 5s ]===
void doTaskEvery5s(){
//== do tasks ==
pollSensors();
}
//===[ Do task every 30s ]===
@ -184,9 +196,7 @@ void doBackgroundTasks()
handleOTGW(); // OTGW handling
httpServer.handleClient();
MDNS.update();
events(); // trigger ezTime update etc.
// // 'blink' the status led every x ms
// if (settingLEDblink) blinkLEDms(1000);
events(); // trigger ezTime update etc
delay(1);
handleDebug();
}
@ -199,14 +209,14 @@ void loop()
DECLARE_TIMER_SEC(timer60s, 60, CATCH_UP_MISSED_TICKS);
DECLARE_TIMER_MIN(tmrcheckpic, 1440, CATCH_UP_MISSED_TICKS);
DECLARE_TIMER_MIN(timer5min, 5, CATCH_UP_MISSED_TICKS);
if (DUE(timer1s)) doTaskEvery1s();
if (DUE(timer5s)) doTaskEvery5s();
if (DUE(timer30s)) doTaskEvery30s();
if (DUE(timer60s)) doTaskEvery60s();
if (DUE(tmrcheckpic)) docheckforpic();
if (DUE(timer5min)) do5minevent();
if (DUE(timer1s)) doTaskEvery1s();
if (DUE(timer5s)) doTaskEvery5s();
if (DUE(timer30s)) doTaskEvery30s();
if (DUE(timer60s)) doTaskEvery60s();
if (DUE(tmrcheckpic)) docheckforpic();
if (DUE(timer5min)) do5minevent();
if (DUE(timerpollsensor)) pollSensors();
doBackgroundTasks();
}

View File

@ -705,6 +705,7 @@
,[ "bootcount", "Nr. Reboots"]
,[ "ledblink", "Heartbeat LED (on/off)"]
,[ "gpiosensorsenabled", "GPIO Sensors Enabled"]
,[ "gpiosensorinterval", "GPIO Publish Interval (sec)"]
,[ "gpiosensorspin", "GPIO pin # (SD3 = GPIO10 => 10)"]
,[ "mqttotmessage", "MQTT OT msg Enable"]

View File

@ -59,6 +59,8 @@ static FSInfo LittleFSinfo;
bool LittleFSmounted;
bool isConnected = false;
#define WM_DEBUG_PORT OTGWSerial
//gets called when WiFiManager enters configuration mode
//===========================================================================================
void configModeCallback (WiFiManager *myWiFiManager)
@ -98,7 +100,7 @@ void startWiFi(const char* hostname, int timeOut)
//--- if it does not connect it starts an access point with the specified name
//--- here "<HOSTNAME>-<MAC>"
//--- and goes into a blocking loop awaiting configuration
OTGWSerial.printf("AutoConnect to: %s", thisAP.c_str());
OTGWSerial.printf("AutoConnect to: %s\r\n", thisAP.c_str());
if (!manageWiFi.autoConnect(thisAP.c_str()))
{
//-- fail to connect? Have you tried turning it off and on again?
@ -108,12 +110,12 @@ void startWiFi(const char* hostname, int timeOut)
delay(5000); // Enough time to ensure we don't return.
}
//WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Debugln();
DebugT(F("Connected to " )); Debugln (WiFi.SSID());
DebugT(F("IP address: " )); Debugln (WiFi.localIP());
DebugT(F("IP gateway: " )); Debugln (WiFi.gatewayIP());
DebugT(F("Connected to " )); Debugln(WiFi.SSID());
DebugT(F("IP address: " )); Debugln(WiFi.localIP());
DebugT(F("IP gateway: " )); Debugln(WiFi.gatewayIP());
Debugln();
httpUpdater.setup(&httpServer);
@ -128,7 +130,7 @@ void startWiFi(const char* hostname, int timeOut)
//===========================================================================================
void startTelnet()
{
OTGWSerial.print("Use 'telnet ");
OTGWSerial.print("\r\nUse 'telnet ");
OTGWSerial.print(WiFi.localIP());
OTGWSerial.println("' for debugging");
TelnetStream.begin();

View File

@ -414,6 +414,8 @@ void sendDeviceSettings()
sendJsonSettingObj("ledblink", settingLEDblink, "b");
sendJsonSettingObj("gpiosensorsenabled", settingGPIOSENSORSenabled, "b");
sendJsonSettingObj("gpiosensorspin", settingGPIOSENSORSpin, "i", 1, 16);
sendJsonSettingObj("gpiosensorsinterval", settingGPIOSENSORSinterval, "i", 1, 65535);
sendEndJsonObj("settings");
} // sendDeviceSettings()

View File

@ -5,7 +5,9 @@
#include <OneWire.h>
#include <DallasTemperature.h>
char * getDallasAddress(DeviceAddress deviceAddress);
//prototype
char* getDallasAddress(DeviceAddress deviceAddress);
// GPIO where the DS18B20 is connected to
// Data wire is plugged TO GPIO 10
@ -120,7 +122,7 @@ int pollSensors()
}
// function to print a device address
char * getDallasAddress(DeviceAddress deviceAddress)
char* getDallasAddress(DeviceAddress deviceAddress)
{
// DebugTf("\r\n");
static char dest[10];

View File

@ -99,6 +99,7 @@ void readSettings(bool show)
settingLEDblink = doc["LEDblink"]|settingLEDblink;
settingGPIOSENSORSenabled = doc["GPIOSENSORSenabled"] | settingGPIOSENSORSenabled;
settingGPIOSENSORSpin = doc["GPIOSENSORSpin"] | settingGPIOSENSORSpin;
settingGPIOSENSORSinterval = doc["GPIOSENSORSinterval"] | settingGPIOSENSORSinterval;
// Close the file (Curiously, File's destructor doesn't close the file)
file.close();
@ -123,7 +124,8 @@ void readSettings(bool show)
Debugf("Led Blink : %s\r\n", CBOOLEAN(settingLEDblink));
Debugf("GPIO Sensors : %s\r\n", CBOOLEAN(settingGPIOSENSORSenabled));
Debugf("GPIO Sen. Pin : %d\r\n", settingGPIOSENSORSpin);
}
Debugf("GPIO Interval : %s\r\n", CBOOLEAN(settingGPIOSENSORSinterval));
}
Debugln(F("-\r\n"));
@ -183,7 +185,10 @@ void updateSetting(const char *field, const char *newValue)
Debugln();
DebugTf("Need reboot before GPIO SENSORS will use new pin GPIO%d!\r\n\n", settingGPIOSENSORSpin);
}
if (stricmp(field, "GPIOSENSORSinterval") == 0) {
settingGPIOSENSORSinterval = atoi(newValue);
CHANGE_INTERVAL_SEC(timerpollsensor, settingGPIOSENSORSinterval, CATCH_UP_MISSED_TICKS);
}
//finally update write settings
writeSettings(false);

View File

@ -1,16 +1,16 @@
//The version number conforms to semver.org format
#define _VERSION_MAJOR 0
#define _VERSION_MINOR 8
#define _VERSION_PATCH 1
#define _VERSION_BUILD 807
#define _VERSION_GITHASH 92f10cb
//#define _VERSION_PRERELEASE beta //uncomment to define prerelease labels: alpha - beta - rc
#define _VERSION_PATCH 2
#define _VERSION_BUILD 820
#define _VERSION_GITHASH d7e70b4
#define _VERSION_PRERELEASE beta
#define _VERSION_DATE "14-03-2021"
#define _VERSION_TIME "14:56:09"
#define _SEMVER_CORE "0.8.1"
#define _SEMVER_BUILD "0.8.1+807"
#define _SEMVER_GITHASH "0.8.1+92f10cb"
#define _SEMVER_FULL "0.8.1+92f10cb"
#define _SEMVER_NOBUILD "0.8.1 (14-03-2021)"
#define _VERSION "0.8.1+92f10cb (14-03-2021)"
#define _VERSION_TIME "21:58:11"
#define _SEMVER_CORE "0.8.2"
#define _SEMVER_BUILD "0.8.2+820"
#define _SEMVER_GITHASH "0.8.2+d7e70b4"
#define _SEMVER_FULL "0.8.2-beta+d7e70b4"
#define _SEMVER_NOBUILD "0.8.2-beta (14-03-2021)"
#define _VERSION "0.8.2-beta+d7e70b4 (14-03-2021)"
//The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver