* Converted time example. Callback for time request was the only clean solution. Now global callback for incoming messages only needs to care about SET commands coming from other nodes or gateway.

* New api for storing states. RelayActator now stores state in eeprom, making it more standalone.
* Controller config is now fetched in the background without needing any special tratment in sketch. Last received config is stored in eeprom:
This commit is contained in:
Henrik Ekblad
2014-05-16 14:48:18 +02:00
parent 9291a97d45
commit 891c826a0c
7 changed files with 270 additions and 256 deletions
@@ -0,0 +1,56 @@
// Example sketch showing how to request time from controller
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#include <Time.h>
MySensor gw;
boolean timeReceived = false;
void setup()
{
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Clock", "1.0");
// Request time from controller.
gw.requestTime(receiveTime);
}
// This is called when a new time value was received
void receiveTime(unsigned long time) {
// Ok, set incoming time
setTime(time);
timeReceived = true;
}
void loop()
{
gw.process();
// Print time
if (timeReceived) {
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}