From 936d30ed47506d853e4bae8ed8f16b6164625058 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Thu, 25 Apr 2019 21:41:39 +0200 Subject: [PATCH 01/11] New example WaterMeterSensor --- .gitignore | 8 ++ .../WatermeterSensor/WaterMeterSensor.cpp | 122 ++++++++++++++++++ platformio.ini | 20 +++ 3 files changed, 150 insertions(+) create mode 100644 examples/WatermeterSensor/WaterMeterSensor.cpp create mode 100644 platformio.ini diff --git a/.gitignore b/.gitignore index 69afccb7..15683d11 100755 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,11 @@ *.tmp *.part *.rsls + +.pio +.pioenvs +.piolibdeps +.vscode/* +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/examples/WatermeterSensor/WaterMeterSensor.cpp b/examples/WatermeterSensor/WaterMeterSensor.cpp new file mode 100644 index 00000000..091e7152 --- /dev/null +++ b/examples/WatermeterSensor/WaterMeterSensor.cpp @@ -0,0 +1,122 @@ +/* +* 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-2017 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. +*/ + +/************************** +Motion Sensor + +The following sketch can be used to report back to the controller when a motion sensor attached to the board's pin 3 +triggers. In this example, the board will be put to sleep just after startup and will report a heartbeat every hour. +NodeManager will take care of configuring an interrupt associated to the provided pin so automatically wake up when a +motion is detected and report a V_TRIPPED message back. +*/ + + +/********************************** +* MySensors node configuration +*/ + +// General settings +#define SKETCH_NAME "WaterMeterSensor" +#define SKETCH_VERSION "0.1" +#define MY_BAUD_RATE 115200 +#define MY_NODE_ID 99 + +// NRF24 radio settings +#define MY_RADIO_RF24 + +/*********************************** + * NodeManager configuration + */ + +#define NODEMANAGER_DEBUG ON // Default ON +#define NODEMANAGER_INTERRUPTS ON +#define NODEMANAGER_SLEEP OFF // Default ON +#define NODEMANAGER_RECEIVE ON +#define NODEMANAGER_DEBUG_VERBOSE ON +#define NODEMANAGER_POWER_MANAGER OFF +#define NODEMANAGER_CONDITIONAL_REPORT OFF +#define NODEMANAGER_EEPROM OFF +#define NODEMANAGER_TIME OFF +#define NODEMANAGER_RTC OFF +#define NODEMANAGER_SD OFF +#define NODEMANAGER_HOOKING OFF +#define NODEMANAGER_OTA_CONFIGURATION OFF +#define NODEMANAGER_SERIAL_INPUT OFF + +// import NodeManager library (a nodeManager object will be then made available) +#include + +/*********************************** + * Add your sensors + */ + +#include +SensorWaterMeter waterMeter(3); + +/*********************************** +* Main Sketch +*/ + +// before +void before() { + +/*********************************** +* Configure your sensors +*/ + + // set reporting interval to 30 seconds. + waterMeter.setReportIntervalSeconds(30); + + // call NodeManager before routine + nodeManager.before(); +} + +// presentation +void presentation() { + // call NodeManager presentation routine + nodeManager.presentation(); +} + +// setup +void setup() { + // call NodeManager setup routine + nodeManager.setup(); +} + +// loop +void loop() { + // call NodeManager loop routine + nodeManager.loop(); +} + +#if NODEMANAGER_RECEIVE == ON +// receive +void receive(const MyMessage &message) { + // call NodeManager receive routine + nodeManager.receive(message); +} +#endif + +#if NODEMANAGER_TIME == ON +// receiveTime +void receiveTime(unsigned long ts) { + // call NodeManager receiveTime routine + nodeManager.receiveTime(ts); +} +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 00000000..1c0aba79 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,20 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + + +[platformio] +src_dir = examples/WatermeterSensor +lib_extra_dirs = P:\software\MySensors\FrameworkDev + +[env:pro8MHzatmega328] +platform = atmelavr +board = pro8MHzatmega328 +framework = arduino +monitor_speed = 115200 \ No newline at end of file From 4397c9f01e6181bb3a20d5ed378d7e258d9030a9 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Fri, 26 Apr 2019 20:46:43 +0200 Subject: [PATCH 02/11] Bugfix for #458 - don't reset efter sending --- .../WatermeterSensor/WaterMeterSensor.ino | 111 ++++++++++++++++++ nodemanager/Child.cpp | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 examples/WatermeterSensor/WaterMeterSensor.ino diff --git a/examples/WatermeterSensor/WaterMeterSensor.ino b/examples/WatermeterSensor/WaterMeterSensor.ino new file mode 100644 index 00000000..e5163e8e --- /dev/null +++ b/examples/WatermeterSensor/WaterMeterSensor.ino @@ -0,0 +1,111 @@ +/* +* 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-2017 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. +*/ + +/************************** +Motion Sensor + +The following sketch can be used to report back to the controller when a motion sensor attached to the board's pin 3 +triggers. In this example, the board will be put to sleep just after startup and will report a heartbeat every hour. +NodeManager will take care of configuring an interrupt associated to the provided pin so automatically wake up when a +motion is detected and report a V_TRIPPED message back. +*/ + + +/********************************** +* MySensors node configuration +*/ + +// General settings +#define SKETCH_NAME "WaterMeterSensor" +#define SKETCH_VERSION "1.0" +#define MY_BAUD_RATE 9600 +#define MY_NODE_ID 99 + +// NRF24 radio settings +#define MY_RADIO_RF24 + +/*********************************** + * NodeManager configuration + */ + +#define NODEMANAGER_SLEEP OFF + +// import NodeManager library (a nodeManager object will be then made available) +#include + +/*********************************** + * Add your sensors + */ + +#include +SensorWaterMeter waterMeter(3); + +/*********************************** +* Main Sketch +*/ + +// before +void before() { + +/*********************************** +* Configure your sensors +*/ + + // set reporting interval to 30 seconds. + waterMeter.setReportIntervalSeconds(30); + // set pulse factor to 1000 pulses per m3 + waterMeter.setPulseFactor(1000); + + // call NodeManager before routine + nodeManager.before(); +} + +// presentation +void presentation() { + // call NodeManager presentation routine + nodeManager.presentation(); +} + +// setup +void setup() { + // call NodeManager setup routine + nodeManager.setup(); +} + +// loop +void loop() { + // call NodeManager loop routine + nodeManager.loop(); +} + +#if NODEMANAGER_RECEIVE == ON +// receive +void receive(const MyMessage &message) { + // call NodeManager receive routine + nodeManager.receive(message); +} +#endif + +#if NODEMANAGER_TIME == ON +// receiveTime +void receiveTime(unsigned long ts) { + // call NodeManager receiveTime routine + nodeManager.receiveTime(ts); +} +#endif \ No newline at end of file diff --git a/nodemanager/Child.cpp b/nodemanager/Child.cpp index aa6c481c..d64474c0 100644 --- a/nodemanager/Child.cpp +++ b/nodemanager/Child.cpp @@ -196,7 +196,7 @@ void Child::sendValue(bool force) { if (_format == DOUBLE) nodeManager.sendMessage(_child_id,_type,_value,_float_precision); if (_format == STRING) nodeManager.sendMessage(_child_id,_type,_value_string); // reset the counters - reset(); + if (_value_processing != SUM) reset(); } // print the child value to a device From 86dfa4689b8830c9a23fcb92708a0fe2cb37dd80 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Fri, 26 Apr 2019 22:02:35 +0200 Subject: [PATCH 03/11] Delete obsolete example version --- .../WatermeterSensor/WaterMeterSensor.cpp | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 examples/WatermeterSensor/WaterMeterSensor.cpp diff --git a/examples/WatermeterSensor/WaterMeterSensor.cpp b/examples/WatermeterSensor/WaterMeterSensor.cpp deleted file mode 100644 index 091e7152..00000000 --- a/examples/WatermeterSensor/WaterMeterSensor.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* -* 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-2017 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. -*/ - -/************************** -Motion Sensor - -The following sketch can be used to report back to the controller when a motion sensor attached to the board's pin 3 -triggers. In this example, the board will be put to sleep just after startup and will report a heartbeat every hour. -NodeManager will take care of configuring an interrupt associated to the provided pin so automatically wake up when a -motion is detected and report a V_TRIPPED message back. -*/ - - -/********************************** -* MySensors node configuration -*/ - -// General settings -#define SKETCH_NAME "WaterMeterSensor" -#define SKETCH_VERSION "0.1" -#define MY_BAUD_RATE 115200 -#define MY_NODE_ID 99 - -// NRF24 radio settings -#define MY_RADIO_RF24 - -/*********************************** - * NodeManager configuration - */ - -#define NODEMANAGER_DEBUG ON // Default ON -#define NODEMANAGER_INTERRUPTS ON -#define NODEMANAGER_SLEEP OFF // Default ON -#define NODEMANAGER_RECEIVE ON -#define NODEMANAGER_DEBUG_VERBOSE ON -#define NODEMANAGER_POWER_MANAGER OFF -#define NODEMANAGER_CONDITIONAL_REPORT OFF -#define NODEMANAGER_EEPROM OFF -#define NODEMANAGER_TIME OFF -#define NODEMANAGER_RTC OFF -#define NODEMANAGER_SD OFF -#define NODEMANAGER_HOOKING OFF -#define NODEMANAGER_OTA_CONFIGURATION OFF -#define NODEMANAGER_SERIAL_INPUT OFF - -// import NodeManager library (a nodeManager object will be then made available) -#include - -/*********************************** - * Add your sensors - */ - -#include -SensorWaterMeter waterMeter(3); - -/*********************************** -* Main Sketch -*/ - -// before -void before() { - -/*********************************** -* Configure your sensors -*/ - - // set reporting interval to 30 seconds. - waterMeter.setReportIntervalSeconds(30); - - // call NodeManager before routine - nodeManager.before(); -} - -// presentation -void presentation() { - // call NodeManager presentation routine - nodeManager.presentation(); -} - -// setup -void setup() { - // call NodeManager setup routine - nodeManager.setup(); -} - -// loop -void loop() { - // call NodeManager loop routine - nodeManager.loop(); -} - -#if NODEMANAGER_RECEIVE == ON -// receive -void receive(const MyMessage &message) { - // call NodeManager receive routine - nodeManager.receive(message); -} -#endif - -#if NODEMANAGER_TIME == ON -// receiveTime -void receiveTime(unsigned long ts) { - // call NodeManager receiveTime routine - nodeManager.receiveTime(ts); -} -#endif \ No newline at end of file From d06c9f5ce50f25251cbc14145b92e747e89a87aa Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Sun, 28 Apr 2019 20:54:46 +0200 Subject: [PATCH 04/11] Use 3 decimals for float debugs in Node.cpp --- nodemanager/Node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodemanager/Node.cpp b/nodemanager/Node.cpp index de62c605..c36744a3 100644 --- a/nodemanager/Node.cpp +++ b/nodemanager/Node.cpp @@ -561,7 +561,7 @@ void NodeManager::loop() { for (int i = 0; i < _retries; i++) { if (mGetPayloadType(_message) == P_INT16) debug_verbose(PSTR(LOG_MSG "SEND(%d) t=%d p=%d\n"),_message.sensor,_message.type,_message.getInt()); if (mGetPayloadType(_message) == P_LONG32) debug_verbose(PSTR(LOG_MSG "SEND(%d) t=%d p=%ld\n"),_message.sensor,_message.type,_message.getLong()); - if (mGetPayloadType(_message) == P_FLOAT32) debug_verbose(PSTR(LOG_MSG "SEND(%d) t=%d p=%d.%02d\n"),_message.sensor,_message.type,(unsigned int)_message.getFloat(), (unsigned int)(_message.getFloat()*100)%100); + if (mGetPayloadType(_message) == P_FLOAT32) debug_verbose(PSTR(LOG_MSG "SEND(%d) t=%d p=%d.%03d\n"),_message.sensor,_message.type,(unsigned int)_message.getFloat(), (unsigned int)(_message.getFloat()*100)%100); if (mGetPayloadType(_message) == P_STRING) debug_verbose(PSTR(LOG_MSG "SEND(%d) t=%d p=%s\n"),_message.sensor,_message.type,_message.getString()); send(_message, _ack); // if configured, sleep between each send From fa0746f9d15ed13088d472187507585701fd2ad2 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Sun, 28 Apr 2019 20:55:55 +0200 Subject: [PATCH 05/11] Add SET command to WaterMeter --- sensors/SensorWaterMeter.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sensors/SensorWaterMeter.h b/sensors/SensorWaterMeter.h index 75529b9a..4dcb38d8 100644 --- a/sensors/SensorWaterMeter.h +++ b/sensors/SensorWaterMeter.h @@ -46,7 +46,13 @@ class SensorWaterMeter: public SensorPulseMeter { void onReceive(MyMessage* message) { Child* child = getChild(message->sensor); if (child == nullptr) return; - if (message->getCommand() == C_REQ && message->type == child->getType()) { + // heandle a SET command + if (message->getCommand() == C_SET && message->type == child->getType()) { + // set the pulse counter to the received value + children.get()->setValue(message->getFloat()); + } + // handle REQ command + if (message->getCommand() == C_REQ && message->type == child->getType()) { // send the accumulated value so far children.get()->sendValue(); } From 8d9904c3d08d759db9c377fc966e72025ce12002 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Sun, 28 Apr 2019 20:57:47 +0200 Subject: [PATCH 06/11] Project settings --- .gitignore | 2 ++ platformio.ini | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 15683d11..b694eb81 100755 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ .pio .pioenvs .piolibdeps + +*.code-workspace .vscode/* .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json diff --git a/platformio.ini b/platformio.ini index 1c0aba79..44353c60 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,4 +17,4 @@ lib_extra_dirs = P:\software\MySensors\FrameworkDev platform = atmelavr board = pro8MHzatmega328 framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 9600 \ No newline at end of file From 060e0e13cf6fffe012a91f3262fedbf34aef5c95 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Sun, 28 Apr 2019 22:19:05 +0200 Subject: [PATCH 07/11] Don't sum received C_SET value --- sensors/SensorWaterMeter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sensors/SensorWaterMeter.h b/sensors/SensorWaterMeter.h index 4dcb38d8..a9de60f5 100644 --- a/sensors/SensorWaterMeter.h +++ b/sensors/SensorWaterMeter.h @@ -49,6 +49,7 @@ class SensorWaterMeter: public SensorPulseMeter { // heandle a SET command if (message->getCommand() == C_SET && message->type == child->getType()) { // set the pulse counter to the received value + children.get()->reset(); children.get()->setValue(message->getFloat()); } // handle REQ command From 5b84e5432512e0ff5d9bbd92040106a1f71911e5 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Mon, 29 Apr 2019 21:16:56 +0200 Subject: [PATCH 08/11] Make PowerMeter and WaterMeter settable --- sensors/SensorPowerMeter.h | 9 ++++++++- sensors/SensorWaterMeter.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sensors/SensorPowerMeter.h b/sensors/SensorPowerMeter.h index fed8c012..1e8bcb48 100644 --- a/sensors/SensorPowerMeter.h +++ b/sensors/SensorPowerMeter.h @@ -46,7 +46,14 @@ class SensorPowerMeter: public SensorPulseMeter { void onReceive(MyMessage* message) { Child* child = getChild(message->sensor); if (child == nullptr) return; - if (message->getCommand() == C_REQ && message->type == child->getType()) { + // handle SET command + if (message->getCommand() == C_SET && message->type == child->getType()) { + // set the pulse counter to the received value + children.get()->reset(); + children.get()->setValue(message->getFloat()); + } + // handle REQ command + if (message->getCommand() == C_REQ && message->type == child->getType()) { // send the accumulated value so far children.get()->sendValue(); } diff --git a/sensors/SensorWaterMeter.h b/sensors/SensorWaterMeter.h index a9de60f5..9e4cba31 100644 --- a/sensors/SensorWaterMeter.h +++ b/sensors/SensorWaterMeter.h @@ -46,7 +46,7 @@ class SensorWaterMeter: public SensorPulseMeter { void onReceive(MyMessage* message) { Child* child = getChild(message->sensor); if (child == nullptr) return; - // heandle a SET command + // handle SET command if (message->getCommand() == C_SET && message->type == child->getType()) { // set the pulse counter to the received value children.get()->reset(); From 551b08b5a368a02928d7d3c4295c855ad771cdfd Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Mon, 29 Apr 2019 22:04:57 +0200 Subject: [PATCH 09/11] Revert changes to .gitignore --- .gitignore | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b694eb81..752e6b86 100755 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,4 @@ *~ *.tmp *.part -*.rsls - -.pio -.pioenvs -.piolibdeps - -*.code-workspace -.vscode/* -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json +*.rsls \ No newline at end of file From e2bae68755696f233073b5580603ae232709d2a9 Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Mon, 29 Apr 2019 22:07:42 +0200 Subject: [PATCH 10/11] Add NL att EOF --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 752e6b86..69afccb7 100755 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ *~ *.tmp *.part -*.rsls \ No newline at end of file +*.rsls From a340f8ca42abedc26898b8bad3bd223d5bcb9c5d Mon Sep 17 00:00:00 2001 From: Fredrik Viklund Date: Tue, 30 Apr 2019 16:36:12 +0200 Subject: [PATCH 11/11] Removed one file from pull request --- platformio.ini | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 platformio.ini diff --git a/platformio.ini b/platformio.ini deleted file mode 100644 index 44353c60..00000000 --- a/platformio.ini +++ /dev/null @@ -1,20 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - - -[platformio] -src_dir = examples/WatermeterSensor -lib_extra_dirs = P:\software\MySensors\FrameworkDev - -[env:pro8MHzatmega328] -platform = atmelavr -board = pro8MHzatmega328 -framework = arduino -monitor_speed = 9600 \ No newline at end of file