diff --git a/libraries/MySensors/examples/HeatpumpIRController/HeatpumpIRController.ino b/libraries/MySensors/examples/HeatpumpIRController/HeatpumpIRController.ino index 79e153f..33a68c2 100644 --- a/libraries/MySensors/examples/HeatpumpIRController/HeatpumpIRController.ino +++ b/libraries/MySensors/examples/HeatpumpIRController/HeatpumpIRController.ino @@ -1,6 +1,38 @@ -#include +/** + * 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 + * 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. + * + ******************************* + * + * REVISION HISTORY + * Version 1.0 - Toni A - https://github.com/ToniA/arduino-heatpumpir + * + * DESCRIPTION + * Heatpump controller + */ -// HeatpumpIR libraries, https://github.com/ToniA/arduino-heatpumpir +// Enable debug prints to serial monitor +#define MY_DEBUG + +// Enable and select radio type attached +#define MY_RADIO_NRF24 +//#define MY_RADIO_RFM69 + +// HeatpumpIR libraries, #include #include #include @@ -13,14 +45,13 @@ #include // MySensors libraries -#include #include +#include // Child ID's of this node #define CHILD_1 1 // MySensors definitions -MySensor gw; MyMessage irMsg(CHILD_1, V_IR_RECEIVE); // -- Hacks for Domoticz start @@ -54,6 +85,7 @@ int8_t panasonicCKPTimer = 0; // Number of supported models byte models = 0; + void setup() { Serial.begin(115200); @@ -63,33 +95,31 @@ void setup() models = sizeof(heatpumpIR) / sizeof(HeatpumpIR*); Serial.print(F("Number of supported models: ")); Serial.println(models); - // Auto-assign the node ID, do not forward messages - gw.begin(incomingMessage, AUTO, false); - - // Send the sketch version information to the gateway and Controller - gw.sendSketchInfo("Heatpump Sensor", "1.0"); - - // Register a sensors to the MySensors Gateway - gw.present(CHILD_1, S_IR, "IR sender"); - - // -- Hacks for Domoticz start - gw.present(CHILD_2, S_INFO, "IR data"); - gw.present(CHILD_3, S_LIGHT, "IR send"); // The TEXT sensor is not created in Domoticz before data is sent - gw.send(textMsg.setSensor(CHILD_2).set("00000000")); + send(textMsg.setSensor(CHILD_2).set("00000000")); // -- Hacks for Domoticz end } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Heatpump Sensor", "1.0"); + + // Register a sensors to the MySensors Gateway + present(CHILD_1, S_IR, "IR sender"); + + // -- Hacks for Domoticz start + present(CHILD_2, S_INFO, "IR data"); + present(CHILD_3, S_LIGHT, "IR send"); +} void loop() { - gw.process(); timer.update(); } // Handle incoming messages from the MySensors Gateway -void incomingMessage(const MyMessage &message) { +void receive(const MyMessage &message) { const char *irData; @@ -105,7 +135,7 @@ void incomingMessage(const MyMessage &message) { else if (message.type==V_LIGHT) { // When the button is pressed on Domoticz, request the value of the TEXT sensor Serial.println(F("Requesting IR code from Domoticz...")); - gw.request(CHILD_2, V_TEXT, 0); + request(CHILD_2, V_TEXT, 0); } else if (message.type==V_TEXT) { // TEXT sensor value is received as a result of the previous step Serial.println(F("IR code received from Domoticz...")); @@ -117,7 +147,7 @@ void incomingMessage(const MyMessage &message) { sendHeatpumpIRCommand(irData); // Set the Domoticz switch back to 'OFF' state - gw.send(sendMsg.setSensor(CHILD_3).set(0)); + send(sendMsg.setSensor(CHILD_3).set(0)); } // -- Hacks for Domoticz end } @@ -207,4 +237,4 @@ void panasonicCancelTimer() panasonicCKPHeatpumpIR->sendPanasonicCKPCancelTimer(irSender); Serial.println(F("The TIMER led should now be OFF")); -} \ No newline at end of file +}