fix SwitchMote example
This commit is contained in:
parent
bce10f3e39
commit
ca3140ca32
|
|
@ -88,9 +88,9 @@
|
||||||
#define SYNC_DIGIT_SYNCMODE 3 //fourth digit indicates the mode that should be requested on the target
|
#define SYNC_DIGIT_SYNCMODE 3 //fourth digit indicates the mode that should be requested on the target
|
||||||
#define SYNC_MIN_TIME_LIMIT 2000 //minimum time limit since last SYNC before a new sync can be propagated (used to stop circular SYNC loops)
|
#define SYNC_MIN_TIME_LIMIT 2000 //minimum time limit since last SYNC before a new sync can be propagated (used to stop circular SYNC loops)
|
||||||
|
|
||||||
#define SERIAL_EN //comment this out when deploying to an installed SM to save a few KB of sketch size
|
#define DEBUG_EN //comment this out when deploying to an installed SM to save a few KB of sketch size
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#ifdef SERIAL_EN
|
#ifdef DEBUG_EN
|
||||||
#define DEBUG(input) {Serial.print(input); delay(1);}
|
#define DEBUG(input) {Serial.print(input); delay(1);}
|
||||||
#define DEBUGln(input) {Serial.println(input); delay(1);}
|
#define DEBUGln(input) {Serial.println(input); delay(1);}
|
||||||
#else
|
#else
|
||||||
|
|
@ -149,10 +149,11 @@ byte btnLEDRED[] = {LED_RT, LED_RM, LED_RB};
|
||||||
byte btnLEDGRN[] = {LED_GT, LED_GM, LED_GB};
|
byte btnLEDGRN[] = {LED_GT, LED_GM, LED_GB};
|
||||||
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
||||||
char * buff="justAnEmptyString";
|
char * buff="justAnEmptyString";
|
||||||
|
byte len=0;
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
#ifdef SERIAL_EN
|
#ifdef DEBUG_EN
|
||||||
Serial.begin(SERIAL_BAUD);
|
Serial.begin(SERIAL_BAUD);
|
||||||
#endif
|
#endif
|
||||||
EEPROM.setMaxAllowedWrites(10000);
|
EEPROM.setMaxAllowedWrites(10000);
|
||||||
|
|
@ -281,7 +282,7 @@ void loop()
|
||||||
else { DEBUGln(F("NO SYNC REPLY ..")); }
|
else { DEBUGln(F("NO SYNC REPLY ..")); }
|
||||||
|
|
||||||
isSyncMode = true;
|
isSyncMode = true;
|
||||||
DEBUGln(F("SYNC MODE ON"));
|
DEBUGln(F("SYNC MODE ENTER"));
|
||||||
displaySYNC();
|
displaySYNC();
|
||||||
syncStart = now;
|
syncStart = now;
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +306,7 @@ void loop()
|
||||||
if (now-syncStart >= SYNC_TIME)
|
if (now-syncStart >= SYNC_TIME)
|
||||||
{
|
{
|
||||||
isSyncMode = false;
|
isSyncMode = false;
|
||||||
DEBUGln(F("SYNC MODE OFF"));
|
DEBUGln(F("\nSYNC MODE EXIT"));
|
||||||
action(btnIndex, mode[btnIndex], false);
|
action(btnIndex, mode[btnIndex], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -328,8 +329,8 @@ void loop()
|
||||||
if (isSyncMode && radio.DATALEN == 5
|
if (isSyncMode && radio.DATALEN == 5
|
||||||
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
||||||
{
|
{
|
||||||
sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
||||||
radio.sendACK(buff, strlen(buff));
|
radio.sendACK(buff, len);
|
||||||
DEBUG(F(" - SYNC ACK sent : "));
|
DEBUG(F(" - SYNC ACK sent : "));
|
||||||
DEBUGln(buff);
|
DEBUGln(buff);
|
||||||
isSyncMode = false;
|
isSyncMode = false;
|
||||||
|
|
@ -410,8 +411,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway)
|
||||||
//notify gateway
|
//notify gateway
|
||||||
if (notifyGateway)
|
if (notifyGateway)
|
||||||
{
|
{
|
||||||
sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode);
|
len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode);
|
||||||
if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts
|
if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts
|
||||||
{DEBUGln(F("..OK"));}
|
{DEBUGln(F("..OK"));}
|
||||||
else {DEBUGln(F("..NOK"));}
|
else {DEBUGln(F("..NOK"));}
|
||||||
}
|
}
|
||||||
|
|
@ -486,7 +487,7 @@ boolean checkSYNC(byte nodeIDToSkip)
|
||||||
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
DEBUG(F("]:"));
|
DEBUG(F("]:"));
|
||||||
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
if (radio.sendWithRetry(SYNC_TO[i], buff,6))
|
if (radio.sendWithRetry(SYNC_TO[i], buff, 6))
|
||||||
{DEBUG(F("OK"));}
|
{DEBUG(F("OK"));}
|
||||||
else {DEBUG(F("NOK"));}
|
else {DEBUG(F("NOK"));}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,7 @@ byte btnLEDRED[] = {LED_RT, LED_RM, LED_RB};
|
||||||
byte btnLEDGRN[] = {LED_GT, LED_GM, LED_GB};
|
byte btnLEDGRN[] = {LED_GT, LED_GM, LED_GB};
|
||||||
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
||||||
char * buff="justAnEmptyString";
|
char * buff="justAnEmptyString";
|
||||||
|
byte len=0;
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
|
|
@ -326,8 +327,8 @@ void loop()
|
||||||
if (isSyncMode && radio.DATALEN == 5
|
if (isSyncMode && radio.DATALEN == 5
|
||||||
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
||||||
{
|
{
|
||||||
sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
||||||
radio.sendACK(buff, strlen(buff));
|
radio.sendACK(buff, len);
|
||||||
DEBUG(F(" - SYNC ACK sent : "));
|
DEBUG(F(" - SYNC ACK sent : "));
|
||||||
DEBUGln(buff);
|
DEBUGln(buff);
|
||||||
isSyncMode = false;
|
isSyncMode = false;
|
||||||
|
|
@ -408,8 +409,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway)
|
||||||
//notify gateway
|
//notify gateway
|
||||||
if (notifyGateway)
|
if (notifyGateway)
|
||||||
{
|
{
|
||||||
sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode);
|
len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode);
|
||||||
if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts
|
if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts
|
||||||
{DEBUGln(F("..OK"));}
|
{DEBUGln(F("..OK"));}
|
||||||
else {DEBUGln(F("..NOK"));}
|
else {DEBUGln(F("..NOK"));}
|
||||||
}
|
}
|
||||||
|
|
@ -484,7 +485,7 @@ boolean checkSYNC(byte nodeIDToSkip)
|
||||||
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
DEBUG(F("]:"));
|
DEBUG(F("]:"));
|
||||||
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
if (radio.sendWithRetry(SYNC_TO[i], buff,6))
|
if (radio.sendWithRetry(SYNC_TO[i], buff, 6))
|
||||||
{DEBUG(F("OK"));}
|
{DEBUG(F("OK"));}
|
||||||
else {DEBUG(F("NOK"));}
|
else {DEBUG(F("NOK"));}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ byte btnLEDRED[] = {LED_RT, LED_RB};
|
||||||
byte btnLEDGRN[] = {LED_GT, LED_GB};
|
byte btnLEDGRN[] = {LED_GT, LED_GB};
|
||||||
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
|
||||||
char * buff="justAnEmptyString";
|
char * buff="justAnEmptyString";
|
||||||
|
byte len=0;
|
||||||
|
|
||||||
#ifdef PIRPRESENT
|
#ifdef PIRPRESENT
|
||||||
boolean PIR_MOTION_RELAY=false;
|
boolean PIR_MOTION_RELAY=false;
|
||||||
|
|
@ -408,8 +409,8 @@ void loop()
|
||||||
if (isSyncMode && radio.DATALEN == 5
|
if (isSyncMode && radio.DATALEN == 5
|
||||||
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
&& radio.DATA[0]=='S' && radio.DATA[1]=='Y' && radio.DATA[2]=='N' && radio.DATA[3] == 'C' && radio.DATA[4]=='?')
|
||||||
{
|
{
|
||||||
sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information
|
||||||
radio.sendACK(buff, strlen(buff));
|
radio.sendACK(buff, len);
|
||||||
DEBUG(F(" - SYNC ACK sent : "));
|
DEBUG(F(" - SYNC ACK sent : "));
|
||||||
DEBUGln(buff);
|
DEBUGln(buff);
|
||||||
isSyncMode = false;
|
isSyncMode = false;
|
||||||
|
|
@ -491,8 +492,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway)
|
||||||
//notify gateway
|
//notify gateway
|
||||||
if (notifyGateway)
|
if (notifyGateway)
|
||||||
{
|
{
|
||||||
sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode);
|
len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode);
|
||||||
if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts
|
if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts
|
||||||
{DEBUGln(F("..OK"));}
|
{DEBUGln(F("..OK"));}
|
||||||
else {DEBUGln(F("..NOK"));}
|
else {DEBUGln(F("..NOK"));}
|
||||||
}
|
}
|
||||||
|
|
@ -567,7 +568,7 @@ boolean checkSYNC(byte nodeIDToSkip)
|
||||||
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
DEBUG(F("]:"));
|
DEBUG(F("]:"));
|
||||||
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
sprintf(buff, "BTN%d:%d", getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCBTN), getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE));
|
||||||
if (radio.sendWithRetry(SYNC_TO[i], buff,6))
|
if (radio.sendWithRetry(SYNC_TO[i], buff, 6))
|
||||||
{DEBUG(F("OK"));}
|
{DEBUG(F("OK"));}
|
||||||
else {DEBUG(F("NOK"));}
|
else {DEBUG(F("NOK"));}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue