Skip to content

Feature/Implement C_SET for pulse meters #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: development
Choose a base branch
from
111 changes: 111 additions & 0 deletions examples/WatermeterSensor/WaterMeterSensor.ino
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* 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 <MySensors_NodeManager.h>

/***********************************
* Add your sensors
*/

#include <sensors/SensorWaterMeter.h>
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
2 changes: 1 addition & 1 deletion nodemanager/Child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nodemanager/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion sensors/SensorPowerMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 8 additions & 1 deletion sensors/SensorWaterMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ 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()) {
// 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();
}
Expand Down