//---------------------------------------------------------------------------------------------------------- // IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************* //---------------------------------------------------------------------------------------------------------- #define ENCRYPTKEY "sampleEncryptKey" // exactly the same 16 characters/bytes on all nodes! #define FREQUENCY RF69_915MHZ #define ACK_TIME 30 // # of ms to wait for an ack #define IS_RFM69HW_HCW boolean promiscuousMode = false; //set to 'true' to sniff all packets on the same network boolean requestACK = true; RFM69 radio; //---------------------------------------------------------------------------------------------------------- typedef struct { byte NETid; byte rcvr_NODEid; byte sndr_NODEid; byte COMMANDid; byte DELAYid; byte PACKETid; } Payload; Payload theData; ---------------------------------- Sender -------------------------------- /*********************************************************************************************************** executeTRANSMIT_COMMAND Do the logic to transmit the command to the designated receiver. Then qualify the command that ACK was received NOTE: In testing using retry of 6 with a 50Ms delay then 6 again is because the receiver might be running a command and not listening for the data. The fix to this is to get the interrupts working. another project ********************************************************************************************************* */ boolean executeTRANSMIT_COMMAND(int RCVR, int CMD, int DLAY ) { memset(&theData, '\0', sizeof(theData)); //- clear buffer PACKETcounter++; theData.NETid = NETWORKid; theData.sndr_NODEid = CONTROLLERid; theData.COMMANDid = CMD; theData.PACKETid = PACKETcounter; theData.DELAYid = DLAY; theData.rcvr_NODEid = RCVR; strobeLIGHT(OT_LED1, 1, 5); // //--------------------------------------------------------------------------------------------- // First send test. Try it multiple times if ACK back then success and transmit was good/true //--------------------------------------------------------------------------------------------- // old_TRANStime = millis(); if (radio.sendWithRetry(RCVR, (const void*)(&theData), sizeof(theData), 6) ) { new_TRANStime = millis(); return(true); } else //-- 1st try failed Delay before second try incase target was moving { delay(250); //-- delay 1/4 second for target move SECONDTRY_cnt++; Serial.print("- FAIL Try 1 ----" ); old_TRANStime = millis(); if ( radio.sendWithRetry(RCVR, (const void*)(&theData), sizeof(theData), 6 ) ) { new_TRANStime = millis(); return(true); } else { ERR_cnt++; new_TRANStime = millis(); Serial.print("- FAIL Try 2 ---- " ); } } return(false); // if it fell down to here target didn't respond } ---------------------------------- Receiver -------------------------------- void loop() { new_buttonTIME = millis(); if (new_buttonTIME-old_buttonTIME > max_idleTIME) gotoSLEEP(); dataSTREAMgood = false; if (radio.receiveDone()) { CMD_cnt++; theData = *(Payload*)radio.DATA; theNodeID = radio.SENDERID; SENDERid = theData.sndr_NODEid; if ( (radio.DATALEN = sizeof(Payload)) && ( theNodeID = SENDERid ) ) { radio.sendACK(); COMMANDcode = theData.COMMANDid; DELAYtime = theData.DELAYid ; SENDERid = theData.sndr_NODEid ; CUR_PACKETid = theData.PACKETid; dataSTREAMgood = true; old_buttonTIME = millis(); outputVARS(); strobeLIGHT(OT_LED1, 1, 10); } else { Serial.print("Invalid payload received, not matching Payload struct!"); outputVARS(); } } }