I can only comment on how my mote examples are sleeping.
This is found in the MotionMote example (https://github.com/LowPowerLab/RFM69/blob/master/Examples/MotionMote/MotionMote.ino).
Look for this line:
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Got it!
Code is using:
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); //sleep duration is 8 seconds multiply by the sleep cycle variable.
Cheers, Felix - it's easy when you know what to look for :)
I have a couple of R4's lying around and was looking to do something similar but just with a temperature sensor for now (I have used a TMP36). Came across your project and was extremely pleased as it was everything I wanted to do and more - so thank you Dickson.
I now have the setup all done, the node and gateway all connected - but there is no data coming into the gateway. I can see the node is sending data - doesn't seem to be a problem there. For reference I have included the sketches for both the Node and the Gateway. Any help hugely appreciated - thanks.
NODE SKETCH
-----------------
#include <LowPower.h> // low power library. Get Felix's version: https://github.com/LowPowerLab/LowPower
#include <RFM69.h> // RFM69 library. Get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <avr/sleep.h> // sleep library
#include <stdlib.h> // library for maths
// For temperature
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
// RADIO SETTINGS
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
#define NODEID 23 // The ID of this node. Has to be unique. 1 is reserved for the gateway!
#define NETWORKID 20 //the network ID we are on
#define GATEWAYID 1 //the gateway Moteino ID (default is 1)
#define ACK_TIME 2800 // # of ms to wait for an ack
#define FREQUENCY RF69_433MHZ
RFM69 radio;
bool requestACK=true;
// Power Management Sleep cycles
int sleepCycledefault = 1; // Sleep cycle 450*8 seconds = 1 hour. DEFAULT 450
String senseDATA; // sensor data STRING
//TMP36 Pin Variables
int tempPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
void setup(void)
{
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
// Initialize the radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
}
void loop()
{
int sleepCYCLE = sleepCycledefault; // Sleep cycle reset
// read temperature
tempReading = analogRead(tempPin);
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
// PREPARE READINGS FOR TRANSMISSION
char VoltagebufTemp[10];
char voltagebufvolts[10];
senseDATA = String(NODEID);
senseDATA += ":";
senseDATA += "0"; //ErrorLvl;
senseDATA += ":";
senseDATA += "0"; //String(moistREADavg);
senseDATA += ":";
senseDATA += dtostrf(temperatureC,5,2,VoltagebufTemp); // convert float Temperature to string
senseDATA += ":";
senseDATA += "0"; //String(dhthumid);
senseDATA += ":";
senseDATA += dtostrf(voltage,4,2,voltagebufvolts);
byte sendSize = senseDATA.length();
sendSize = sendSize + 1;
char sendBuf[sendSize];
senseDATA.toCharArray(sendBuf, sendSize); // convert string to char array for transmission
Serial.print(sendBuf);
Serial.print(sendSize);
//Transmit the data
radio.send(GATEWAYID, sendBuf, sendSize, requestACK); // send the data
if (requestACK)
{
//wait for ack
if (waitForAck()) {
//ack recieved
} else {
//ack not recieved
sleepCYCLE = sleepCYCLE / 2; // since we didnt recieve ack, halve sleep cycle
}
}
// Randomize sleep cycle a little to prevent collisions with other nodes
sleepCYCLE = sleepCYCLE + random(8);
// POWER MANAGEMENT DEEP SLEEP
// after everything is done, go into deep sleep to save power
for ( int sleepTIME = 0; sleepTIME < sleepCYCLE; sleepTIME++ ) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //sleep duration is 8 seconds multiply by the sleep cycle variable.
}
}
// Radio ACK recieve/send function
// wait a few milliseconds for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(GATEWAYID))
return true;
return false;
}
GATEWAY SKETCH
---------------------
#include <LowPower.h> // low power library. Get Felix's version: https://github.com/LowPowerLab/LowPower
#include <RFM69.h> // RFM69 library. Get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <avr/sleep.h> // sleep library
#include <stdlib.h> // library for maths
#define NODEID 1 // Node ID used for this unit. 1 is reserved for gateway
#define NETWORKID 20 //the network ID we are on
#define FREQUENCY RF69_433MHZ
RFM69 radio;
#define SERIAL_BAUD 115200 // define serial port speed
void setup() {
Serial.print("Starting..."); //debugging
Serial.println(); //debugging
// open serial port
Serial.begin(SERIAL_BAUD);
Serial.print("Port is open"); //debugging
Serial.println(); //debugging
// Initialize the radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
Serial.print("RFM69HW true"); //debugging
#endif
}
void loop() {
int datalen;
char charbuf;
if (radio.receiveDone()) // radio finishes recieving data
{
Serial.print("Something received..."); //debugging
// get length
for (byte i = 0; i < radio.DATALEN; i++)
// dumps data to the serial port
Serial.print((char)radio.DATA[i]);
Serial.println();
// sends ack to sensor node
if (radio.ACKRequested())
{
radio.sendACK();
Serial.print(" - ACK sent"); //debugging
}
}
Serial.print("Waiting..."); //debugging
Serial.println(); //debugging
}