Serial flush in sleep method also means one less code in examples. Removed set(bool) in message. Not needed. getBool just calls getInt __attribute__((packed)) for RPI compability Print more info in send/read debug prints. Get internalTemp returns full degrees and uses longer Vref delay Fix debug print gateway prepend (wrong command/type) Fixed problem in RelayWithButton example. Now working with ack in both directions. Serial protocol changed (incoming serial message have an new ack-parameter)
56 lines
1.1 KiB
Arduino
56 lines
1.1 KiB
Arduino
|
|
// Example sketch showing how to request time from controller
|
|
|
|
#include <SPI.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);
|
|
}
|
|
|
|
|