mirror of
https://github.com/anklimov/lighthub
synced 2025-12-11 14:19:50 +03:00
49days issue fixed, thermostates, RGB/HSV mixes
This commit is contained in:
@@ -20,7 +20,9 @@ int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
|
||||
{
|
||||
debugSerial<<F("clrCtr: ");
|
||||
cmd.debugOut();
|
||||
int suffixCode = cmd.getSuffix();
|
||||
int suffixCode;
|
||||
if (cmd.isCommand()) suffixCode = S_CMD;
|
||||
else suffixCode = cmd.getSuffix();
|
||||
|
||||
switch(suffixCode)
|
||||
{
|
||||
@@ -41,6 +43,7 @@ case S_CMD:
|
||||
return 1;
|
||||
|
||||
case CMD_OFF:
|
||||
cmd.param.asInt32=0;
|
||||
PixelCtrl(cmd, subItem, true);
|
||||
// item->SendStatus(SEND_COMMAND);
|
||||
return 1;
|
||||
|
||||
@@ -158,7 +158,7 @@ for (short tch=0; tch<=3 ; tch++)
|
||||
if (updated)
|
||||
{
|
||||
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||
D_checkT=millis()+D_CHECKT;
|
||||
D_checkT=millisNZ();
|
||||
}
|
||||
}
|
||||
//Serial.print(D_State,BIN);Serial.println();
|
||||
@@ -185,7 +185,8 @@ short t,tch;
|
||||
|
||||
}
|
||||
|
||||
if ((millis()<D_checkT) || (D_checkT==0)) return;
|
||||
//if ((millis()<D_checkT) || (D_checkT==0)) return;
|
||||
if ( (!D_checkT) || (!isTimeOver(D_checkT,millis(),D_CHECKT))) return;
|
||||
D_checkT=0;
|
||||
|
||||
// Here code for network update
|
||||
@@ -274,7 +275,8 @@ void DMXOUT_propagate()
|
||||
{
|
||||
#ifdef DMX_SMOOTH
|
||||
uint32_t now = millis();
|
||||
if (now<checkTimestamp) return;
|
||||
//if (now<checkTimestamp) return;
|
||||
if (!isTimeOver(checkTimestamp,now,DMX_SMOOTH_DELAY)) return;
|
||||
|
||||
for(int i=1;i<=DMXOUT_Channels;i++)
|
||||
{
|
||||
@@ -292,7 +294,7 @@ void DMXOUT_propagate()
|
||||
{DmxWrite2(i,currLevel-step);debugSerial<<">";}
|
||||
}
|
||||
}
|
||||
checkTimestamp=now+DMX_SMOOTH_DELAY;
|
||||
checkTimestamp=now;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
54
lighthub/esp.cpp
Normal file
54
lighthub/esp.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "options.h"
|
||||
#ifdef __ESP__
|
||||
#include "esp.h"
|
||||
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
WiFiClient ethClient;
|
||||
|
||||
char mqtt_password[16];
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.56";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
//char static_sn[16] = "255.255.255.0";
|
||||
|
||||
//flag for saving data
|
||||
bool shouldSaveConfig = false;
|
||||
|
||||
//callback notifying us of the need to save config
|
||||
void saveConfigCallback () {
|
||||
Serial.println(F("Should save config"));
|
||||
shouldSaveConfig = true;
|
||||
}
|
||||
|
||||
|
||||
void espSetup () {
|
||||
Serial.println(F("Setting up Wifi"));
|
||||
shouldSaveConfig = true;
|
||||
//WiFiManager
|
||||
|
||||
WiFiManagerParameter custom_mqtt_password("", "mqtt password", mqtt_password, 16);
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||
|
||||
wifiManager.addParameter(&custom_mqtt_password);
|
||||
wifiManager.setMinimumSignalQuality();
|
||||
|
||||
if (!wifiManager.autoConnect()) {
|
||||
Serial.println(F("failed to connect and hit timeout"));
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println(F("connected...yeey :)"));
|
||||
|
||||
//read updated parameters
|
||||
strcpy(mqtt_password, custom_mqtt_password.getValue());
|
||||
|
||||
}
|
||||
#endif
|
||||
24
lighthub/esp.h
Normal file
24
lighthub/esp.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
|
||||
extern ESP8266WiFiMulti wifiMulti;
|
||||
extern WiFiClient ethClient;
|
||||
//WiFiManager wifiManager;
|
||||
|
||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||
//length should be max size + 1
|
||||
extern char mqtt_password[16];
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.56";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
//char static_sn[16] = "255.255.255.0";
|
||||
|
||||
//flag for saving data
|
||||
extern bool shouldSaveConfig;
|
||||
|
||||
void espSetup ();
|
||||
@@ -289,7 +289,8 @@ switch (cause) {
|
||||
|
||||
#ifndef COUNTER_DISABLE
|
||||
void Input::counterPoll() {
|
||||
if(nextPollTime()>millis())
|
||||
// if(nextPollTime()>millis())
|
||||
if (!isTimeOver(nextPollTime(),millis(),DHT_POLL_DELAY_DEFAULT))
|
||||
return;
|
||||
if (store->logicState == 0) {
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
@@ -326,7 +327,7 @@ void Input::counterPoll() {
|
||||
sprintf(valstr, "%ld", counterValue);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
setNextPollTime(millis());// + DHT_POLL_DELAY_DEFAULT);
|
||||
// debugSerial<<F(" NextPollMillis=")<<nextPollTime();
|
||||
}
|
||||
else
|
||||
@@ -374,7 +375,8 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
||||
|
||||
|
||||
void Input::uptimePoll() {
|
||||
if (nextPollTime() > millis())
|
||||
//if (nextPollTime() > millis())
|
||||
if (!isTimeOver(nextPollTime(),millis(),UPTIME_POLL_DELAY_DEFAULT))
|
||||
return;
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit && emit->type == aJson_String) {
|
||||
@@ -391,7 +393,7 @@ void Input::uptimePoll() {
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
}
|
||||
setNextPollTime(millis() + UPTIME_POLL_DELAY_DEFAULT);
|
||||
setNextPollTime(millis());// + UPTIME_POLL_DELAY_DEFAULT);
|
||||
}
|
||||
|
||||
void Input::onCounterChanged(int i) {
|
||||
@@ -456,7 +458,8 @@ void Input::setNextPollTime(unsigned long pollTime) {
|
||||
#ifndef DHT_DISABLE
|
||||
|
||||
void Input::dht22Poll() {
|
||||
if (nextPollTime() > millis())
|
||||
//if (nextPollTime() > millis())
|
||||
if (!isTimeOver(nextPollTime(),millis(),DHT_POLL_DELAY_DEFAULT))
|
||||
return;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
DHTesp dhtSensor;
|
||||
@@ -495,10 +498,12 @@ void Input::dht22Poll() {
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
//setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
// debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
||||
} else
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||
}
|
||||
//else
|
||||
// setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||
setNextPollTime(millis());
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
|
||||
@@ -47,6 +47,7 @@ e-mail anklimov@gmail.com
|
||||
#include "modules/out_modbus.h"
|
||||
#include "modules/out_dmx.h"
|
||||
#include "modules/out_pwm.h"
|
||||
#include "modules/out_pid.h"
|
||||
|
||||
short modbusBusy = 0;
|
||||
extern aJsonObject *pollingItem;
|
||||
@@ -97,12 +98,7 @@ int txt2subItem(char *payload) {
|
||||
else if (strcmp_P(payload, HUE_P) == 0) cmd = S_HUE;
|
||||
else if (strcmp_P(payload, SAT_P) == 0) cmd = S_SAT;
|
||||
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
||||
/* UnUsed now
|
||||
else if (strcmp_P(payload, SETPOINT_P) == 0) cmd = S_SETPOINT;
|
||||
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
||||
else if (strcmp_P(payload, POWER_P) == 0) cmd = S_POWER;
|
||||
else if (strcmp_P(payload, VOL_P) == 0) cmd = S_VOL;
|
||||
*/
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -166,6 +162,13 @@ void Item::Parse() {
|
||||
// debugSerial<<F("AC driver created")<<endl;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef PID_DISABLE
|
||||
case CH_PID:
|
||||
driver = new out_pid (this);
|
||||
// debugSerial<<F("AC driver created")<<endl;
|
||||
break;
|
||||
#endif
|
||||
default: ;
|
||||
}
|
||||
// debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl;
|
||||
@@ -561,7 +564,7 @@ st.setSuffix(suffixCode);
|
||||
case 4: st.RGBW(Par[0],Par[1],Par[2],Par[3]);
|
||||
default:;
|
||||
}
|
||||
//return Ctrl(setCommand, i, Par, suffixCode, subItem);
|
||||
|
||||
return Ctrl(st,subItem);
|
||||
}
|
||||
default: //some known command
|
||||
@@ -586,10 +589,18 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
if (!suffixCode && defaultSuffixCode)
|
||||
suffixCode = defaultSuffixCode;
|
||||
|
||||
|
||||
debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=");
|
||||
int fr = freeRam();
|
||||
|
||||
|
||||
debugSerial<<F("RAM=")<<fr<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=");
|
||||
if (fr < 180) {
|
||||
errorSerial<<F("OutOfMemory!\n")<<endl;
|
||||
return -1;
|
||||
}
|
||||
cmd.debugOut();
|
||||
if (!itemArr) return -1;
|
||||
|
||||
|
||||
|
||||
bool chActive = (isActive()>0);
|
||||
bool toExecute = (chActive>0); // execute if channel is active now
|
||||
@@ -643,7 +654,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
case CMD_HALT: //previous command was HALT ?
|
||||
debugSerial << F("Restored from:") << t << endl;
|
||||
toExecute=true;
|
||||
if (itemType == CH_THERMO) st.Cmd(CMD_AUTO);
|
||||
if (itemType == CH_THERMO) st.Cmd(CMD_AUTO); ////
|
||||
else st.Cmd(CMD_ON); //turning on
|
||||
break;
|
||||
default:
|
||||
@@ -665,15 +676,15 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
|
||||
}
|
||||
break;
|
||||
case CMD_DN:
|
||||
case CMD_UP:
|
||||
{
|
||||
//if (itemType == CH_GROUP) break; ////bug here
|
||||
st.Cmd(CMD_VOID); // Converting to SET value command
|
||||
short step=0;
|
||||
if (cmd.isValue()) step=cmd.getInt();
|
||||
if (!step) step=DEFAULT_INC_STEP;
|
||||
if (cmd.getCmd() == CMD_DN) step=-step;
|
||||
case CMD_DN:
|
||||
case CMD_UP:
|
||||
{
|
||||
//if (itemType == CH_GROUP) break; ////bug here
|
||||
st.Cmd(CMD_VOID); // Converting to SET value command
|
||||
short step=0;
|
||||
if (cmd.isValue()) step=cmd.getInt();
|
||||
if (!step) step=DEFAULT_INC_STEP;
|
||||
if (cmd.getCmd() == CMD_DN) step=-step;
|
||||
|
||||
switch (suffixCode)
|
||||
{
|
||||
@@ -707,7 +718,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
case CMD_VOID: // No commands, just set value
|
||||
////if (itemType == CH_GROUP ) break; ////
|
||||
if (!cmd.isValue()) break;
|
||||
//// if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
||||
//// if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
||||
switch (suffixCode)
|
||||
{
|
||||
case S_NOTFOUND: //For empty (universal) suffix - turn ON/OFF automatically
|
||||
@@ -720,7 +731,10 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
// continue processing as SET
|
||||
case S_SET:
|
||||
//case S_ESET:
|
||||
if ((st.getArgType() == ST_RGB || st.getArgType() == ST_RGBW) && (cmd.getArgType() == ST_HSV ) || (cmd.getArgType() == ST_HSV255)) st.setArgType(cmd.getArgType());
|
||||
if ((st.getArgType() == ST_RGB || st.getArgType() == ST_RGBW) &&
|
||||
(cmd.getArgType() == ST_HSV ) || (cmd.getArgType() == ST_HSV255))
|
||||
st.setArgType(cmd.getArgType());
|
||||
|
||||
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV);//Extend storage for group channel
|
||||
st.assignFrom(cmd);
|
||||
st.saveItem(this);
|
||||
@@ -754,6 +768,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
||||
|
||||
default:
|
||||
st.Cmd(cmd.getCmd());
|
||||
st.setSuffix(cmd.getSuffix());
|
||||
toExecute=true;
|
||||
} //Switch commands
|
||||
|
||||
@@ -893,9 +908,20 @@ switch (itemType) {
|
||||
} //switch
|
||||
if (st.isCommand())
|
||||
{
|
||||
if (cmd.getCmd() == CMD_HALT)
|
||||
{
|
||||
if (chActive>0) //if channel was active before CMD_HALT
|
||||
{
|
||||
setCmd(CMD_HALT);
|
||||
SendStatus(SEND_COMMAND);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setCmd(st.getCmd());
|
||||
SendStatus(SEND_COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -1495,17 +1521,17 @@ switch (cause)
|
||||
case CH_MODBUS:
|
||||
checkModbusDimmer();
|
||||
sendDelayedStatus();
|
||||
return INTERVAL_CHECK_MODBUS;
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
break;
|
||||
case CH_VC:
|
||||
checkFM();
|
||||
sendDelayedStatus();
|
||||
return INTERVAL_CHECK_MODBUS;
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
break;
|
||||
case CH_VCTEMP:
|
||||
checkHeatRetry();
|
||||
sendDelayedStatus();
|
||||
return INTERVAL_CHECK_MODBUS;
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
break;
|
||||
#endif
|
||||
/* case CH_RGB: //All channels with slider generate too many updates
|
||||
@@ -1525,7 +1551,7 @@ switch (cause)
|
||||
return driver->Poll(cause);
|
||||
}
|
||||
|
||||
return INTERVAL_POLLING;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Item::sendDelayedStatus()
|
||||
@@ -1541,12 +1567,16 @@ void Item::sendDelayedStatus()
|
||||
|
||||
int Item::SendStatus(int sendFlags) {
|
||||
|
||||
if ((sendFlags & SEND_DEFFERED) || (!isNotRetainingStatus() )) {
|
||||
if ((sendFlags & SEND_DEFFERED) || freeRam()<150 || (!isNotRetainingStatus() )) {
|
||||
setFlag(sendFlags & (SEND_COMMAND | SEND_PARAMETERS));
|
||||
debugSerial<<F("Status deffered\n");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
else return SendStatusImmediate(sendFlags);
|
||||
}
|
||||
|
||||
int Item::SendStatusImmediate(int sendFlags) {
|
||||
{
|
||||
itemCmd st(ST_VOID,CMD_VOID);
|
||||
st.loadItem(this, true);
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ e-mail anklimov@gmail.com
|
||||
#define CH_AC 10 //AC Haier
|
||||
#define CH_SPILED 11
|
||||
#define CH_MOTOR 12
|
||||
#define CH_PID 13
|
||||
#define CH_MBUS 14
|
||||
|
||||
//#define CHANNEL_TYPES 13
|
||||
|
||||
//static uint32_t pollInterval[CHANNEL_TYPES] = {0,0,0,0,MODB};
|
||||
@@ -125,6 +127,7 @@ class Item
|
||||
void setSubtype(uint8_t par);
|
||||
int Poll(int cause);
|
||||
int SendStatus(int sendFlags);
|
||||
int SendStatusImmediate(int sendFlags);
|
||||
int isActive();
|
||||
int getChanType();
|
||||
inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));};
|
||||
|
||||
@@ -63,6 +63,19 @@ itemCmd::itemCmd(float val)
|
||||
param.asfloat=val;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Constructor with loading value from Item
|
||||
\param Item
|
||||
*/
|
||||
itemCmd::itemCmd(Item *item)
|
||||
{
|
||||
cmd.aslong=0;
|
||||
param.aslong=0;
|
||||
|
||||
loadItem(item);
|
||||
}
|
||||
|
||||
|
||||
itemCmd itemCmd::setChanType(short chanType)
|
||||
{
|
||||
switch (chanType)
|
||||
@@ -285,6 +298,8 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
||||
{
|
||||
bool RGBW_flag = false;
|
||||
bool HSV255_flag = false;
|
||||
bool toFarenheit = false;
|
||||
|
||||
int t=from.getColorTemp();
|
||||
|
||||
if (t>=0)
|
||||
@@ -372,10 +387,41 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
||||
|
||||
case ST_INT32:
|
||||
case ST_UINT32:
|
||||
param.asInt32=from.param.asInt32;
|
||||
break;
|
||||
case ST_FLOAT_FARENHEIT:
|
||||
toFarenheit = true;
|
||||
case ST_FLOAT:
|
||||
case ST_FLOAT_CELSIUS:
|
||||
case ST_FLOAT_FARENHEIT:
|
||||
param.asInt32=from.param.asInt32;
|
||||
switch (from.cmd.itemArgType)
|
||||
{
|
||||
case ST_TENS:
|
||||
param.asfloat=from.param.asInt32/10.;
|
||||
break;
|
||||
|
||||
case ST_PERCENTS:
|
||||
case ST_PERCENTS255:
|
||||
param.asfloat=from.param.v;
|
||||
break;
|
||||
|
||||
case ST_INT32:
|
||||
param.asfloat=from.param.asInt32;
|
||||
break;
|
||||
case ST_UINT32:
|
||||
param.asfloat=from.param.asUint32;
|
||||
break;
|
||||
|
||||
case ST_FLOAT_FARENHEIT:
|
||||
// F to C code should be here
|
||||
// if (!toFarenheit) convert (from.param.asfloat); cmd.itemArgType=ST_FARENHEIT
|
||||
case ST_FLOAT:
|
||||
case ST_FLOAT_CELSIUS:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param.asfloat=from.param.asfloat;
|
||||
default:
|
||||
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ST_RGBW:
|
||||
@@ -423,22 +469,25 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
||||
from.param.h=100;
|
||||
from.param.s=0;
|
||||
#endif
|
||||
from.cmd.itemArgType=ST_HSV255;
|
||||
//from.param.v = map(from.param.v,0,100,0,255);
|
||||
from.cmd.itemArgType=ST_HSV;//255;
|
||||
break;
|
||||
case ST_HS:
|
||||
|
||||
#ifndef ADAFRUIT_LED
|
||||
from.param.v = hsv.v;
|
||||
#else
|
||||
from.param.v=255;
|
||||
from.param.v=100;
|
||||
#endif
|
||||
from.cmd.itemArgType=ST_HSV255;
|
||||
from.cmd.itemArgType=ST_HSV; //255
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Converting current obj to HSV
|
||||
|
||||
debugSerial<<F("Updated:"); from.debugOut();
|
||||
debugSerial<<F("Conv RGB2HSV:"); from.debugOut();
|
||||
|
||||
// Do not convert to RGBx ?
|
||||
param=from.param;
|
||||
cmd=from.cmd;
|
||||
return *this;
|
||||
@@ -574,6 +623,37 @@ long int itemCmd::getInt()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float itemCmd::getFloat()
|
||||
{
|
||||
switch (cmd.itemArgType) {
|
||||
|
||||
case ST_INT32:
|
||||
case ST_UINT32:
|
||||
case ST_RGB:
|
||||
case ST_RGBW:
|
||||
case ST_TENS:
|
||||
return param.aslong;
|
||||
|
||||
case ST_PERCENTS:
|
||||
case ST_PERCENTS255:
|
||||
case ST_HSV:
|
||||
case ST_HSV255:
|
||||
return param.v;
|
||||
|
||||
case ST_FLOAT:
|
||||
case ST_FLOAT_CELSIUS:
|
||||
case ST_FLOAT_FARENHEIT:
|
||||
return param.asfloat;
|
||||
|
||||
|
||||
default:
|
||||
return 0.;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
long int itemCmd::getSingleInt()
|
||||
{
|
||||
if (cmd.cmdCode) return cmd.cmdCode;
|
||||
@@ -790,8 +870,8 @@ bool itemCmd::loadItem(Item * item, bool includeCommand)
|
||||
param.asInt32=item->getVal();
|
||||
cmd.itemArgType= subtype;
|
||||
if (includeCommand) cmd.cmdCode=item->getCmd();
|
||||
debugSerial<<F("Loaded :");
|
||||
debugOut();
|
||||
//debugSerial<<F("Loaded :");
|
||||
//debugOut();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -849,6 +929,7 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
|
||||
len=strlen(Buffer);
|
||||
argPtr+=len;
|
||||
bufLen-=len;
|
||||
bufLen--;
|
||||
}
|
||||
if (sendFlags & SEND_PARAMETERS)
|
||||
switch (cmd.itemArgType)
|
||||
@@ -884,7 +965,19 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
|
||||
case ST_FLOAT_CELSIUS:
|
||||
case ST_FLOAT_FARENHEIT:
|
||||
case ST_FLOAT:
|
||||
snprintf(argPtr, bufLen, "%.1f", param.asfloat);
|
||||
{
|
||||
//char *tmpSign = (param.asfloat < 0) ? "-" : "";
|
||||
float tmpVal = (param.asfloat < 0) ? -param.asfloat : param.asfloat;
|
||||
int tmpInt1 = tmpVal; // Get the integer
|
||||
float tmpFrac = tmpVal - tmpInt1; // Get fraction
|
||||
int tmpInt2 = trunc(tmpFrac * 10000); // Turn into integer
|
||||
// Print as parts, note that you need 0-padding for fractional bit.
|
||||
|
||||
if (param.asfloat < 0)
|
||||
snprintf (argPtr, bufLen, "-%d.%04d", tmpInt1, tmpInt2);
|
||||
else snprintf (argPtr, bufLen, "%d.%04d", tmpInt1, tmpInt2);
|
||||
}
|
||||
// snprintf(argPtr, bufLen, "%.1f", param.asfloat);
|
||||
break;
|
||||
case ST_RGB:
|
||||
snprintf(argPtr, bufLen, "%d,%d,%d", param.r, param.g, param.b);
|
||||
|
||||
@@ -180,6 +180,8 @@ public:
|
||||
|
||||
itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID);
|
||||
itemCmd(float val);
|
||||
itemCmd(Item *item);
|
||||
|
||||
itemCmd assignFrom(itemCmd from);
|
||||
|
||||
bool loadItem(Item * item, bool includeCommand=false );
|
||||
@@ -212,6 +214,7 @@ public:
|
||||
bool incrementS(int16_t);
|
||||
|
||||
long int getInt();
|
||||
float getFloat();
|
||||
long int getSingleInt();
|
||||
short getPercents(bool inverse=false);
|
||||
short getPercents255(bool inverse=false);
|
||||
|
||||
@@ -67,7 +67,7 @@ PWM Out
|
||||
|
||||
#include "main.h"
|
||||
#include "statusled.h"
|
||||
|
||||
extern long timer0_overflow_count;
|
||||
#ifdef WIFI_ENABLE
|
||||
WiFiClient ethClient;
|
||||
|
||||
@@ -109,7 +109,7 @@ NRFFlashStorage EEPROM;
|
||||
WiFiUDP udpSyslogClient;
|
||||
#endif
|
||||
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD);
|
||||
unsigned long nextSyslogPingTime;
|
||||
unsigned long timerSyslogPingTime;
|
||||
static char syslogDeviceHostname[16];
|
||||
|
||||
Streamlog debugSerial(&debugSerialPort,LOG_DEBUG,&udpSyslog);
|
||||
@@ -155,11 +155,11 @@ aJsonObject *dmxArr = NULL;
|
||||
bool syslogInitialized = false;
|
||||
#endif
|
||||
|
||||
uint32_t nextPollingCheck = 0;
|
||||
uint32_t nextInputCheck = 0;
|
||||
uint32_t nextLanCheckTime = 0;
|
||||
uint32_t nextThermostatCheck = 0;
|
||||
uint32_t nextSensorCheck =0;
|
||||
uint32_t timerPollingCheck = 0;
|
||||
uint32_t timerInputCheck = 0;
|
||||
uint32_t timerLanCheckTime = 0;
|
||||
uint32_t timerThermostatCheck = 0;
|
||||
uint32_t timerSensorCheck =0;
|
||||
uint32_t WiFiAwaitingTime =0;
|
||||
|
||||
aJsonObject *pollingItem = NULL;
|
||||
@@ -257,11 +257,13 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
if (!payload) return;
|
||||
|
||||
payload[length] = 0;
|
||||
|
||||
int fr = freeRam();
|
||||
if (fr < 250) {
|
||||
errorSerial<<F("OutOfMemory!")<<endl;
|
||||
return;
|
||||
}
|
||||
|
||||
LED.flash(ledBLUE);
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
debugSerial<<((char) payload[i]);
|
||||
@@ -447,7 +449,8 @@ lan_status lanLoop() {
|
||||
lanStatus = HAVE_IP_ADDRESS;
|
||||
}
|
||||
else
|
||||
if (millis()>WiFiAwaitingTime)
|
||||
// if (millis()>WiFiAwaitingTime)
|
||||
if (isTimeOver(WiFiAwaitingTime,millis(),WIFI_TIMEOUT))
|
||||
{
|
||||
errorSerial<<F("\nProblem with WiFi!");
|
||||
return lanStatus = DO_REINIT;
|
||||
@@ -487,7 +490,9 @@ lan_status lanLoop() {
|
||||
break;
|
||||
|
||||
case RETAINING_COLLECTING:
|
||||
if (millis() > nextLanCheckTime) {
|
||||
//if (millis() > timerLanCheckTime)
|
||||
if (isTimeOver(timerLanCheckTime,millis(),TIMEOUT_RETAIN))
|
||||
{
|
||||
char buf[MQTT_TOPIC_LENGTH+1];
|
||||
|
||||
//Unsubscribe from status topics..
|
||||
@@ -507,14 +512,15 @@ lan_status lanLoop() {
|
||||
|
||||
case DO_REINIT: // Pause and re-init LAN
|
||||
//if (mqttClient.connected()) mqttClient.disconnect(); // Hmm hungs then cable disconnected
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
timerLanCheckTime = millis();// + 5000;
|
||||
lanStatus = REINIT;
|
||||
LED.set(ledRED|((configLoaded)?ledBLINK:0));
|
||||
break;
|
||||
|
||||
case REINIT: // Pause and re-init LAN
|
||||
|
||||
if (millis() > nextLanCheckTime)
|
||||
//if (millis() > timerLanCheckTime)
|
||||
if (isTimeOver(timerLanCheckTime,millis(),TIMEOUT_REINIT))
|
||||
{
|
||||
lanStatus = INITIAL_STATE;
|
||||
}
|
||||
@@ -522,12 +528,13 @@ lan_status lanLoop() {
|
||||
|
||||
case DO_RECONNECT: // Pause and re-connect MQTT
|
||||
if (mqttClient.connected()) mqttClient.disconnect();
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
timerLanCheckTime = millis();// + 5000;
|
||||
lanStatus = RECONNECT;
|
||||
break;
|
||||
|
||||
case RECONNECT:
|
||||
if (millis() > nextLanCheckTime)
|
||||
//if (millis() > timerLanCheckTime)
|
||||
if (isTimeOver(timerLanCheckTime,millis(),TIMEOUT_RECONNECT))
|
||||
|
||||
lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2;
|
||||
break;
|
||||
@@ -535,7 +542,7 @@ lan_status lanLoop() {
|
||||
case READ_RE_CONFIG: // Restore config from FLASH, re-init LAN
|
||||
if (loadConfigFromEEPROM()) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2;
|
||||
else {
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
//timerLanCheckTime = millis();// + 5000;
|
||||
lanStatus = DO_REINIT;//-10;
|
||||
}
|
||||
break;
|
||||
@@ -575,7 +582,7 @@ lan_status lanLoop() {
|
||||
case DHCP_CHECK_REBIND_FAIL:
|
||||
errorSerial<<F("Error: rebind fail");
|
||||
if (mqttClient.connected()) mqttClient.disconnect();
|
||||
nextLanCheckTime = millis() + 1000;
|
||||
//timerLanCheckTime = millis();// + 1000;
|
||||
lanStatus = DO_REINIT;
|
||||
break;
|
||||
|
||||
@@ -777,16 +784,15 @@ debugSerial<<F("N:")<<n<<endl;
|
||||
Serial.println(buf);
|
||||
mqttClient.subscribe(buf);
|
||||
|
||||
//restoreState();
|
||||
onMQTTConnect();
|
||||
// if (_once) {DMXput(); _once=0;}
|
||||
lanStatus = RETAINING_COLLECTING;//4;
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
timerLanCheckTime = millis();// + 5000;
|
||||
infoSerial<<F("Awaiting for retained topics");
|
||||
} else
|
||||
{
|
||||
errorSerial<<F("failed, rc=")<<mqttClient.state()<<F(" try again in 5 seconds")<<endl;
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
timerLanCheckTime = millis();// + 5000;
|
||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||
mqttErrorRate++;
|
||||
if(mqttErrorRate>50){
|
||||
@@ -831,7 +837,7 @@ void onInitialStateInitLAN() {
|
||||
}
|
||||
#endif
|
||||
lanStatus = AWAITING_ADDRESS;
|
||||
WiFiAwaitingTime = millis() + 60000L;
|
||||
WiFiAwaitingTime = millis();// + 60000L;
|
||||
return;
|
||||
/*
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
@@ -844,7 +850,7 @@ if (WiFi.status() == WL_CONNECTED) {
|
||||
{
|
||||
errorSerial<<F("\nProblem with WiFi!");
|
||||
lanStatus = DO_REINIT;
|
||||
//nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||
//timerLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||
}
|
||||
*/
|
||||
#else // Ethernet connection
|
||||
@@ -854,16 +860,16 @@ if (WiFi.status() == WL_CONNECTED) {
|
||||
int res = 1;
|
||||
infoSerial<<F("Starting lan")<<endl;
|
||||
if (ipLoadFromFlash(OFFSET_IP, ip)) {
|
||||
infoSerial<<"Loaded from flash IP:";
|
||||
infoSerial<<F("Loaded from flash IP:");
|
||||
printIPAddress(ip);
|
||||
if (ipLoadFromFlash(OFFSET_DNS, dns)) {
|
||||
infoSerial<<" DNS:";
|
||||
infoSerial<<F(" DNS:");
|
||||
printIPAddress(dns);
|
||||
if (ipLoadFromFlash(OFFSET_GW, gw)) {
|
||||
infoSerial<<" GW:";
|
||||
infoSerial<<F(" GW:");
|
||||
printIPAddress(gw);
|
||||
if (ipLoadFromFlash(OFFSET_MASK, mask)) {
|
||||
infoSerial<<" MASK:";
|
||||
infoSerial<<F(" MASK:");
|
||||
printIPAddress(mask);
|
||||
Ethernet.begin(mac, ip, dns, gw, mask);
|
||||
} else Ethernet.begin(mac, ip, dns, gw);
|
||||
@@ -873,7 +879,7 @@ if (WiFi.status() == WL_CONNECTED) {
|
||||
lanStatus = HAVE_IP_ADDRESS;
|
||||
}
|
||||
else {
|
||||
infoSerial<<"\nuses DHCP\n";
|
||||
infoSerial<<F("\nuses DHCP\n");
|
||||
wdt_dis();
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
@@ -888,7 +894,7 @@ if (WiFi.status() == WL_CONNECTED) {
|
||||
if (res == 0) {
|
||||
errorSerial<<F("Failed to configure Ethernet using DHCP. You can set ip manually!")<<F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n");
|
||||
lanStatus = DO_REINIT;//-10;
|
||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||
//timerLanCheckTime = millis();// + DHCP_RETRY_INTERVAL;
|
||||
#ifdef RESET_PIN
|
||||
resetHard();
|
||||
#endif
|
||||
@@ -1421,7 +1427,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
|
||||
if (!root) {
|
||||
errorSerial<<F("Config parsing failed\n");
|
||||
nextLanCheckTime = millis() + 15000;
|
||||
// timerLanCheckTime = millis();// + 15000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
} else {
|
||||
infoSerial<<F("Applying.\n");
|
||||
@@ -1433,14 +1439,14 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
} else {
|
||||
errorSerial<<F("ERROR: Server returned ");
|
||||
errorSerial<<responseStatusCode<<endl;
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
// timerLanCheckTime = millis();// + 5000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
}
|
||||
|
||||
} else {
|
||||
debugSerial<<F("failed to connect\n");
|
||||
// debugSerial<<F(" try again in 5 seconds\n");
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
// timerLanCheckTime = millis();// + 5000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
}
|
||||
#endif
|
||||
@@ -1969,7 +1975,9 @@ void inputLoop(void) {
|
||||
if (!inputs) return;
|
||||
|
||||
configLocked++;
|
||||
if (millis() > nextInputCheck) {
|
||||
//if (millis() > timerInputCheck)
|
||||
if (isTimeOver(timerInputCheck,millis(),INTERVAL_CHECK_INPUT))
|
||||
{
|
||||
aJsonObject *input = inputs->child;
|
||||
|
||||
while (input) {
|
||||
@@ -1999,11 +2007,13 @@ configLocked++;
|
||||
yield();
|
||||
input = input->next;
|
||||
}
|
||||
nextInputCheck = millis() + INTERVAL_CHECK_INPUT;
|
||||
timerInputCheck = millis();// + INTERVAL_CHECK_INPUT;
|
||||
inCache.invalidateInputCache();
|
||||
}
|
||||
|
||||
if (millis() > nextSensorCheck) {
|
||||
//if (millis() > timerSensorCheck)
|
||||
if (isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
|
||||
{
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
@@ -2013,7 +2023,7 @@ configLocked++;
|
||||
yield();
|
||||
input = input->next;
|
||||
}
|
||||
nextSensorCheck = millis() + INTERVAL_CHECK_SENSOR;
|
||||
timerSensorCheck = millis();// + INTERVAL_CHECK_SENSOR;
|
||||
}
|
||||
configLocked--;
|
||||
}
|
||||
@@ -2053,14 +2063,16 @@ configLocked--;
|
||||
// SLOW POLLING
|
||||
boolean done = false;
|
||||
if (lanStatus == RETAINING_COLLECTING) return;
|
||||
if (millis() > nextPollingCheck) {
|
||||
//if (millis() > timerPollingCheck)
|
||||
if (isTimeOver(timerPollingCheck,millis(),INTERVAL_SLOW_POLLING))
|
||||
{
|
||||
while (pollingItem && !done) {
|
||||
if (pollingItem->type == aJson_Array) {
|
||||
Item it(pollingItem);
|
||||
uint32_t ret = it.Poll(POLLING_SLOW);
|
||||
if (ret)
|
||||
{
|
||||
nextPollingCheck = millis() + ret; //INTERVAL_CHECK_MODBUS;
|
||||
timerPollingCheck = millis();// + ret; //INTERVAL_CHECK_MODBUS;
|
||||
done = true;
|
||||
}
|
||||
}//if
|
||||
@@ -2095,7 +2107,8 @@ bool thermoDisabledOrDisconnected(aJsonObject *thermoExtensionArray, int thermoS
|
||||
|
||||
//TODO: refactoring
|
||||
void thermoLoop(void) {
|
||||
if (millis() < nextThermostatCheck)
|
||||
// if (millis() < timerThermostatCheck)
|
||||
if (!isTimeOver(timerThermostatCheck,millis(),THERMOSTAT_CHECK_PERIOD))
|
||||
return;
|
||||
if (!items) return;
|
||||
bool thermostatCheckPrinted = false;
|
||||
@@ -2104,9 +2117,21 @@ void thermoLoop(void) {
|
||||
if (isThermostatWithMinArraySize(thermoItem, 5)) {
|
||||
aJsonObject *thermoExtensionArray = aJson.getArrayItem(thermoItem, I_EXT);
|
||||
if (thermoExtensionArray && (aJson.getArraySize(thermoExtensionArray) > 1)) {
|
||||
int thermoPin = aJson.getArrayItem(thermoItem, I_ARG)->valueint;
|
||||
float thermoSetting = aJson.getArrayItem(thermoItem, I_VAL)->valueint; ///
|
||||
|
||||
Item thermostat(thermoItem);
|
||||
if (!thermostat.isValid()) continue;
|
||||
|
||||
itemCmd thermostatCmd(&thermostat);
|
||||
|
||||
|
||||
//int thermoPin = aJson.getArrayItem(thermoItem, I_ARG)->valueint;
|
||||
int thermoPin = thermostat.getArg(0);
|
||||
|
||||
//float thermoSetting = aJson.getArrayItem(thermoItem, I_VAL)->valueint; ///
|
||||
float thermoSetting = thermostatCmd.getFloat();
|
||||
|
||||
int thermoStateCommand = aJson.getArrayItem(thermoItem, I_CMD)->valueint;
|
||||
|
||||
float curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valuefloat;
|
||||
|
||||
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
||||
@@ -2144,7 +2169,7 @@ void thermoLoop(void) {
|
||||
}
|
||||
}
|
||||
configLocked--;
|
||||
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
|
||||
timerThermostatCheck = millis();// + THERMOSTAT_CHECK_PERIOD;
|
||||
publishStat();
|
||||
#ifndef DISABLE_FREERAM_PRINT
|
||||
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" ");
|
||||
|
||||
@@ -75,9 +75,9 @@ extern Streamlog errorSerial;
|
||||
#define wdt_dis()
|
||||
#endif
|
||||
|
||||
#ifndef DHCP_RETRY_INTERVAL
|
||||
#define DHCP_RETRY_INTERVAL 60000
|
||||
#endif
|
||||
//#ifndef DHCP_RETRY_INTERVAL
|
||||
//#define DHCP_RETRY_INTERVAL 60000
|
||||
//#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
#define wdt_en() wdt_enable(WDTO_8S)
|
||||
|
||||
@@ -122,7 +122,7 @@ else //ESP I2C glitch
|
||||
Serial.println("I2C Reset");
|
||||
i2cReset();
|
||||
}
|
||||
return INTERVAL_POLLING;
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
}
|
||||
|
||||
int in_ccs811::Poll(short cause)
|
||||
|
||||
@@ -158,7 +158,7 @@ void out_AC::InsertData(byte data[], size_t size){
|
||||
publishTopic(item->itemArr->name, s_mode,"/cmd");
|
||||
|
||||
else publishTopic(item->itemArr->name, "OFF","/cmd");
|
||||
|
||||
/*
|
||||
String raw_str;
|
||||
char raw[75];
|
||||
for (int i=0; i < 37; i++){
|
||||
@@ -173,7 +173,7 @@ void out_AC::InsertData(byte data[], size_t size){
|
||||
raw_str.toCharArray(raw,75);
|
||||
publishTopic(item->itemArr->name, raw,"/raw");
|
||||
Serial.println(raw);
|
||||
|
||||
*/
|
||||
///////////////////////////////////
|
||||
}
|
||||
|
||||
@@ -241,9 +241,10 @@ int out_AC::Poll(short cause)
|
||||
{
|
||||
if (cause!=POLLING_SLOW) return 0;
|
||||
|
||||
long now = millis();
|
||||
if (now - prevPolling > INTERVAL_AC_POLLING) {
|
||||
prevPolling = now;
|
||||
//long now = millis();
|
||||
//if (now - prevPolling > INTERVAL_AC_POLLING) {
|
||||
if (isTimeOver(prevPolling,millis(),INTERVAL_AC_POLLING)) {
|
||||
prevPolling = millisNZ();
|
||||
Serial.println ("Polling");
|
||||
SendData(qstn, sizeof(qstn)/sizeof(byte)); //Опрос кондиционера
|
||||
}
|
||||
@@ -259,7 +260,7 @@ delay(100);
|
||||
InsertData(data, 37);
|
||||
}
|
||||
}
|
||||
return INTERVAL_POLLING;
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
};
|
||||
|
||||
//int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
||||
|
||||
@@ -68,14 +68,18 @@ if (!item || !show) return 0;
|
||||
short cType=getChanType();
|
||||
uint8_t storageType;
|
||||
|
||||
/*
|
||||
switch (cmd.getCmd()){
|
||||
case CMD_OFF:
|
||||
cmd.Percents(0);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
debugSerial<<F("DMX ctrl: "); cmd.debugOut();
|
||||
|
||||
|
||||
if (cType==CH_DIMMER) //Single channel
|
||||
{
|
||||
DmxWrite(iaddr, cmd.getPercents255());
|
||||
@@ -95,8 +99,8 @@ if (cType==CH_DIMMER) //Single channel
|
||||
}
|
||||
|
||||
itemCmd st(storageType,CMD_VOID);
|
||||
|
||||
st.assignFrom(cmd);
|
||||
|
||||
debugSerial<<F("Assigned:");st.debugOut();
|
||||
switch (cType)
|
||||
{
|
||||
|
||||
@@ -144,7 +144,7 @@ if (!store)
|
||||
{ errorSerial<<F("MBUS: Out of memory")<<endl;
|
||||
return 0;}
|
||||
|
||||
store->timestamp=millis();
|
||||
store->timestamp=millisNZ();
|
||||
if (getConfig())
|
||||
{
|
||||
//item->clearFlag(ACTION_NEEDED);
|
||||
@@ -354,7 +354,7 @@ if (store->pollingRegisters && !modbusBusy && (Status() == CST_INITIALIZED) && i
|
||||
reg = reg->next;
|
||||
}
|
||||
|
||||
store->timestamp=millis();
|
||||
store->timestamp=millisNZ();
|
||||
debugSerial<<F("endPoll ")<< item->itemArr->name << endl;
|
||||
|
||||
//Non blocking waiting to release line
|
||||
|
||||
@@ -132,7 +132,8 @@ if (curPos<0) curPos=0;
|
||||
if (curPos>100) curPos=100;
|
||||
}
|
||||
|
||||
if (motorOfftime && motorOfftime<millis()) //Time over
|
||||
//if (motorOfftime && motorOfftime<millis()) //Time over
|
||||
if (motorOfftime && isTimeOver(motorOfftime,millis(),maxOnTime))
|
||||
{dif = 0; debugSerial<<F("Motor timeout")<<endl;}
|
||||
else if (curPos>=0)
|
||||
dif=targetPos-curPos;
|
||||
@@ -145,7 +146,7 @@ if (dif<-POS_ERR)
|
||||
{
|
||||
|
||||
digitalWrite(pinDown,INACTIVE);
|
||||
if (!item->getExt())item->setExt(millis()+maxOnTime);
|
||||
if (!item->getExt())item->setExt(millisNZ());
|
||||
|
||||
//
|
||||
//PINS_COUNT
|
||||
@@ -193,7 +194,7 @@ if (dif>POS_ERR)
|
||||
{
|
||||
digitalWrite(pinUp,INACTIVE);
|
||||
|
||||
if (!item->getExt()) item->setExt(millis()+maxOnTime);
|
||||
if (!item->getExt()) item->setExt(millisNZ());
|
||||
#ifndef ESP32
|
||||
if (digitalPinHasPWM(pinDown))
|
||||
{
|
||||
@@ -269,7 +270,7 @@ debugSerial<<F("Forced execution");
|
||||
case S_SET:
|
||||
if (!cmd.isValue()) return 0;
|
||||
// item->setVal(cmd.getPercents());
|
||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
/*
|
||||
st.assignFrom(cmd);
|
||||
//Store
|
||||
@@ -279,7 +280,7 @@ case S_SET:
|
||||
if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF);
|
||||
if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON);
|
||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
}
|
||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
||||
*/
|
||||
@@ -315,12 +316,12 @@ case S_CMD:
|
||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||
}
|
||||
*/
|
||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
return 1;
|
||||
|
||||
case CMD_OFF:
|
||||
////item->SendStatus(SEND_COMMAND);
|
||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
return 1;
|
||||
|
||||
} //switch cmd
|
||||
|
||||
@@ -119,7 +119,7 @@ int out_pid::Poll(short cause)
|
||||
if ((Status() == CST_INITIALIZED) && isTimeOver(store->timestamp,millis(),store->pollingInterval))
|
||||
{
|
||||
|
||||
store->timestamp=millis();
|
||||
store->timestamp=millisNZ();
|
||||
debugSerial<<F("endPoll ")<< item->itemArr->name << endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -125,12 +125,13 @@ bool inverse = (item->getArg()<0);
|
||||
short cType = getChanType();
|
||||
uint8_t storageType;
|
||||
|
||||
/*
|
||||
switch (cmd.getCmd()){
|
||||
case CMD_OFF:
|
||||
cmd.Percents(0);
|
||||
break;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
switch (cType)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
#define AVR_DMXOUT_PIN 18
|
||||
#endif
|
||||
|
||||
#define WIFI_TIMEOUT 60000UL
|
||||
#define TIMEOUT_RECONNECT 10000UL
|
||||
#define TIMEOUT_REINIT 5000UL
|
||||
#define TIMEOUT_RETAIN 5000UL
|
||||
#define INTERVAL_1W 5000UL
|
||||
|
||||
#define T_ATTEMPTS 200
|
||||
#define IET_TEMP 0
|
||||
#define IET_ATTEMPTS 1
|
||||
@@ -69,8 +75,8 @@
|
||||
#define INTERVAL_CHECK_SENSOR 5000
|
||||
#endif
|
||||
|
||||
#define INTERVAL_CHECK_MODBUS 2000
|
||||
#define INTERVAL_POLLING 100
|
||||
#define INTERVAL_SLOW_POLLING 1000
|
||||
//#define INTERVAL_POLLING 100
|
||||
#define THERMOSTAT_CHECK_PERIOD 30000
|
||||
|
||||
#ifndef OW_UPDATE_INTERVAL
|
||||
|
||||
@@ -42,7 +42,7 @@ owChangedType owChanged;
|
||||
|
||||
int owUpdate() {
|
||||
#ifndef OWIRE_DISABLE
|
||||
unsigned long finish = millis() + OW_UPDATE_INTERVAL;
|
||||
unsigned long finish = millis();// + OW_UPDATE_INTERVAL;
|
||||
/*
|
||||
if (oneWire->getError() == DS2482_ERROR_SHORT)
|
||||
{
|
||||
@@ -54,7 +54,8 @@ int owUpdate() {
|
||||
if (oneWire) oneWire->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && !isTimeOver(finish,millis(), OW_UPDATE_INTERVAL))//&& finish > millis())
|
||||
{
|
||||
short ifind = -1;
|
||||
if (oneWire->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||
for (short i = 0; i < t_count; i++)
|
||||
@@ -202,7 +203,12 @@ int sensors_loop(void) {
|
||||
|
||||
|
||||
void owLoop() {
|
||||
if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
||||
//if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
||||
if (isTimeOver(owTimer,millis(),INTERVAL_1W))
|
||||
{
|
||||
sensors_loop();
|
||||
owTimer=millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
|
||||
#include "statusled.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
statusLED::statusLED(uint8_t pattern)
|
||||
@@ -28,7 +29,7 @@ statusLED::statusLED(uint8_t pattern)
|
||||
pinMode(pinGREEN, OUTPUT);
|
||||
pinMode(pinBLUE, OUTPUT);
|
||||
set(pattern);
|
||||
timestamp=millis()+ledDelayms;
|
||||
timestamp=millis();//+ledDelayms;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -71,11 +72,12 @@ void statusLED::poll()
|
||||
curStat&=~ledFlash;
|
||||
show(curStat);
|
||||
}
|
||||
if (millis()>timestamp)
|
||||
//if (millis()>timestamp)
|
||||
if (isTimeOver(timestamp,millis(),(curStat & ledFASTBLINK)?ledFastDelayms:ledDelayms))
|
||||
{
|
||||
|
||||
if (curStat & ledFASTBLINK) timestamp=millis()+ledFastDelayms;
|
||||
else timestamp=millis()+ledDelayms;
|
||||
timestamp=millis();
|
||||
//if (curStat & ledFASTBLINK) timestamp=millis()+ledFastDelayms;
|
||||
// else timestamp=millis()+ledDelayms;
|
||||
|
||||
if (( curStat & ledBLINK) || (curStat & ledFASTBLINK))
|
||||
{
|
||||
|
||||
@@ -632,6 +632,13 @@ itemCmd mapInt(int32_t arg, aJsonObject* map)
|
||||
return _itemCmd.Int(arg);
|
||||
}
|
||||
|
||||
unsigned long millisNZ()
|
||||
{
|
||||
unsigned long now = millis();
|
||||
if (!now) now=1;
|
||||
return now;
|
||||
}
|
||||
|
||||
|
||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||
|
||||
@@ -65,3 +65,4 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m
|
||||
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
||||
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd);
|
||||
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
||||
unsigned long millisNZ();
|
||||
|
||||
Reference in New Issue
Block a user