Allow sensors to re-present themselves on request from controller. All

presentations actions moved to their own function in the examples.
This commit is contained in:
Henrik Ekblad
2015-09-27 18:04:05 +02:00
parent aa22a3eaec
commit 415aa29b34
49 changed files with 281 additions and 169 deletions
+2
View File
@@ -28,6 +28,7 @@
#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(ARDUINO_ARCH_ESP8266)
#define MY_GATEWAY_FEATURE
#define MY_IS_GATEWAY (true)
#define MY_NODE_TYPE "gateway"
#elif defined(MY_REPEATER_FEATURE)
#define MY_NODE_TYPE "repeater"
@@ -237,6 +238,7 @@ int main(void) {
#endif
_begin(); // Startup MySensors library
if (setup) setup(); // Call sketch setup
for(;;) {
_process(); // Process incoming data
if (loop) loop(); // Call sketch loop
+1 -1
View File
@@ -151,7 +151,7 @@ typedef enum {
I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE,
I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION,
I_REBOOT, I_GATEWAY_READY, I_REQUEST_SIGNING, I_GET_NONCE, I_GET_NONCE_RESPONSE,
I_HEARTBEAT
I_HEARTBEAT, I_PRESENTATION
} mysensor_internal;
+14 -1
View File
@@ -146,7 +146,7 @@ void _begin() {
#endif
#if defined(MY_RADIO_FEATURE)
transportSetupNode();
transportPresentNode();
#endif
debug(PSTR("%s started, id=%d, parent=%d, distance=%d\n"), MY_NODE_TYPE, _nc.nodeId, _nc.parentNodeId, _nc.distance);
@@ -231,6 +231,19 @@ void _processInternalMessages() {
isMetric = _msg.getString()[0] == 'M' ;
_cc.isMetric = isMetric;
hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
} else if (type == I_PRESENTATION) {
// Re-send node presentation to controller
transportPresentNode();
} else if (type == I_HEARTBEAT) {
if (!mGetAck(_msg)) {
// Send heartbeat ack message back to sender (with the same payload)
_msgTmp = _msg;
mSetRequestAck(_msgTmp,false); // Reply without ack flag (otherwise we would end up in an eternal loop)
mSetAck(_msgTmp,true);
_msgTmp.sender = _nc.nodeId;
_msgTmp.destination = _msg.sender;
_sendRoute(_msgTmp);
}
} else if (type == I_TIME && receiveTime) {
// Deliver time to callback
receiveTime(_msg.getULong());
-2
View File
@@ -170,8 +170,6 @@ void saveState(uint8_t pos, uint8_t value);
*/
uint8_t loadState(uint8_t pos);
/**
* Wait for a specified amount of time to pass. Keeps process()ing.
* This does not power-down the radio nor the Arduino.
+13 -7
View File
@@ -81,11 +81,15 @@ inline void transportProcess() {
// Before processing message, reject unsigned messages if signing is required and check signature (if it is signed and addressed to us)
// Note that we do not care at all about any signature found if we do not require signing, nor do we care about ACKs (they are never signed)
#ifdef MY_SIGNING_REQUEST_SIGNATURES
if (_msg.destination == _nc.nodeId && mGetLength(_msg) && !mGetAck(_msg) &&
(mGetCommand(_msg) != C_INTERNAL ||
(_msg.type != I_GET_NONCE_RESPONSE && _msg.type != I_GET_NONCE && _msg.type != I_REQUEST_SIGNING &&
_msg.type != I_ID_REQUEST && _msg.type != I_ID_RESPONSE &&
_msg.type != I_FIND_PARENT && _msg.type != I_FIND_PARENT_RESPONSE))) {
if ((!MY_IS_GATEWAY || DO_SIGN(msg.sender)) &&
msg.destination == nc.nodeId &&
mGetLength(msg) &&
!mGetAck(msg) &&
(mGetCommand(msg) != C_INTERNAL ||
(msg.type != I_GET_NONCE_RESPONSE && msg.type != I_GET_NONCE && msg.type != I_REQUEST_SIGNING &&
msg.type != I_ID_REQUEST && msg.type != I_ID_RESPONSE &&
msg.type != I_FIND_PARENT && msg.type != I_FIND_PARENT_RESPONSE))) {
if (!mGetSigned(_msg)) {
// Got unsigned message that should have been signed
debug(PSTR("no sign\n"));
@@ -207,7 +211,7 @@ inline void transportProcess() {
debug(PSTR("full\n"));
while (1); // Wait here. Nothing else we can do...
}
transportSetupNode();
transportPresentNode();
// Write id to EEPROM
hwWriteConfig(EEPROM_NODE_ID_ADDRESS, _nc.nodeId);
debug(PSTR("id=%d\n"), _nc.nodeId);
@@ -487,7 +491,7 @@ void transportRequestNodeId() {
wait(2000);
}
void transportSetupNode() {
void transportPresentNode() {
// Open reading pipe for messages directed to this node (set write pipe to same)
transportSetAddress(_nc.nodeId);
// Present node and request config
@@ -532,6 +536,8 @@ void transportSetupNode() {
#endif
}
#endif
if (presentation)
presentation();
}
void transportFindParentNode() {
+1 -1
View File
@@ -92,7 +92,7 @@ typedef struct {
void transportProcess();
void transportRequestNodeId();
void transportSetupNode();
void transportPresentNode();
void transportFindParentNode();
boolean transportSendRoute(MyMessage &message);
boolean transportSendWrite(uint8_t to, MyMessage &message);
@@ -83,17 +83,17 @@ float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from
MyMessage msg(CHILD_ID_MQ, V_LEVEL);
void setup()
{
Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Air Quality Sensor", "1.0");
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_MQ, S_AIR_QUALITY);
Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air
//when you perform the calibration
}
void loop()
@@ -50,7 +50,9 @@ void setup()
#else
analogReference(INTERNAL);
#endif
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Battery Meter", "1.0");
}
@@ -57,6 +57,9 @@ void setup()
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
@@ -76,7 +76,9 @@ void setup()
// Activate internal pull-ups
digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
@@ -60,17 +60,16 @@ MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX);
void setup()
{
pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0");
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_AIQ, S_AIR_QUALITY);
send(msg2.set("ppm"));
sleep(SLEEP_TIME);
pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT);
}
void loop() {
@@ -56,7 +56,9 @@ void setup()
sensors.begin();
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Temperature Sensor", "1.1");
@@ -69,7 +71,6 @@ void setup()
}
}
void loop()
{
// Fetch temperatures from Dallas sensors
@@ -60,12 +60,15 @@ MyMessage lightMsg(0, V_LIGHT);
*/
void setup()
{
// Pull the gateway's current dim level - restore light level upon sendor node power-up
request( 0, V_DIMMER );
}
void presentation() {
// Register the LED Dimmable Light with the gateway
present( 0, S_DIMMER );
sendSketchInfo(SN, SV);
// Pull the gateway's current dim level - restore light level upon sendor node power-up
request( 0, V_DIMMER );
}
/***
@@ -57,11 +57,6 @@ MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
void setup()
{
// Send the Sketch Version Information to the Gateway
sendSketchInfo(SN, SV);
present(CHILD_ID_LIGHT, S_DIMMER );
//Retreive our last light state from the eprom
int LightState=loadState(EPROM_LIGHT_STATE);
if (LightState<=1) {
@@ -79,6 +74,13 @@ void setup()
Serial.println( "Node ready to receive messages..." );
}
void presentation() {
// Send the Sketch Version Information to the Gateway
sendSketchInfo(SN, SV);
present(CHILD_ID_LIGHT, S_DIMMER );
}
void loop()
{
}
@@ -95,10 +95,6 @@ void setup()
// Set analog led pin to off
analogWrite( LED_PIN, 0);
// Send the Sketch Version Information to the Gateway
present(CHILD_ID_LIGHT, S_DIMMER);
sendSketchInfo(SN, SV);
// Retreive our last dim levels from the eprom
fadeTo = dimValue = 0;
byte oldLevel = loadLevelState(EEPROM_DIM_LEVEL_LAST);
@@ -109,6 +105,12 @@ void setup()
Serial.println("Ready to receive messages...");
}
void presentation() {
// Send the Sketch Version Information to the Gateway
present(CHILD_ID_LIGHT, S_DIMMER);
sendSketchInfo(SN, SV);
}
void loop()
{
// Check if someone turned the rotary encode
@@ -49,12 +49,15 @@ boolean metric = true;
void setup()
{
metric = getConfig().isMetric;
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Distance Sensor", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_DISTANCE);
metric = getConfig().isMetric;
}
void loop()
@@ -64,8 +64,7 @@ float dustDensity = 0;
MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL);
void setup()
{
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Dust Sensor", "1.1");
@@ -73,8 +72,7 @@ void setup()
present(CHILD_ID_DUST, S_DUST);
}
void loop()
{
void loop() {
uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value
// 0 - 5V mapped to 0 - 1023 integer values
@@ -67,6 +67,11 @@ MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX);
void setup()
{
pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT);
pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Dust Sensor DSM501", "1.4");
@@ -75,9 +80,6 @@ void setup()
send(msgPM10.set("ppm"));
present(CHILD_ID_DUST_PM25, S_DUST);
send(msgPM25.set("ppm"));
pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT);
pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT);
}
void loop()
@@ -67,12 +67,6 @@ MyMessage pcMsg(CHILD_ID,V_VAR1);
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Energy Meter", "1.0");
// Register this device as power sensor
present(CHILD_ID, S_POWER);
// Fetch last known pulse count value from gw
request(CHILD_ID, V_VAR1);
@@ -80,6 +74,13 @@ void setup()
lastSend=millis();
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Energy Meter", "1.0");
// Register this device as power sensor
present(CHILD_ID, S_POWER);
}
void loop()
{
@@ -54,16 +54,20 @@ void setup()
{
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
metric = getConfig().isMetric;
}
void presentation()
{
// Send the Sketch Version Information to the Gateway
sendSketchInfo("Humidity", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
metric = getConfig().isMetric;
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
@@ -57,6 +57,9 @@ void setup()
irrecv.enableIRIn(); // Start the ir receiver
decoder.UseExtnBuf(Buffer);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("IR Sensor", "1.0");
@@ -64,7 +67,6 @@ void setup()
present(CHILD_1, S_LIGHT);
}
void loop()
{
if (irrecv.GetResults(&decoder)) {
@@ -206,11 +206,7 @@ void setup()
lastTimeRun = lastTimeRun | loadState(i + 1); // assemble 4 bytes into an ussigned long epoch timestamp
}
}
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{
present(i, S_LIGHT);
}
DEBUG_PRINTLN(F("Sensor Presentation Complete"));
//
digitalWrite (ledPin, LOW);
@@ -282,6 +278,17 @@ void setup()
}
lcd.clear();
}
void presentation()
{
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
{
present(i, S_LIGHT);
}
}
//
void loop()
{
@@ -63,13 +63,15 @@ uint16_t lastlux;
void setup()
{
lightSensor.begin();
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Light Lux Sensor", "1.0");
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
lightSensor.begin();
}
void loop()
@@ -43,8 +43,8 @@ unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
int lastLightLevel;
void setup()
{
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Light Sensor", "1.0");
@@ -39,14 +39,6 @@ MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1);
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Lightning Sensor", "1.1");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_DISTANCE, S_DISTANCE);
present(CHILD_ID_INTENSITY, S_CUSTOM);
Serial.begin(115200);
Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001");
Serial.println("beginning boot procedure....");
@@ -76,6 +68,15 @@ void setup()
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Lightning Sensor", "1.1");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_DISTANCE, S_DISTANCE);
present(CHILD_ID_INTENSITY, S_CUSTOM);
}
void loop()
{
@@ -60,8 +60,7 @@ MyMessage msg(0, V_TEMP);
MAX6675 temp0(CS0, SO, SCLK, units);
void setup()
{
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Max6675 Temp Sensor", "1.0");
@@ -335,7 +335,9 @@ void setup()
wait(LONG_WAIT);
Serial.println("GW Started");
}
void presentation() {
// Send the Sketch Version Information to the Gateway
Serial.print("Send Sketch Info: ");
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
@@ -46,13 +46,15 @@ MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Motion Sensor", "1.0");
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)
present(CHILD_ID, S_MOTION);
}
void loop()
@@ -95,11 +95,14 @@ void setup() {
Serial.println("Starting distance sensor");
pixels.begin(); // This initializes the NeoPixel library.
Serial.println("Neopixels initialized");
}
#ifdef SEND_STATUS_TO_CONTROLLER
void presentation() {
sendSketchInfo("Parking Sensor", "1.0");
present(CHILD_ID, S_DOOR, "Parking Status");
#endif
}
#endif
void loop() {
unsigned long now = millis();
@@ -29,6 +29,9 @@ MyMessage mPing(CHILD, V_VAR1); //Ping message
MyMessage mPong(CHILD, V_VAR2); //Pong message
void setup() {
}
void presentation() {
present(CHILD, S_CUSTOM); //
sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN );
@@ -86,21 +86,23 @@ MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Pressure Sensor", "1.1");
if (!bmp.begin())
{
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
// Register sensors to gw (they will be created as child devices)
present(BARO_CHILD, S_BARO);
present(TEMP_CHILD, S_TEMP);
metric = getConfig().isMetric;
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Pressure Sensor", "1.1");
// Register sensors to gw (they will be created as child devices)
present(BARO_CHILD, S_BARO);
present(TEMP_CHILD, S_TEMP);
}
void loop()
{
float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
@@ -96,12 +96,14 @@ void setup() {
// configure board to read RFID tags
nfc.SAMConfig();
sendSketchInfo("RFID Lock", "1.0");
present(CHILD_ID, S_LOCK);
lockStatus = loadState(0); // Read last lock status from eeprom
setLockState(lockStatus, true); // Now set the last known state and send it to controller
}
void presentation() {
sendSketchInfo("RFID Lock", "1.0");
present(CHILD_ID, S_LOCK);
}
void loop() {
boolean success;
+11 -9
View File
@@ -62,15 +62,6 @@ int isShow;
void setup()
{
// Present sketch (name, version)
sendSketchInfo(SN, SV);
// Register sensors (id, type, description, ack back)
present(RED_PIN, S_DIMMER, "present RED light", false);
present(GREEN_PIN, S_DIMMER, "present GREEN light", false);
present(BLUE_PIN, S_DIMMER, "present BLUE light", false);
present(0, S_LIGHT, "present Show button", false);
// Define pin mode (pin number, type)
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
@@ -114,6 +105,17 @@ void setup()
Serial.println("Ready to receive messages...");
}
void presentation() {
// Present sketch (name, version)
sendSketchInfo(SN, SV);
// Register sensors (id, type, description, ack back)
present(RED_PIN, S_DIMMER, "present RED light", false);
present(GREEN_PIN, S_DIMMER, "present GREEN light", false);
present(BLUE_PIN, S_DIMMER, "present BLUE light", false);
present(0, S_LIGHT, "present Show button", false);
}
void loop()
{
// Run RGB show if is set
@@ -145,14 +145,6 @@ void setup()
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
//
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
wait(DWELL_TIME);
present(CHILD_ID_RAIN_LOG, S_RAIN);
wait(DWELL_TIME);
present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
wait(DWELL_TIME);
DEBUG_PRINTLN(F("Sensor Presentation Complete"));
//
//Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal
//
unsigned long functionTimeout = millis();
@@ -206,17 +198,11 @@ void setup()
//
#ifdef DHT_ON
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_HUM, S_HUM);
wait(DWELL_TIME);
present(CHILD_ID_TEMP, S_TEMP);
wait(DWELL_TIME);
metric = getConfig().isMetric;
wait(DWELL_TIME);
#endif
//
#ifdef LUX_ON
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
wait(DWELL_TIME);
lightSensor.begin();
#endif
@@ -225,6 +211,31 @@ void setup()
transmitRainData();
}
void presentation() {
// Register all sensors to gw (they will be created as child devices)
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
wait(DWELL_TIME);
present(CHILD_ID_RAIN_LOG, S_RAIN);
wait(DWELL_TIME);
present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
wait(DWELL_TIME);
#ifdef DHT_ON
present(CHILD_ID_HUM, S_HUM);
wait(DWELL_TIME);
present(CHILD_ID_TEMP, S_TEMP);
wait(DWELL_TIME);
#endif
#ifdef LUX_ON
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
#endif
DEBUG_PRINTLN(F("Sensor Presentation Complete"));
}
void loop()
{
if (state)
@@ -61,9 +61,6 @@ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("RTC Clock", "1.0");
// the function to get the time from the RTC
setSyncProvider(RTC.get);
@@ -74,6 +71,11 @@ void setup()
lcd.begin(16,2);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("RTC Clock", "1.0");
}
// This is called when a new time value was received
void receiveTime(unsigned long controllerTime) {
// Ok, set incoming time
@@ -44,15 +44,10 @@
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay", "1.0");
// Fetch relay status
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
@@ -60,6 +55,17 @@ void setup()
}
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay", "1.0");
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_LIGHT);
}
}
void loop()
{
@@ -56,10 +56,7 @@ MyMessage msg(CHILD_ID,V_LIGHT);
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay & Button", "1.0");
// Setup the button
// Setup the button
pinMode(BUTTON_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
@@ -68,9 +65,6 @@ void setup()
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_LIGHT);
// Make sure relays are off when starting up
digitalWrite(RELAY_PIN, RELAY_OFF);
// Then set relay pins in output mode
@@ -81,6 +75,13 @@ void setup()
digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay & Button", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_LIGHT);
}
/*
* Example on how to asynchronously check for new messages from gw
@@ -40,7 +40,11 @@
#include <MySensor.h>
void setup()
void setup() {
}
void presentation()
{
//Send the sensor node sketch version information to the gateway
sendSketchInfo("Repeater Node", "1.0");
@@ -98,9 +98,6 @@ void setup() {
pinMode(programButton, INPUT);
digitalWrite(programButton, HIGH); // Enable internal pull up
sendSketchInfo("Secret Knock", "1.0");
present(CHILD_ID, S_LOCK);
readSecretKnock(); // Load the secret knock (if any) from EEPROM.
digitalWrite(lockPin, HIGH); // Unlock the door for a bit when we power up. For system check and to allow a way in if the key is forgotten
@@ -111,6 +108,11 @@ void setup() {
delay(500); // This delay is here because the solenoid lock returning to place can otherwise trigger and inadvertent knock.
}
void presentation() {
sendSketchInfo("Secret Knock", "1.0");
present(CHILD_ID, S_LOCK);
}
void loop() {
// Listen for any knock at all.
@@ -62,7 +62,16 @@
#define LOCK_LOCK 1 // GPIO value to write to lock attached lock
#define LOCK_UNLOCK 0 // GPIO value to write to unlock attached lock
void setup()
void setup() {
for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS;lock++, pin++) {
// Set lock pins in output mode
pinMode(pin, OUTPUT);
// Set lock to last known state (using eeprom storage)
digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK);
}
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Secure Lock", "1.0");
@@ -71,10 +80,6 @@ void setup()
for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS;lock++, pin++) {
// Register all locks to gw (they will be created as child devices)
present(lock, S_LOCK, "SecureActuator", false);
// Then set lock pins in output mode
pinMode(pin, OUTPUT);
// Set lock to last known state (using eeprom storage)
digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK);
}
}
@@ -30,9 +30,10 @@ MyMessage msgCounter(CHILD_ID_COUNTER, V_VAR1);
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LED_STATUS);
}
void presentation() {
sendSketchInfo(SketchName, SketchVersion);
present(CHILD_ID_COUNTER, S_CUSTOM,"Millis()");
}
@@ -162,15 +162,6 @@ void setup() {
Serial.flush();
Serial.println(F(" - Online!"));
sendSketchInfo("Sensebender Micro", RELEASE);
present(CHILD_ID_TEMP,S_TEMP);
present(CHILD_ID_HUM,S_HUM);
#ifdef BATT_SENSOR
present(BATT_SENSOR, S_POWER);
#endif
isMetric = getConfig().isMetric;
Serial.print(F("isMetric: ")); Serial.println(isMetric);
@@ -181,6 +172,17 @@ void setup() {
}
void presentation() {
sendSketchInfo("Sensebender Micro", RELEASE);
present(CHILD_ID_TEMP,S_TEMP);
present(CHILD_ID_HUM,S_HUM);
#ifdef BATT_SENSOR
present(BATT_SENSOR, S_POWER);
#endif
}
/***********************************************
*
@@ -55,15 +55,17 @@ bool attachedServo = false;
void setup()
{
// Request last servo state at startup
request(CHILD_ID, V_DIMMER);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Servo", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_COVER);
// Request last servo state at startup
request(CHILD_ID, V_DIMMER);
}
}
void loop()
{
@@ -95,9 +95,6 @@ values valueOf[NUM_READS]; // Calculated moisture percentages and resista
int i; // Simple index variable
void setup() {
sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
present(CHILD_ID, S_HUM);
// initialize the digital pins as an output.
// Pin 6,7 is for sensor 1
// initialize the digital pin as an output.
@@ -109,6 +106,11 @@ void setup() {
pinMode(7, OUTPUT);
}
void presentation() {
sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
present(CHILD_ID, S_HUM);
}
void loop() {
measure(6,7,1);
@@ -40,13 +40,15 @@ unsigned long lastUpdate=0, lastRequest=0;
void setup()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Clock", "1.0");
// Request time from controller.
requestTime();
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Clock", "1.0");
}
// This is called when a new time value was received
void receiveTime(unsigned long time) {
// Ok, set incoming time
@@ -127,13 +127,15 @@ void setup()
}
myButtons.drawButtons();
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Scene Ctrl", "1.0");
present(CHILD_ID, S_SCENE_CONTROLLER);
// Request time from controller.
requestTime();
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Scene Ctrl", "1.0");
present(CHILD_ID, S_SCENE_CONTROLLER);
}
int lastPressedButton = -1;
@@ -58,8 +58,8 @@ float uvIndex;
float lastUV = -1;
uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170};
void setup()
{
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("UV Sensor", "1.2");
@@ -58,16 +58,17 @@ MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL);
void setup()
{
pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT);
attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected
pinMode(SensorLED, OUTPUT);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("VIBRATION Sensor", "1.0");
// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_VIBRATION, S_VIBRATION);
pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT);
attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected
pinMode(SensorLED, OUTPUT);
}
void loop()
@@ -79,12 +79,6 @@ void setup()
// initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Water Meter", "1.1");
// Register this device as Waterflow sensor
present(CHILD_ID, S_WATER);
pulseCount = oldPulseCount = 0;
// Fetch last known pulse count value from gw
@@ -95,6 +89,13 @@ void setup()
attachInterrupt(SENSOR_INTERRUPT, onPulse, FALLING);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Water Meter", "1.1");
// Register this device as Waterflow sensor
present(CHILD_ID, S_WATER);
}
void loop()
{