diff --git a/NodeManager.cpp b/NodeManager.cpp index 1cc6182d95134812e51de50f34c8542210cba3a7..f255e509aeadb0050362bdbd43d0eb2ebe4dcaf0 100644 --- a/NodeManager.cpp +++ b/NodeManager.cpp @@ -126,6 +126,9 @@ int Sensor::getType() { void Sensor::setDescription(char* value) { _description = value; } +void Sensor::setAck(bool value) { + _ack = value; +} void Sensor::setRetries(int value) { _retries = value; } @@ -173,7 +176,7 @@ void Sensor::presentation() { Serial.print(F(" T=")); Serial.println(_presentation); #endif - present(_child_id, _presentation,_description); + present(_child_id, _presentation,_description,_ack); } // call the sensor-specific implementation of before @@ -283,7 +286,7 @@ void Sensor::_send(MyMessage & message) { Serial.print(F(" F=")); Serial.println(message.getFloat()); #endif - send(message); + send(message,_ack); } } @@ -1447,6 +1450,9 @@ void NodeManager::setInterrupt(int pin, int mode, int pull) { void NodeManager::setSleepBetweenSend(int value) { _sleep_between_send = value; } +void NodeManager::setAck(bool value) { + _ack = value; +} // register a sensor to this manager int NodeManager::registerSensor(int sensor_type, int pin, int child_id) { @@ -1701,22 +1707,10 @@ void NodeManager::presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SKETCH_NAME,SKETCH_VERSION); // present the service as a custom sensor to the controller - #if DEBUG == 1 - Serial.print(F("PRES I=")); - Serial.print(CONFIGURATION_CHILD_ID); - Serial.print(F(", T=")); - Serial.println(S_CUSTOM); - #endif - present(CONFIGURATION_CHILD_ID, S_CUSTOM); + _present(CONFIGURATION_CHILD_ID, S_CUSTOM); #if BATTERY_MANAGER == 1 && BATTERY_SENSOR == 1 - #if DEBUG == 1 - Serial.print(F("PRES I=")); - Serial.print(BATTERY_CHILD_ID); - Serial.print(F(", T=")); - Serial.println(S_MULTIMETER); - #endif // present the battery service - present(BATTERY_CHILD_ID, S_MULTIMETER); + _present(BATTERY_CHILD_ID, S_MULTIMETER); // report battery level _process("BATTERY"); #endif @@ -1832,7 +1826,7 @@ void NodeManager::_send(MyMessage & message) { Serial.print(F(" F=")); Serial.println(message.getFloat()); #endif - send(message); + send(message,_ack); } } @@ -2068,6 +2062,16 @@ void NodeManager::_sleep() { } #endif +// present the service +void NodeManager::_present(int child_id, int type) { + #if DEBUG == 1 + Serial.print(F("PRES I=")); + Serial.print(child_id); + Serial.print(F(", T=")); + Serial.println(type); + #endif + present(child_id,type,"",_ack); +} // return the next available child_id int NodeManager::_getAvailableChildId() { diff --git a/NodeManager.h b/NodeManager.h index c457c4b521ca7f650c5a09dc188cacd912ed5b67..7ef4450485db7046ff44078e3dd64578912b7849 100644 --- a/NodeManager.h +++ b/NodeManager.h @@ -278,6 +278,8 @@ class Sensor { int getType(); // description of the sensor (default: '') void setDescription(char *value); + // set this to true if you want destination node to send ack back to this node (default: false) + void setAck(bool value); // when queried, send the message multiple times (default: 1) void setRetries(int value); // For some sensors, the measurement can be queried multiple times and an average is returned (default: 1) @@ -323,6 +325,7 @@ class Sensor { int _presentation = S_CUSTOM; int _type = V_CUSTOM; char* _description = ""; + bool _ack = false; int _retries = 1; int _samples = 1; int _samples_interval = 0; @@ -781,6 +784,8 @@ class NodeManager { // manually turn the power off void powerOff(); #endif + // set this to true if you want destination node to send ack back to this node (default: false) + void setAck(bool value); // hook into the main sketch functions void before(); void presentation(); @@ -820,8 +825,10 @@ class NodeManager { int _interrupt_2_pull = -1; int _reboot_pin = -1; Sensor* _sensors[255] = {0}; + bool _ack = false; void _process(const char * message); void _sleep(); + void _present(int child_id, int type); int _getAvailableChildId(); int _getInterruptInitialValue(int mode); }; diff --git a/README.md b/README.md index 04dfae1025eb6f2f9b23c637883618f606d0cdcd..e1f53e609fdb1269faf1b956d68ea652626ab924 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,8 @@ Node Manager comes with a reasonable default configuration. If you want/need to // manually turn the power off void powerOff(); #endif + // set this to true if you want destination node to send ack back to this node (default: false) + void setAck(bool value); ~~~ For example @@ -260,6 +262,8 @@ The following methods are available for all the sensors: void setType(int value); // description of the sensor (default: '') void setDescription(char *value); + // set this to true if you want destination node to send ack back to this node (default: false) + void setAck(bool value); // when queried, send the message multiple times (default: 1) void setRetries(int value); // For some sensors, the measurement can be queried multiple times and an average is returned (default: 1)