From 89e3c4f0ef1830f07dd7fa92d7fc8c7318b16475 Mon Sep 17 00:00:00 2001 From: Bruce Lacey Date: Fri, 7 Mar 2014 09:05:25 -0800 Subject: [PATCH] Sensor nodes can now report their sketch name and version to the gateway for informational purposes. Added class methods sendSketchName(), sendSketchVersion() and sendSketchInfo() that invokes the aforementioned as a convenience method. Sensor nodes report their sketch information to the gateway by calling sendSketchInfo(const char *name, const char *version) in the Arduino sketch setup() method after initializing the radio by invoking the Sensor::begin() method. --- libraries/MySensors/Sensor.cpp | 17 +++++++++++++- libraries/MySensors/Sensor.h | 22 +++++++++++++++++-- .../HumiditySensor/HumiditySensor.ino | 3 +++ .../examples/RelayingNode/RelayingNode.ino | 3 +++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/Sensor.cpp b/libraries/MySensors/Sensor.cpp index 69c1b85..2908105 100644 --- a/libraries/MySensors/Sensor.cpp +++ b/libraries/MySensors/Sensor.cpp @@ -1,4 +1,4 @@ -/* + /* The Sensor Net Arduino library adds a new layer on top of the RF24 library. It handles radio network routing, relaying and ids. @@ -335,6 +335,21 @@ void Sensor::requestStatus(uint8_t nodeId, int8_t childId, uint8_t variableType) sendData(radioId, nodeId, childId, M_REQ_VARIABLE, variableType, "", 0, false); } +void Sensor::sendSketchInfo(const char *name, const char *version) { + sendSketchName(name); + sendSketchVersion(version); +} + +void Sensor::sendSketchName(const char *name) { + if (name != NULL) + sendInternal(I_SKETCH_NAME, name); +} + +void Sensor::sendSketchVersion(const char *version) { + if (version != NULL) + sendInternal(I_SKETCH_VERSION, version); +} + void Sensor::sendBatteryLevel(int value) { sendInternal(I_BATTERY_LEVEL, ltoa(value, convBuffer, 10)); } diff --git a/libraries/MySensors/Sensor.h b/libraries/MySensors/Sensor.h index 2b46208..b8cc4a4 100644 --- a/libraries/MySensors/Sensor.h +++ b/libraries/MySensors/Sensor.h @@ -22,7 +22,7 @@ #include #include -//#define DEBUG +#define DEBUG #ifdef DEBUG #define debug(x,...) debugPrint(x, ##__VA_ARGS__) @@ -80,7 +80,7 @@ typedef enum { typedef enum { I_BATTERY_LEVEL, I_BATTERY_DATE, I_LAST_TRIP, I_TIME, I_VERSION, I_REQUEST_ID, I_INCLUSION_MODE, I_RELAY_NODE, I_LAST_UPDATE, I_PING, I_PING_ACK, - I_LOG_MESSAGE, I_CHILDREN, I_UNIT + I_LOG_MESSAGE, I_CHILDREN, I_UNIT, I_SKETCH_NAME, I_SKETCH_VERSION } internalMessageType; // Sensor types @@ -176,6 +176,24 @@ class Sensor : public RF24 void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, unsigned int value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, int value); + /** + * Sends sketch info to sensor net gateway for this radio node. + * @param name String containing a short Sketch name + * @param version String containing a short Sketch version + */ + void sendSketchInfo(const char *name, const char *version); + + /** + * Sends sketch name to sensor net gateway for this radio node. + * @param info String containing a short Sketch name and version + */ + void sendSketchName(const char *name); + + /** + * Sends sketch version to sensor net gateway for this radio node. + * @param info String containing a short Sketch name and version + */ + void sendSketchVersion(const char *version); /** * Sends battery status to sensor net gateway for this radio node. diff --git a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino index 0021073..aabdc04 100644 --- a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino +++ b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino @@ -22,6 +22,9 @@ void setup() gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); + // Send the Sketch Version Information to the Gateway + gw.sendSketchInfo("Humidity", "1.0") + // Register all sensors to gw (they will be created as child devices) gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM); gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP); diff --git a/libraries/MySensors/examples/RelayingNode/RelayingNode.ino b/libraries/MySensors/examples/RelayingNode/RelayingNode.ino index 9c2e8ac..d82c297 100644 --- a/libraries/MySensors/examples/RelayingNode/RelayingNode.ino +++ b/libraries/MySensors/examples/RelayingNode/RelayingNode.ino @@ -14,6 +14,9 @@ Relay gw; void setup() { gw.begin(); + + //Send the sensor node sketch version information to the gateway + gw.sendSketchInfo("RelayingNode", "1.2"); } void loop()