MySensors 1.5.1
Controller: Domoticz
I'm using a simpel test sensor with the "blinking led's" to find "dead zones" in my house. The "blinking led's" are a big help for this and works flawlessly all the time.
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*/
#include <SPI.h>
#include <MySensor.h>
#define CHILD_ID_BUTTON 0 //pushbutton attached to interrupt 0 (= pin 2).
#define CHILD_ID_LED 1 //LED that is switch on/off by the controller (Domoticz).
MySensor gw;
MyMessage msg(CHILD_ID_LED, V_LIGHT);
MyMessage msg2(CHILD_ID_BUTTON, V_STATUS);
byte firstTime = 1; //make sure that the mcu is going to sleep for the first time (no loop)
void setup() {
gw.begin(incomingMessage);
gw.sendSketchInfo("Test sensor","1.0");
gw.present(CHILD_ID_LED, S_LIGHT);
gw.present(CHILD_ID_BUTTON, S_BINARY);
pinMode(2, INPUT_PULLUP); //interrupt = 0;
pinMode(7, OUTPUT); //LED is attached to pin 7
digitalWrite(7, LOW); //make sure that the LED is off
}
void loop() {
if(firstTime == 0) {
gw.process();
gw.send(msg2.set(1)); // send to controller a message that the button has been pushed. The controller then swithes the LED on (incomingMessage)
gw.wait(2000);
if(digitalRead(7) == HIGH) digitalWrite(7, LOW); // switch the LED off after 2 seconds
gw.send(msg.set(0)); // let the controller know that the mcu has switched off the LED
gw.wait(2000);
}
firstTime = 0;
gw.sleep(0,FALLING); // go to sleep and wait for the next button push
}
void incomingMessage(const MyMessage &message) {
if (message.type == V_LIGHT) {
if (message.getInt() == 1) digitalWrite(7, HIGH);
}
}