mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Modbus retry for VaCom fixed
1-st attempt to add OTA
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
-DMODBUS_DISABLE
|
||||
#-DCOUNTER_DISABLE
|
||||
-DOTA
|
||||
|
||||
@@ -685,7 +685,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
|
||||
case CMD_ON:
|
||||
|
||||
|
||||
if (itemType==CH_RGBW && getCmd() == CMD_ON && send /*&& getEnableCMD(500) */) {
|
||||
if (itemType==CH_RGBW && getCmd() == CMD_ON && send && (chActive>0)/*&& getEnableCMD(500) */) {
|
||||
debugSerial<<F("Force White\n");
|
||||
itemType = CH_WHITE;
|
||||
Par[1] = 0; //Zero saturation
|
||||
@@ -869,7 +869,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
|
||||
// 0..50 - white + RGB
|
||||
//50..100 RGB
|
||||
{
|
||||
int k;
|
||||
// int k;
|
||||
if (Par[1]<50 && iaddr>0) { // Using white
|
||||
DmxWrite(iaddr + 3, map((50 - Par[1]) * Par[2], 0, 5000, 0, 255));
|
||||
int rgbvLevel = map (Par[1],0,50,0,255*2);
|
||||
@@ -978,8 +978,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
|
||||
//prescaler = 4 ---> PWM frequency is 120 Hz
|
||||
//prescaler = 5 ---> PWM frequency is 30 Hz
|
||||
//prescaler = 6 ---> PWM frequency is <20 Hz
|
||||
int tval = 7; // this is 111 in binary and is used as an eraser
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
int tval = 7; // this is 111 in binary and is used as an eraser
|
||||
TCCR4B &= ~tval; // this operation (AND plus NOT), set the three bits in TCCR2B to 0
|
||||
TCCR3B &= ~tval;
|
||||
tval = 2;
|
||||
@@ -997,9 +997,9 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
|
||||
VacomSetFan(Par[0], cmd);
|
||||
break;
|
||||
case CH_VCTEMP: {
|
||||
Item it(itemArg->valuestring);
|
||||
if (it.isValid() && it.itemType == CH_VC)
|
||||
VacomSetHeat(it.getArg(), Par[0], cmd);
|
||||
// Item it(itemArg->valuestring);
|
||||
// if (it.isValid() && it.itemType == CH_VC)
|
||||
VacomSetHeat(Par[0], cmd);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -1172,8 +1172,8 @@ int Item::modbusDimmerSet(uint16_t value)
|
||||
if (numpar >= (MODBUS_CMD_ARG_MAX_SCALE+1)) _maxval = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_MAX_SCALE)->valueint;
|
||||
int _regType = MODBUS_HOLDING_REG_TYPE;
|
||||
if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint;
|
||||
if (_maxval) modbusDimmerSet(_addr, _reg, _regType, _mask, map(value, 0, 100, 0, _maxval));
|
||||
else modbusDimmerSet(_addr, _reg, _regType, _mask, value);
|
||||
if (_maxval) return modbusDimmerSet(_addr, _reg, _regType, _mask, map(value, 0, 100, 0, _maxval));
|
||||
else return modbusDimmerSet(_addr, _reg, _regType, _mask, value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1221,8 +1221,14 @@ int Item::VacomSetFan(int8_t val, int8_t cmd) {
|
||||
#define a 0.1842f
|
||||
#define b -36.68f
|
||||
|
||||
int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) {
|
||||
int Item::VacomSetHeat(int8_t val, int8_t cmd) {
|
||||
uint8_t result;
|
||||
int addr;
|
||||
|
||||
Item it(itemArg->valuestring);
|
||||
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
||||
else return 0;
|
||||
|
||||
debugSerial<<F("VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||
if (modbusBusy) {
|
||||
setCmd(cmd);
|
||||
@@ -1300,7 +1306,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
|
||||
int Item::checkFM() {
|
||||
if (modbusBusy) return -1;
|
||||
if (checkModbusRetry()) return -2;
|
||||
if (checkVCRetry()) return -2;
|
||||
modbusBusy = 1;
|
||||
|
||||
uint8_t j, result;
|
||||
@@ -1404,13 +1410,39 @@ int Item::checkFM() {
|
||||
}
|
||||
|
||||
boolean Item::checkModbusRetry() {
|
||||
if (modbusBusy) return false;
|
||||
// int cmd = getCmd();
|
||||
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
|
||||
int val = getVal();
|
||||
debugSerial<<F("Retrying dimmer CMD\n");
|
||||
clearFlag(SEND_RETRY); // Clean retry flag
|
||||
modbusDimmerSet(val);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean Item::checkVCRetry() {
|
||||
if (modbusBusy) return false;
|
||||
int cmd = getCmd();
|
||||
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
|
||||
int val = getVal();
|
||||
debugSerial<<F("Retrying CMD\n");
|
||||
debugSerial<<F("Retrying VC CMD\n");
|
||||
clearFlag(SEND_RETRY); // Clean retry flag
|
||||
//Ctrl(cmd,1,&val); // Execute command again
|
||||
modbusDimmerSet(val);
|
||||
VacomSetFan(val,cmd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean Item::checkHeatRetry() {
|
||||
if (modbusBusy) return false;
|
||||
int cmd = getCmd();
|
||||
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
|
||||
int val = getVal();
|
||||
debugSerial<<F("Retrying VC temp CMD\n");
|
||||
clearFlag(SEND_RETRY); // Clean retry flag
|
||||
VacomSetHeat(val,cmd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1537,6 +1569,11 @@ switch (cause)
|
||||
sendDelayedStatus();
|
||||
return INTERVAL_CHECK_MODBUS;
|
||||
break;
|
||||
case CH_VCTEMP:
|
||||
checkHeatRetry();
|
||||
sendDelayedStatus();
|
||||
return INTERVAL_CHECK_MODBUS;
|
||||
break;
|
||||
/* case CH_RGB: //All channels with slider generate too many updates
|
||||
case CH_RGBW:
|
||||
case CH_DIMMER:
|
||||
|
||||
@@ -193,7 +193,7 @@ class Item
|
||||
protected:
|
||||
//short cmd2changeActivity(int lastActivity, short defaultCmd = CMD_SET);
|
||||
int VacomSetFan (int8_t val, int8_t cmd=0);
|
||||
int VacomSetHeat(int addr, int8_t val, int8_t cmd=0);
|
||||
int VacomSetHeat(int8_t val, int8_t cmd=0);
|
||||
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
|
||||
int modbusDimmerSet(uint16_t value);
|
||||
void mb_fail();
|
||||
@@ -201,6 +201,8 @@ class Item
|
||||
int checkModbusDimmer();
|
||||
int checkModbusDimmer(int data);
|
||||
boolean checkModbusRetry();
|
||||
boolean checkVCRetry();
|
||||
boolean checkHeatRetry();
|
||||
void sendDelayedStatus();
|
||||
|
||||
int checkFM();
|
||||
|
||||
@@ -67,6 +67,9 @@ PWM Out
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#if defined(OTA)
|
||||
#include <ArduinoOTA.h>
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
DueFlashStorage EEPROM;
|
||||
@@ -301,6 +304,11 @@ lan_status lanLoop() {
|
||||
break;
|
||||
|
||||
case HAVE_IP_ADDRESS:
|
||||
#ifdef OTA
|
||||
// start the OTEthernet library with internal (flash) based storage
|
||||
ArduinoOTA.begin(Ethernet.localIP(), "Lighthub", "password", InternalStorage);
|
||||
#endif
|
||||
|
||||
if (!configOk)
|
||||
lanStatus = loadConfigFromHttp(0, NULL);
|
||||
else lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
@@ -308,12 +316,15 @@ lan_status lanLoop() {
|
||||
|
||||
case IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER:
|
||||
wdt_res();
|
||||
|
||||
|
||||
|
||||
ip_ready_config_loaded_connecting_to_broker();
|
||||
break;
|
||||
|
||||
case RETAINING_COLLECTING:
|
||||
if (millis() > nextLanCheckTime) {
|
||||
char buf[MQTT_TOPIC_LENGTH];
|
||||
char buf[MQTT_TOPIC_LENGTH+1];
|
||||
|
||||
//Unsubscribe from status topics..
|
||||
//strncpy_P(buf, outprefix, sizeof(buf));
|
||||
@@ -579,7 +590,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
// wdt_en();
|
||||
configOk = true;
|
||||
// ... Temporary subscribe to status topic
|
||||
char buf[MQTT_TOPIC_LENGTH];
|
||||
char buf[MQTT_TOPIC_LENGTH+1];
|
||||
|
||||
// strncpy_P(buf, outprefix, sizeof(buf));
|
||||
setTopic(buf,sizeof(buf),T_OUT);
|
||||
@@ -1641,6 +1652,10 @@ void setupCmdArduino() {
|
||||
}
|
||||
|
||||
void loop_main() {
|
||||
#if defined(OTA)
|
||||
ArduinoOTA.poll();
|
||||
#endif
|
||||
|
||||
#if defined(M5STACK)
|
||||
// Initialize the M5Stack object
|
||||
M5.update();
|
||||
|
||||
@@ -73,7 +73,7 @@ return 1;
|
||||
|
||||
void i2cReset(){
|
||||
Wire.endTransmission(true);
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
#if defined (SCL_RESET)
|
||||
SCL_LOW();
|
||||
delay(300);
|
||||
SCL_HIGH();
|
||||
|
||||
@@ -18,8 +18,17 @@
|
||||
|
||||
#define SCL_LOW() (GPES = (1 << twi_scl))
|
||||
#define SCL_HIGH() (GPEC = (1 << twi_scl))
|
||||
#define SCL_RESET
|
||||
#endif
|
||||
|
||||
/*
|
||||
#if defined (__SAM3X8E__)
|
||||
#define SCL_LOW() digitalWrite(21,LOW)
|
||||
#define SCL_HIGH() digitalWrite(21,HIGH)
|
||||
#define SCL_RESET
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP32)
|
||||
#undef WAK_PIN
|
||||
//#ifndef WAK_PIN
|
||||
|
||||
@@ -29,7 +29,7 @@ default_envs =
|
||||
; due-5100
|
||||
|
||||
; Arduino DUE + Ethernet shield Wiznet 5500
|
||||
; due-5500
|
||||
due-5500
|
||||
|
||||
; ESP 8266
|
||||
; esp8266-wifi
|
||||
@@ -86,6 +86,7 @@ lib_ignore =
|
||||
SparkFun CCS811 Arduino Library
|
||||
ESP8266HTTPClient
|
||||
M5Stack
|
||||
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
@@ -102,6 +103,7 @@ lib_deps =
|
||||
Streaming
|
||||
https://github.com/anklimov/NRFFlashStorage
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
; https://github.com/livello/PrintEx#is-select-redecl
|
||||
|
||||
|
||||
@@ -152,6 +154,7 @@ lib_deps =
|
||||
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git
|
||||
M5Stack
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:esp32-wifi]
|
||||
platform = espressif32
|
||||
@@ -200,6 +203,8 @@ lib_deps =
|
||||
;SparkFun CCS811 Arduino Library
|
||||
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:due-5100]
|
||||
platform = atmelsam
|
||||
framework = arduino
|
||||
@@ -242,6 +247,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:mega2560slim-5100]
|
||||
platform = atmelavr
|
||||
@@ -282,6 +288,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:mega2560-5500]
|
||||
platform = atmelavr
|
||||
@@ -321,12 +328,19 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
|
||||
[env:esp8266-wifi]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = nodemcuv2
|
||||
upload_protocol = espota
|
||||
upload_port = Lighthub.local
|
||||
;192.168.88.46
|
||||
upload_flags =
|
||||
--auth=password
|
||||
; --port=65280
|
||||
build_flags = !python get_build_flags.py esp8266-wifi
|
||||
lib_ignore =
|
||||
DmxSimple
|
||||
@@ -368,6 +382,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:mega2560-5100]
|
||||
platform = atmelavr
|
||||
@@ -409,6 +424,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:due-5500]
|
||||
platform = atmelsam
|
||||
@@ -432,6 +448,7 @@ lib_ignore =
|
||||
ESP_EEPROM
|
||||
EEPROM
|
||||
M5Stack
|
||||
ArduinoOTA
|
||||
lib_deps =
|
||||
https://github.com/sebnil/DueFlashStorage
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
@@ -456,6 +473,7 @@ lib_deps =
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
|
||||
|
||||
[env:lighthub21]
|
||||
platform = atmelsam
|
||||
framework = arduino
|
||||
@@ -500,6 +518,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
|
||||
[env:controllino]
|
||||
@@ -542,6 +561,7 @@ lib_deps =
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
[env:stm32-enc2860]
|
||||
platform = ststm32
|
||||
@@ -588,3 +608,4 @@ lib_deps =
|
||||
UIPEthernet
|
||||
https://github.com/anklimov/NRFFlashStorage
|
||||
Adafruit NeoPixel
|
||||
ArduinoOTA
|
||||
|
||||
Reference in New Issue
Block a user