Last active
January 18, 2017 14:35
-
-
Save nobodyguy/d5c876a93e85d9a4a61829903d08fece to your computer and use it in GitHub Desktop.
RFM69CW basic sleeping node - reports static payload every 1 minute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//********************************************************************************************* | |
// Sample RFM69 sender/node sketch, with ACK and optional encryption, and Automatic Transmission Control | |
// Sends periodic static messages to gateway (id=1) | |
//********************************************************************************************* | |
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 | |
#include <RFM69_ATC.h> //get it here: https://www.github.com/lowpowerlab/rfm69 | |
#include <SPI.h> //included with Arduino IDE install (www.arduino.cc) | |
#include "LowPower.h" | |
//********************************************************************************************* | |
//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************ | |
//********************************************************************************************* | |
#define NODEID 2 //must be unique for each node on same network (range up to 254, 255 is used for broadcast) | |
#define NETWORKID 100 //the same on all nodes that talk to each other (range up to 255) | |
#define GATEWAYID 1 | |
//Match frequency to the hardware version of the radio on your Moteino (uncomment one): | |
#define FREQUENCY RF69_433MHZ | |
//#define FREQUENCY RF69_868MHZ | |
//#define FREQUENCY RF69_915MHZ | |
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes! | |
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W! | |
//********************************************************************************************* | |
//Auto Transmission Control - dials down transmit power to save battery | |
//Usually you do not need to always transmit at max output power | |
//By reducing TX power even a little you save a significant amount of battery power | |
//This setting enables this gateway to work with remote nodes that have ATC enabled to | |
//dial their power down to only the required level (ATC_RSSI) | |
#define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL | |
#define ATC_RSSI -80 | |
//********************************************************************************************* | |
char payload[] = "123 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
byte sendSize= strlen(payload); | |
#ifdef ENABLE_ATC | |
RFM69_ATC radio; | |
#else | |
RFM69 radio; | |
#endif | |
void setup() { | |
radio.initialize(FREQUENCY,NODEID,NETWORKID); | |
radio.encrypt(ENCRYPTKEY); | |
//Auto Transmission Control - dials down transmit power to save battery (-100 is the noise floor, -90 is still pretty good) | |
//For indoor nodes that are pretty static and at pretty stable temperatures (like a MotionMote) -90dBm is quite safe | |
//For more variable nodes that can expect to move or experience larger temp drifts a lower margin like -70 to -80 would probably be better | |
//Always test your ATC mote in the edge cases in your own environment to ensure ATC will perform as you expect | |
#ifdef ENABLE_ATC | |
radio.enableAutoPower(ATC_RSSI); | |
#endif | |
radio.sleep(); | |
} | |
void loop() { | |
radio.sendWithRetry(GATEWAYID, payload, sendSize); | |
radio.sleep(); | |
sleep(1); | |
} | |
void sleep(int minutes) | |
{ | |
int iterations = (minutes * 60) / 8; | |
if (((minutes * 60) % 8) == 4) | |
{ | |
// Enter power down state for 4s with ADC and BOD module disabled | |
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); | |
} | |
for (int i = 0; i < iterations; i++) | |
{ | |
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment