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
@@ -17,7 +17,8 @@ float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
boolean receivedConfig = false;
boolean metric = true;
MyMessage out;
// Initialize temperature message
MyMessage msg(0,V_TEMP);
void setup()
{
@@ -37,9 +38,6 @@ void setup()
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.present(i, S_TEMP);
}
// Initialize outgoing message to always send temperature
out.type = V_TEMP;
}
@@ -61,7 +59,7 @@ void loop()
if (lastTemperature[i] != temperature && temperature != -127.00) {
// Send in the new temperature
gw.send(out.setSensor(i)->set(temperature,1));
gw.send(msg.setSensor(i)->set(temperature,1));
lastTemperature[i]=temperature;
}
}
@@ -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.
@@ -16,7 +16,7 @@ MySensor gw;
void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, false);
gw.begin(incomingMessage, AUTO, true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Relay", "1.0");
@@ -42,10 +42,9 @@ void incomingMessage(MyMessage message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor, message.getBool()?RELAY_ON:RELAY_OFF);
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);