gpio ot hook
This feature adds the option to trigger a gpio output based on the msid = 0 (status) master salve bridge.
This commit is contained in:
parent
bb64a9aa8d
commit
d51ece9cb7
|
@ -541,6 +541,7 @@ uint16_t print_status()
|
|||
sendMQTTData("centralheating2", (((OTdata.valueLB) & 0x20) ? "ON" : "OFF"));
|
||||
sendMQTTData("diagnostic_indicator", (((OTdata.valueLB) & 0x40) ? "ON" : "OFF"));
|
||||
|
||||
|
||||
uint16_t _value = OTdata.u16();
|
||||
OTGWDebugTf("Status u16 [%04x] _value [%04x] hb [%02x] lb [%02x]\r\n", OTdata.u16(), _value, OTdata.valueHB, OTdata.valueLB);
|
||||
return _value;
|
||||
|
|
|
@ -107,12 +107,18 @@ bool bDebugOTmsg = true;
|
|||
bool bDebugRestAPI = false;
|
||||
bool bDebugMQTT = true;
|
||||
|
||||
// GPIO Output Settings
|
||||
bool settingMyDEBUG = false;
|
||||
bool settingGPIOOUTPUTSenabled = false;
|
||||
int8_t settingGPIOOUTPUTSpin = 16;
|
||||
int8_t settingGPIOOUTPUTStriggerBit = 0;
|
||||
|
||||
//Now load network suff
|
||||
#include "networkStuff.h"
|
||||
|
||||
// That's all folks...
|
||||
// That's all folks...
|
||||
|
||||
/***************************************************************************
|
||||
/***************************************************************************
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
#define OFF HIGH
|
||||
|
||||
DECLARE_TIMER_SEC(timerpollsensor, settingGPIOSENSORSinterval, CATCH_UP_MISSED_TICKS);
|
||||
|
||||
// TODO need to determine interval
|
||||
DECLARE_TIMER_SEC(timersetoutput, settingGPIOSENSORSinterval, CATCH_UP_MISSED_TICKS);
|
||||
|
||||
//=====================================================================
|
||||
void setup() {
|
||||
|
@ -79,6 +82,8 @@ void setup() {
|
|||
startOTGWstream(); // start port 25238
|
||||
checkOTWGpicforupdate();
|
||||
initSensors(); // init DS18B20
|
||||
initOutputs();
|
||||
|
||||
initWatchDog(); // setup the WatchDog
|
||||
sendOTGWbootcmd();
|
||||
//Blink LED2 to signal setup done
|
||||
|
@ -206,6 +211,7 @@ void loop()
|
|||
if (DUE(tmrcheckpic)) docheckforpic();
|
||||
if (DUE(timer5min)) do5minevent();
|
||||
if (DUE(timerpollsensor)) pollSensors();
|
||||
if (DUE(timersetoutput)) evalOutputs();
|
||||
doBackgroundTasks();
|
||||
}
|
||||
|
||||
|
|
|
@ -711,8 +711,9 @@
|
|||
,[ "mqttotmessage", "MQTT OT msg Enable"]
|
||||
,[ "otgwcommandenable", "OTGW Boot Command Enabled"]
|
||||
,[ "otgwcommands", "OTGW Boot Command"]
|
||||
|
||||
|
||||
,[ "gpiooutputsenabled", "GPIO Output Enabled"]
|
||||
,[ "gpiooutputspin", "GPIO pin # to switch on/off"]
|
||||
,[ "gpiooutputstriggerbit", "Bit # of the master/slave bits to trigger on (0-15)"]
|
||||
|
||||
];
|
||||
|
||||
|
|
|
@ -31,6 +31,48 @@ void handleDebug(){
|
|||
case '1': bDebugOTmsg = !bDebugOTmsg; DebugTf("\r\nDebug OTmsg: %s\r\n", CBOOLEAN(bDebugOTmsg)); break;
|
||||
case '2': bDebugRestAPI = !bDebugRestAPI; DebugTf("\r\nDebug RestAPI: %s\r\n", CBOOLEAN(bDebugRestAPI)); break;
|
||||
case '3': bDebugMQTT = !bDebugMQTT; DebugTf("\r\nDebug MQTT: %s\r\n", CBOOLEAN(bDebugMQTT)); break;
|
||||
case 'b':
|
||||
DebugTln("Blink led 1");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
blinkLED(LED1, 5, 500);
|
||||
break;
|
||||
case 'i':
|
||||
DebugTln("relay init");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
initOutputs();
|
||||
break;
|
||||
case 'u':
|
||||
DebugTln("gpio output on ");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
digitalWrite(settingGPIOOUTPUTSpin, ON);
|
||||
break;
|
||||
case 'j':
|
||||
DebugTf("read gpio output state (0== led ON): %d \r\n", digitalRead(settingGPIOOUTPUTSpin));
|
||||
break;
|
||||
case 'k':
|
||||
DebugTln("read settings");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
readSettings(true);
|
||||
break;
|
||||
case 'o':
|
||||
DebugTln("gpio output off");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
digitalWrite(settingGPIOOUTPUTSpin, OFF);
|
||||
break;
|
||||
case 'l':
|
||||
DebugTln("MyDEBUG =true");
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
settingMyDEBUG = true;
|
||||
break;
|
||||
case 'f':
|
||||
if(settingMyDEBUG)
|
||||
{
|
||||
DebugTln("MyDEBUG = true");
|
||||
}else{
|
||||
DebugTln("MyDEBUG = false");
|
||||
}
|
||||
// DebugTf("Enable MQTT: %s", CBOOLEAN(settingMQTTenable));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*********
|
||||
* aaa
|
||||
* aaa
|
||||
*********/
|
||||
|
||||
|
||||
// adds support to activiate a digital output
|
||||
//
|
||||
void setOutputState(bool set_HIGH);
|
||||
|
||||
|
||||
void initOutputs() {
|
||||
DebugTf("inside initOutputsO%d...\r\n", 1);
|
||||
|
||||
if (!settingGPIOOUTPUTSenabled) return;
|
||||
|
||||
DebugTf("init GPIO Output on GPIO%d...\r\n", settingGPIOOUTPUTSpin);
|
||||
|
||||
pinMode(settingGPIOOUTPUTSpin, OUTPUT);
|
||||
setOutputState(OFF);
|
||||
|
||||
// set the LED with the ledState of the variable:
|
||||
// digitalWrite(ledPin, ledState);
|
||||
}
|
||||
|
||||
// still need to hook into processOTGW
|
||||
void setOutputState(uint8_t status = ON)
|
||||
{
|
||||
(status == ON) ? setOutputState(true) : setOutputState(false);
|
||||
}
|
||||
void setOutputState(bool set_HIGH = true)
|
||||
{
|
||||
if(!settingGPIOOUTPUTSenabled) return;
|
||||
digitalWrite(settingGPIOOUTPUTSpin,ON);
|
||||
DebugTf("Output GPIO%d set to %d", settingGPIOOUTPUTSpin, digitalRead(settingGPIOOUTPUTSpin));
|
||||
}
|
||||
|
||||
void evalOutputs()
|
||||
{
|
||||
// master
|
||||
// bit: [clear/0, set/1]
|
||||
// 0: CH enable [ CH is disabled, CH is enabled]
|
||||
// 1: DHW enable [ DHW is disabled, DHW is enabled]
|
||||
// 2: Cooling enable [ Cooling is disabled, Cooling is enabled]]
|
||||
// 3: OTC active [OTC not active, OTC is active]
|
||||
// 4: CH2 enable [CH2 is disabled, CH2 is enabled]
|
||||
// 5: reserved
|
||||
// 6: reserved
|
||||
// 7: reserved
|
||||
|
||||
// slave
|
||||
// 0: fault indication [ no fault, fault ]
|
||||
// 1: CH mode [CH not active, CH active]
|
||||
// 2: DHW mode [ DHW not active, DHW active]
|
||||
// 3: Flame status [ flame off, flame on ]
|
||||
// 4: Cooling status [ cooling mode not active, cooling mode active ]
|
||||
// 5: CH2 mode [CH2 not active, CH2 active]
|
||||
// 6: diagnostic indication [no diagnostics, diagnostic event]
|
||||
// 7: reserved
|
||||
if (!settingMyDEBUG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
settingMyDEBUG = false;
|
||||
DebugTf("current gpio output state: %d \r\n", digitalRead(settingGPIOOUTPUTSpin));
|
||||
DebugFlush();
|
||||
|
||||
bool bitState = false;
|
||||
|
||||
bitState = (OTdataObject.Statusflags & (2^settingGPIOOUTPUTStriggerBit));
|
||||
DebugTf("bitState: bit: %d , state %d \r\n", settingGPIOOUTPUTStriggerBit, bitState);
|
||||
|
||||
setOutputState(bitState);
|
||||
|
||||
DebugTf("end void: current gpio output state: %d \r\n", digitalRead(settingGPIOOUTPUTSpin));
|
||||
}
|
|
@ -421,10 +421,13 @@ void sendDeviceSettings()
|
|||
sendJsonSettingObj("ntptimezone", CSTR(settingNTPtimezone), "s", 50);
|
||||
sendJsonSettingObj("ledblink", settingLEDblink, "b");
|
||||
sendJsonSettingObj("gpiosensorsenabled", settingGPIOSENSORSenabled, "b");
|
||||
sendJsonSettingObj("gpiosensorspin", settingGPIOSENSORSpin, "i", 1, 16);
|
||||
sendJsonSettingObj("gpiosensorspin", settingGPIOSENSORSpin, "i", 0, 16);
|
||||
sendJsonSettingObj("gpiosensorsinterval", settingGPIOSENSORSinterval, "i", 5, 65535);
|
||||
sendJsonSettingObj("otgwcommandenable", settingOTGWcommandenable, "b");
|
||||
sendJsonSettingObj("otgwcommands", CSTR(settingOTGWcommands), "s", 32);
|
||||
sendJsonSettingObj("gpiooutputsenabled", settingGPIOOUTPUTSenabled, "b");
|
||||
sendJsonSettingObj("gpiooutputspin", settingGPIOOUTPUTSpin, "i", 0, 16);
|
||||
sendJsonSettingObj("gpiooutputstriggerbit", settingGPIOOUTPUTStriggerBit, "i", 0,16);
|
||||
sendEndJsonObj("settings");
|
||||
|
||||
} // sendDeviceSettings()
|
||||
|
|
|
@ -45,6 +45,9 @@ void writeSettings(bool show)
|
|||
root["GPIOSENSORSpin"] = settingGPIOSENSORSpin;
|
||||
root["OTGWcommandenable"] = settingOTGWcommandenable;
|
||||
root["OTGWcommands"] = settingOTGWcommands;
|
||||
root["GPIOOUTPUTSenabled"] = settingGPIOOUTPUTSenabled;
|
||||
root["GPIOOUTPUTSpin"] = settingGPIOOUTPUTSpin;
|
||||
root["GPIOOUTPUTStriggerBit"] = settingGPIOOUTPUTStriggerBit;
|
||||
|
||||
serializeJsonPretty(root, file);
|
||||
Debugln(F("... done!"));
|
||||
|
@ -105,6 +108,9 @@ void readSettings(bool show)
|
|||
settingOTGWcommandenable = doc["OTGWcommandenable"] | settingOTGWcommandenable;
|
||||
settingOTGWcommands = doc["OTGWcommands"].as<String>();
|
||||
if (settingOTGWcommands=="null") settingOTGWcommands = "";
|
||||
settingGPIOOUTPUTSenabled = doc["GPIOOUTPUTSenabled"] | settingGPIOOUTPUTSenabled;
|
||||
settingGPIOOUTPUTSpin = doc["GPIOOUTPUTSpin"] | settingGPIOOUTPUTSpin;
|
||||
settingGPIOOUTPUTStriggerBit = doc["GPIOOUTPUTStriggerBit"] | settingGPIOOUTPUTStriggerBit;
|
||||
|
||||
// Close the file (Curiously, File's destructor doesn't close the file)
|
||||
file.close();
|
||||
|
@ -113,23 +119,26 @@ void readSettings(bool show)
|
|||
|
||||
if (show) {
|
||||
Debugln(F("\r\n==== read Settings ===================================================\r"));
|
||||
Debugf("Hostname : %s\r\n", CSTR(settingHostname));
|
||||
Debugf("MQTT enabled : %s\r\n", CBOOLEAN(settingMQTTenable));
|
||||
Debugf("MQTT broker : %s\r\n", CSTR(settingMQTTbroker));
|
||||
Debugf("MQTT port : %d\r\n", settingMQTTbrokerPort);
|
||||
Debugf("MQTT username : %s\r\n", CSTR(settingMQTTuser));
|
||||
Debugf("MQTT password : %s\r\n", CSTR(settingMQTTpasswd));
|
||||
Debugf("MQTT toptopic : %s\r\n", CSTR(settingMQTTtopTopic));
|
||||
Debugf("HA prefix : %s\r\n", CSTR(settingMQTThaprefix));
|
||||
Debugf("NTP enabled : %s\r\n", CBOOLEAN(settingNTPenable));
|
||||
Debugf("NPT timezone : %s\r\n", CSTR(settingNTPtimezone));
|
||||
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));
|
||||
Debugf("Hostname : %s\r\n", CSTR(settingHostname));
|
||||
Debugf("MQTT enabled : %s\r\n", CBOOLEAN(settingMQTTenable));
|
||||
Debugf("MQTT broker : %s\r\n", CSTR(settingMQTTbroker));
|
||||
Debugf("MQTT port : %d\r\n", settingMQTTbrokerPort);
|
||||
Debugf("MQTT username : %s\r\n", CSTR(settingMQTTuser));
|
||||
Debugf("MQTT password : %s\r\n", CSTR(settingMQTTpasswd));
|
||||
Debugf("MQTT toptopic : %s\r\n", CSTR(settingMQTTtopTopic));
|
||||
Debugf("HA prefix : %s\r\n", CSTR(settingMQTThaprefix));
|
||||
Debugf("NTP enabled : %s\r\n", CBOOLEAN(settingNTPenable));
|
||||
Debugf("NPT timezone : %s\r\n", CSTR(settingNTPtimezone));
|
||||
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));
|
||||
Debugf("OTGW boot cmd enabled : %s\r\n", CBOOLEAN(settingOTGWcommandenable));
|
||||
Debugf("OTGW boot cmd : %s\r\n", CSTR(settingOTGWcommands));
|
||||
}
|
||||
Debugf("GPIO Outputs : %s\r\n", CBOOLEAN(settingGPIOOUTPUTSenabled));
|
||||
Debugf("GPIO Out. Pin : %d\r\n", settingGPIOOUTPUTSpin);
|
||||
Debugf("GPIO Out. Trg. Bit : %d\r\n", settingGPIOOUTPUTStriggerBit);
|
||||
}
|
||||
|
||||
Debugln(F("-\r\n"));
|
||||
|
||||
|
@ -203,6 +212,24 @@ void updateSetting(const char *field, const char *newValue)
|
|||
}
|
||||
if (stricmp(field, "OTGWcommandenable")==0) settingOTGWcommandenable = EVALBOOLEAN(newValue);
|
||||
if (stricmp(field, "OTGWcommands")==0) settingOTGWcommands = String(newValue);
|
||||
if (stricmp(field, "GPIOOUTPUTSenabled") == 0)
|
||||
{
|
||||
settingGPIOOUTPUTSenabled = EVALBOOLEAN(newValue);
|
||||
Debugln();
|
||||
DebugTf("Need reboot before GPIO OUTPUTS will be enabled on pin GPIO%d!\r\n\n", settingGPIOOUTPUTSenabled);
|
||||
}
|
||||
if (stricmp(field, "GPIOOUTPUTSpin") == 0)
|
||||
{
|
||||
settingGPIOOUTPUTSpin = atoi(newValue);
|
||||
Debugln();
|
||||
DebugTf("Need reboot before GPIO OUTPUTS will use new pin GPIO%d!\r\n\n", settingGPIOOUTPUTSpin);
|
||||
}
|
||||
if (stricmp(field, "GPIOOUTPUTStriggerBit") == 0)
|
||||
{
|
||||
settingGPIOOUTPUTStriggerBit = atoi(newValue);
|
||||
Debugln();
|
||||
DebugTf("Need reboot before GPIO OUTPUTS will use new trigger bit %d!\r\n\n", settingGPIOOUTPUTStriggerBit);
|
||||
}
|
||||
|
||||
//finally update write settings
|
||||
writeSettings(false);
|
||||
|
|
Loading…
Reference in New Issue