latest test sketches and working request for id

This commit is contained in:
Henrik Ekblad
2014-05-19 20:08:12 +02:00
parent 9e043f3379
commit 67f4ca1fb4
9 changed files with 129 additions and 112 deletions
@@ -1,20 +1,22 @@
#include <MySensor.h>
#include <Sleep_n0m1.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Sensor.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID 0 // Id of the sensor child
#define CHILD_ID 1 // Id of the sensor child
Sensor gw;
MySensor gw;
Sleep sleep;
// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
EEPROM.write(EEPROM_RELAY_ID_ADDRESS, 0);
//eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, 1);
//eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, 255);
//delay(2000);
gw.begin();
// Send the sketch version information to the gateway and Controller
@@ -22,7 +24,10 @@ void setup()
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
// Register all sensors to gw (they will be created as child devices)
gw.sendSensorPresentation(CHILD_ID, S_MOTION);
delay(500);
gw.present(CHILD_ID, S_MOTION);
delay(1000);
}
void loop()
@@ -31,7 +36,7 @@ void loop()
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.println(tripped);
gw.sendVariable(CHILD_ID, V_TRIPPED, tripped?"1":"0"); // Send tripped value to gw
gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.