diff --git a/Examples/SwitchMote/SwitchMote.ino b/Examples/SwitchMote/SwitchMote.ino index bb7e9d7..f35cb1a 100644 --- a/Examples/SwitchMote/SwitchMote.ino +++ b/Examples/SwitchMote/SwitchMote.ino @@ -88,9 +88,9 @@ #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 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 -#ifdef SERIAL_EN +#ifdef DEBUG_EN #define DEBUG(input) {Serial.print(input); delay(1);} #define DEBUGln(input) {Serial.println(input); delay(1);} #else @@ -149,10 +149,11 @@ byte btnLEDRED[] = {LED_RT, LED_RM, LED_RB}; 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 char * buff="justAnEmptyString"; +byte len=0; void setup(void) { - #ifdef SERIAL_EN + #ifdef DEBUG_EN Serial.begin(SERIAL_BAUD); #endif EEPROM.setMaxAllowedWrites(10000); @@ -281,7 +282,7 @@ void loop() else { DEBUGln(F("NO SYNC REPLY ..")); } isSyncMode = true; - DEBUGln(F("SYNC MODE ON")); + DEBUGln(F("SYNC MODE ENTER")); displaySYNC(); syncStart = now; } @@ -305,7 +306,7 @@ void loop() if (now-syncStart >= SYNC_TIME) { isSyncMode = false; - DEBUGln(F("SYNC MODE OFF")); + DEBUGln(F("\nSYNC MODE EXIT")); action(btnIndex, mode[btnIndex], false); } } @@ -328,8 +329,8 @@ void loop() if (isSyncMode && radio.DATALEN == 5 && 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 - radio.sendACK(buff, strlen(buff)); + len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information + radio.sendACK(buff, len); DEBUG(F(" - SYNC ACK sent : ")); DEBUGln(buff); isSyncMode = false; @@ -372,7 +373,7 @@ void loop() //delay(5); } } - + //check if a motion command timer expired and the corresponding light can turn off if ((offTimer > 0) && (millis() - offTimer > MOTION_TIME_ON)) { @@ -410,8 +411,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway) //notify gateway if (notifyGateway) { - sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode); - if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts + len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode); + if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts {DEBUGln(F("..OK"));} else {DEBUGln(F("..NOK"));} } @@ -486,7 +487,7 @@ boolean checkSYNC(byte nodeIDToSkip) DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE)); DEBUG(F("]:")); 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"));} else {DEBUG(F("NOK"));} } @@ -692,4 +693,4 @@ void handleMenuInput(char c) menu=0; break; } -} +} \ No newline at end of file diff --git a/Examples/SwitchMote/SwitchMoteR2.ino b/Examples/SwitchMote/SwitchMoteR2.ino index 96fa344..46d5205 100644 --- a/Examples/SwitchMote/SwitchMoteR2.ino +++ b/Examples/SwitchMote/SwitchMoteR2.ino @@ -147,6 +147,7 @@ byte btnLEDRED[] = {LED_RT, LED_RM, LED_RB}; 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 char * buff="justAnEmptyString"; +byte len=0; void setup(void) { @@ -326,8 +327,8 @@ void loop() if (isSyncMode && radio.DATALEN == 5 && 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 - radio.sendACK(buff, strlen(buff)); + len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information + radio.sendACK(buff, len); DEBUG(F(" - SYNC ACK sent : ")); DEBUGln(buff); isSyncMode = false; @@ -408,8 +409,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway) //notify gateway if (notifyGateway) { - sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode); - if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts + len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode); + if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts {DEBUGln(F("..OK"));} else {DEBUGln(F("..NOK"));} } @@ -484,7 +485,7 @@ boolean checkSYNC(byte nodeIDToSkip) DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE)); DEBUG(F("]:")); 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"));} else {DEBUG(F("NOK"));} } diff --git a/Examples/SwitchMote/SwitchMote_withPIR.ino b/Examples/SwitchMote/SwitchMote_withPIR.ino index 6c3d69d..3aa44fe 100644 --- a/Examples/SwitchMote/SwitchMote_withPIR.ino +++ b/Examples/SwitchMote/SwitchMote_withPIR.ino @@ -160,6 +160,7 @@ byte btnLEDRED[] = {LED_RT, LED_RB}; byte btnLEDGRN[] = {LED_GT, LED_GB}; uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios char * buff="justAnEmptyString"; +byte len=0; #ifdef PIRPRESENT boolean PIR_MOTION_RELAY=false; @@ -408,8 +409,8 @@ void loop() if (isSyncMode && radio.DATALEN == 5 && 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 - radio.sendACK(buff, strlen(buff)); + len = sprintf(buff,"SYNC%d:%d",btnIndex, mode[btnIndex]); //respond to SYNC request with this SM's button and mode information + radio.sendACK(buff, len); DEBUG(F(" - SYNC ACK sent : ")); DEBUGln(buff); isSyncMode = false; @@ -491,8 +492,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway) //notify gateway if (notifyGateway) { - sprintf(buff, "BTN%d:%d", whichButtonIndex,whatMode); - if (radio.sendWithRetry(GATEWAYID, buff, strlen(buff), 5)) //up to 5 attempts + len = sprintf(buff, "BTN%d:%d", whichButtonIndex, whatMode); + if (radio.sendWithRetry(GATEWAYID, buff, len, 5)) //up to 5 attempts {DEBUGln(F("..OK"));} else {DEBUGln(F("..NOK"));} } @@ -567,7 +568,7 @@ boolean checkSYNC(byte nodeIDToSkip) DEBUG(getDigit(SYNC_INFO[i],SYNC_DIGIT_SYNCMODE)); DEBUG(F("]:")); 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"));} else {DEBUG(F("NOK"));} }