scmd,rcmd in inputs may contain not only cmd but values, minimal dimmers volume treshhold for ON command, remote command execute on MQTT command (new Cmd.h required), bat-files to flash DUE and start CLI added

This commit is contained in:
2018-05-25 09:29:47 +03:00
parent b8861d895a
commit 8e38095177
10 changed files with 154 additions and 144 deletions

Binary file not shown.

3
compiled/DUE/upload.bat Normal file
View File

@@ -0,0 +1,3 @@
mode com3:1200,n,8,1
pause
C:\Users\Akmal\.platformio\packages\tool-bossac\bossac.exe -i --port=com3 -U false -e -w -v -b C:\Users\Akmal\ownCloud\compiled\due\Wiz5500\firmware.bin -R

View File

@@ -0,0 +1,3 @@
mode com3:1200,n,8,1
pause
C:\Users\Akmal\.platformio\packages\tool-bossac\bossac.exe -i --port=com3 -U false -e -w -v -b C:\Users\Akmal\ownCloud\compiled\due\Wiz5500\firmware999.bin -R

1
compiled/mon.bat Normal file
View File

@@ -0,0 +1 @@
pio device monitor -b 115200

View File

@@ -110,7 +110,7 @@ int Input::Poll()
void Input::Changed (int val)
{
Serial.print(pin);Serial.print(F("="));Serial.println(val);
Serial.print(F("IN:")); Serial.print(pin);Serial.print(F("="));Serial.println(val);
aJsonObject * item = aJson.getObjectItem(inputObj,"item");
aJsonObject * scmd = aJson.getObjectItem(inputObj,"scmd");
aJsonObject * rcmd = aJson.getObjectItem(inputObj,"rcmd");
@@ -136,11 +136,11 @@ void Input::Changed (int val)
{
if (val)
{ //send set command
if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(txt2cmd(scmd->valuestring),0,NULL,true);
if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(scmd->valuestring,true);
}
else
{ //send reset command
if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(txt2cmd(rcmd->valuestring),0,NULL,true);
if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(rcmd->valuestring,true);
}
}
}

View File

@@ -20,7 +20,7 @@ e-mail anklimov@gmail.com
#include "aJSON.h"
#define IN_ACTIVE_HIGH 128 // High level = PUSHED/ CLOSED/ ON othervise :Low Level
#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level
#define IN_ANALOG 64 // Analog input
#define IN_RE 32 // Rotary Encoder (for further use)
@@ -91,7 +91,3 @@ class Input
protected:
void Parse();
};

View File

@@ -199,6 +199,53 @@ boolean Item::getEnableCMD(int delta) {
}
#define MAXCTRLPAR 3
int Item::Ctrl(char * payload, boolean send){
int cmd = txt2cmd(payload);
switch (cmd) {
case 0: {
short i = 0;
int Par[3];
while (payload && i < 3)
Par[i++] = getInt((char **) &payload);
Ctrl(0, i, Par, send);
}
break;
case -1: //Not known command
case -2: //JSON input (not implemented yet
break;
case -3: //RGB color in #RRGGBB notation
{
CRGB rgb;
if (sscanf((const char*)payload, "#%2X%2X%2X", &rgb.r, &rgb.g, &rgb.b) == 3) {
int Par[3];
CHSV hsv = rgb2hsv_approximate(rgb);
Par[0] = map(hsv.h, 0, 255, 0, 365);
Par[1] = map(hsv.s, 0, 255, 0, 100);
Par[2] = map(hsv.v, 0, 255, 0, 100);
Ctrl(0, 3, Par, send);
}
break;
}
case CMD_ON:
// if (item.getEnableCMD(500) || lanStatus == 4)
Ctrl(cmd, 0, NULL,
send); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
// else Serial.println(F("on Skipped"));
break;
default: //some known command
Ctrl(cmd, 0, NULL, send);
} //ctrl
}
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
@@ -286,6 +333,20 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
setCmd(cmd);
//retrive stored values
st.aslong = getVal();
// If command is ON but saved volume to low - setup mimimum volume
switch (itemType) {
case CH_DIMMER:
case CH_MODBUS:
if (st.aslong<MIN_VOLUME) st.aslong=INIT_VOLUME;
setVal(st.aslong);
break;
case CH_RGB:
case CH_RGBW:
if (st.aslong && (st.v<MIN_VOLUME)) st.v=INIT_VOLUME;
setVal(st.aslong);
}
if (st.aslong > 0) //Stored smthng
switch (itemType) {
@@ -295,8 +356,6 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
Par[0] = st.h;
Par[1] = st.s;
Par[2] = st.v;
if (!Par[2]) Par[2]=80; //If RGB value==0 set to 80%
setVal(st.aslong);
params = 3;
SendStatus(0, params, Par,true); // Send restored triplet. In any cases
break;
@@ -306,8 +365,6 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
case CH_DIMMER: //Everywhere, in flat VAL
case CH_MODBUS:
case CH_VC:
Par[0] = st.aslong;
params = 1;
SendStatus(0, params, Par, true); // Send restored parameter, even if send=false - no problem, loop will be supressed at next hop
@@ -616,8 +673,8 @@ int Item::isActive() {
case CH_PWM:
val = st.aslong;
} //switch
Serial.print(F(":="));
Serial.println(val);
//Serial.print(F(":="));
//Serial.println(val);
if (val) return 1; else return 0;
}
@@ -712,8 +769,8 @@ int Item::VacomSetFan(int8_t val, int8_t cmd) {
}
modbusBusy = 1;
uint8_t j, result;
uint16_t data[1];
uint8_t j;//, result;
//uint16_t data[1];
modbusSerial.begin(9600, fmPar);
node.begin(addr, modbusSerial);
@@ -987,7 +1044,7 @@ int Item::checkModbusDimmer() {
uint16_t addr = getArg(0);
uint16_t reg = getArg(1);
short mask = getArg(2);
// short mask = getArg(2);
int data;

View File

@@ -88,6 +88,8 @@ class Item
Item(aJsonObject * obj);
boolean isValid ();
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true);
virtual int Ctrl(char * payload, boolean send=true);
int getArg(short n=0);
boolean getEnableCMD(int delta);
//int getVal(short n); //From VAL array. Negative if no array

View File

@@ -141,6 +141,11 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
}
Serial.println();
if(!strcmp(topic,CMDTOPIC)) {
cmd_parse((char *)payload);
return;
}
boolean retaining = (lanStatus == 4); //Todo - named constant
//Check if topic = Command topic
short intopic = 0;
@@ -149,86 +154,23 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
strncpy_P(buf, inprefix, sizeof(buf));
intopic = strncmp(topic, buf, strlen(inprefix));
}
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
if (retaining && !intopic) {
Serial.println(F("Skipping.."));
return;
}
char subtopic[MQTT_SUBJECT_LENGTH] = "";
int cmd = 0;
cmd = txt2cmd((char *) payload);
// int cmd = 0;
//cmd = txt2cmd((char *) payload);
char *t;
if (t = strrchr(topic, '/'))
strncpy(subtopic, t + 1, MQTT_SUBJECT_LENGTH - 1);
/* No 1-w direct support anymore
int subchan;
char buf[17];
//Check for one-wire address
if (sscanf(subtopic,"S%1d%16s",&subchan,&buf)==2) // SnXXXXXXXX
{ DeviceAddress addr;
SetAddr(buf,addr);;
PrintBytes(addr,8);
Serial.print(F(":"));
Serial.println(subchan);
cntrl2413(addr,subchan,(cmd==CMD_ON)?1:0);
}// End OneWire
else
*/
{
Item item(subtopic);
if (item.isValid()) {
if (item.itemType == CH_GROUP && retaining)
return; //Do not restore group channels - they consist not relevant data
switch (cmd) {
case 0: {
short i = 0;
int Par[3];
while (payload && i < 3)
Par[i++] = getInt((char **) &payload);
item.Ctrl(0, i, Par, !retaining);
}
break;
case -1: //Not known command
case -2: //JSON input (not implemented yet
break;
case -3: //RGB color in #RRGGBB notation
{
CRGB rgb;
if (sscanf((const char*)payload, "#%2X%2X%2X", &rgb.r, &rgb.g, &rgb.b) == 3) {
int Par[3];
CHSV hsv = rgb2hsv_approximate(rgb);
Par[0] = map(hsv.h, 0, 255, 0, 365);
Par[1] = map(hsv.s, 0, 255, 0, 100);
Par[2] = map(hsv.v, 0, 255, 0, 100);
item.Ctrl(0, 3, Par, !retaining);
}
break;
}
case CMD_ON:
// if (item.getEnableCMD(500) || lanStatus == 4)
item.Ctrl(cmd, 0, NULL,
!retaining); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
// else Serial.println(F("on Skipped"));
break;
default: //some known command
item.Ctrl(cmd, 0, NULL, !retaining);
} //ctrl
} //valid json
} //no1wire
item.Ctrl((char *)payload, !retaining);
} //valid item
}
#ifndef __ESP__

View File

@@ -17,6 +17,8 @@
#define THERMO_OVERHEAT_CELSIUS 38
#define FM_OVERHEAT_CELSIUS 40.
#define MIN_VOLUME 10
#define INIT_VOLUME 30
#define OFFSET_MAC 0
#define OFFSET_IP OFFSET_MAC+6
@@ -57,6 +59,10 @@
#define OUTTOPIC "/myhome/s_out/"
#endif
#ifndef CMDTOPIC
#define CMDTOPIC "/myhome/in/command/"
#endif
#ifndef INTOPIC
#define INTOPIC "/myhome/in/"
#endif