From 415aa29b34536739077bb5ecf48987a0764383c9 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Sun, 27 Sep 2015 18:04:05 +0200 Subject: [PATCH] Allow sensors to re-present themselves on request from controller. All presentations actions moved to their own function in the examples. --- libraries/MySensors/MySensor.h | 2 + libraries/MySensors/core/MyMessage.h | 2 +- libraries/MySensors/core/MySensorCore.cpp | 15 ++++++- libraries/MySensors/core/MySensorCore.h | 2 - libraries/MySensors/core/MyTransport.cpp | 20 ++++++---- libraries/MySensors/core/MyTransport.h | 2 +- .../AirQualitySensor/AirQualitySensor.ino | 8 ++-- .../BatteryPoweredSensor.ino | 2 + .../BinarySwitchSensor/BinarySwitchSensor.ino | 3 ++ .../BinarySwitchSleepSensor.ino | 4 +- .../examples/CO2Sensor/CO2Sensor.ino | 9 ++--- .../DallasTemperatureSensor.ino | 3 +- .../DimmableLEDActuator.ino | 7 +++- .../examples/DimmableLight/DimmableLight.ino | 12 +++--- .../DimmableLightWithRotaryEncoderButton.ino | 10 +++-- .../DistanceSensor/DistanceSensor.ino | 5 ++- .../examples/DustSensor/DustSensor.ino | 6 +-- .../examples/DustSensorDSM/DustSensorDSM.ino | 8 ++-- .../EnergyMeterPulseSensor.ino | 13 ++++--- .../HumiditySensor/HumiditySensor.ino | 8 +++- .../MySensors/examples/IrSensor/IrSensor.ino | 4 +- .../IrrigationController.ino | 17 +++++--- .../LightLuxSensor/LightLuxSensor.ino | 6 ++- .../examples/LightSensor/LightSensor.ino | 4 +- .../LightningSensor/LightningSensor.ino | 17 ++++---- .../MAX6875TemperatureSensor.ino | 3 +- .../examples/MockMySensors/MockMySensors.ino | 4 +- .../examples/MotionSensor/MotionSensor.ino | 6 ++- .../examples/ParkingSensor/ParkingSensor.ino | 5 ++- .../PingPongSensor/PingPongSensor.ino | 3 ++ .../PressureSensor/PressureSensor.ino | 16 ++++---- .../RFIDLockSensor/RFIDLockSensor.ino | 8 ++-- .../MySensors/examples/RGB-3D/RGB-3D.ino | 20 +++++----- .../examples/RainGauge/RainGauge.ino | 39 ++++++++++++------- .../RealTimeClockDisplaySensor.ino | 8 ++-- .../examples/RelayActuator/RelayActuator.ino | 18 ++++++--- .../RelayWithButtonActuator.ino | 15 +++---- .../examples/RepeaterNode/RepeaterNode.ino | 6 ++- .../SecretKnockSensor/SecretKnockSensor.ino | 8 ++-- .../SecureActuator/SecureActuator.ino | 15 ++++--- .../SensebenderBlink/SensebenderBlink.ino | 5 ++- .../SensebenderMicro/SensebenderMicro.ino | 20 +++++----- .../examples/ServoActuator/ServoActuator.ino | 10 +++-- .../SoilMoistSensor/SoilMoistSensor.ino | 8 ++-- .../TimeAwareSensor/TimeAwareSensor.ino | 8 ++-- .../TouchDisplaySceneControllerSensor.ino | 8 ++-- .../MySensors/examples/UVSensor/UVSensor.ino | 4 +- .../VibrationSensor/VibrationSensor.ino | 11 +++--- .../WaterMeterPulseSensor.ino | 13 ++++--- 49 files changed, 281 insertions(+), 169 deletions(-) diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 13b848b..98d493e 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -28,6 +28,7 @@ #if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(ARDUINO_ARCH_ESP8266) #define MY_GATEWAY_FEATURE + #define MY_IS_GATEWAY (true) #define MY_NODE_TYPE "gateway" #elif defined(MY_REPEATER_FEATURE) #define MY_NODE_TYPE "repeater" @@ -237,6 +238,7 @@ int main(void) { #endif _begin(); // Startup MySensors library if (setup) setup(); // Call sketch setup + for(;;) { _process(); // Process incoming data if (loop) loop(); // Call sketch loop diff --git a/libraries/MySensors/core/MyMessage.h b/libraries/MySensors/core/MyMessage.h index 5a9fc43..ec94e3a 100644 --- a/libraries/MySensors/core/MyMessage.h +++ b/libraries/MySensors/core/MyMessage.h @@ -151,7 +151,7 @@ typedef enum { I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE, I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION, I_REBOOT, I_GATEWAY_READY, I_REQUEST_SIGNING, I_GET_NONCE, I_GET_NONCE_RESPONSE, - I_HEARTBEAT + I_HEARTBEAT, I_PRESENTATION } mysensor_internal; diff --git a/libraries/MySensors/core/MySensorCore.cpp b/libraries/MySensors/core/MySensorCore.cpp index 86a6933..65e7199 100644 --- a/libraries/MySensors/core/MySensorCore.cpp +++ b/libraries/MySensors/core/MySensorCore.cpp @@ -146,7 +146,7 @@ void _begin() { #endif #if defined(MY_RADIO_FEATURE) - transportSetupNode(); + transportPresentNode(); #endif debug(PSTR("%s started, id=%d, parent=%d, distance=%d\n"), MY_NODE_TYPE, _nc.nodeId, _nc.parentNodeId, _nc.distance); @@ -231,6 +231,19 @@ void _processInternalMessages() { isMetric = _msg.getString()[0] == 'M' ; _cc.isMetric = isMetric; hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric); + } else if (type == I_PRESENTATION) { + // Re-send node presentation to controller + transportPresentNode(); + } else if (type == I_HEARTBEAT) { + if (!mGetAck(_msg)) { + // Send heartbeat ack message back to sender (with the same payload) + _msgTmp = _msg; + mSetRequestAck(_msgTmp,false); // Reply without ack flag (otherwise we would end up in an eternal loop) + mSetAck(_msgTmp,true); + _msgTmp.sender = _nc.nodeId; + _msgTmp.destination = _msg.sender; + _sendRoute(_msgTmp); + } } else if (type == I_TIME && receiveTime) { // Deliver time to callback receiveTime(_msg.getULong()); diff --git a/libraries/MySensors/core/MySensorCore.h b/libraries/MySensors/core/MySensorCore.h index 018ad99..30edd42 100644 --- a/libraries/MySensors/core/MySensorCore.h +++ b/libraries/MySensors/core/MySensorCore.h @@ -170,8 +170,6 @@ void saveState(uint8_t pos, uint8_t value); */ uint8_t loadState(uint8_t pos); - - /** * Wait for a specified amount of time to pass. Keeps process()ing. * This does not power-down the radio nor the Arduino. diff --git a/libraries/MySensors/core/MyTransport.cpp b/libraries/MySensors/core/MyTransport.cpp index 8a93854..f9f19ec 100644 --- a/libraries/MySensors/core/MyTransport.cpp +++ b/libraries/MySensors/core/MyTransport.cpp @@ -81,11 +81,15 @@ inline void transportProcess() { // Before processing message, reject unsigned messages if signing is required and check signature (if it is signed and addressed to us) // Note that we do not care at all about any signature found if we do not require signing, nor do we care about ACKs (they are never signed) #ifdef MY_SIGNING_REQUEST_SIGNATURES - if (_msg.destination == _nc.nodeId && mGetLength(_msg) && !mGetAck(_msg) && - (mGetCommand(_msg) != C_INTERNAL || - (_msg.type != I_GET_NONCE_RESPONSE && _msg.type != I_GET_NONCE && _msg.type != I_REQUEST_SIGNING && - _msg.type != I_ID_REQUEST && _msg.type != I_ID_RESPONSE && - _msg.type != I_FIND_PARENT && _msg.type != I_FIND_PARENT_RESPONSE))) { + + if ((!MY_IS_GATEWAY || DO_SIGN(msg.sender)) && + msg.destination == nc.nodeId && + mGetLength(msg) && + !mGetAck(msg) && + (mGetCommand(msg) != C_INTERNAL || + (msg.type != I_GET_NONCE_RESPONSE && msg.type != I_GET_NONCE && msg.type != I_REQUEST_SIGNING && + msg.type != I_ID_REQUEST && msg.type != I_ID_RESPONSE && + msg.type != I_FIND_PARENT && msg.type != I_FIND_PARENT_RESPONSE))) { if (!mGetSigned(_msg)) { // Got unsigned message that should have been signed debug(PSTR("no sign\n")); @@ -207,7 +211,7 @@ inline void transportProcess() { debug(PSTR("full\n")); while (1); // Wait here. Nothing else we can do... } - transportSetupNode(); + transportPresentNode(); // Write id to EEPROM hwWriteConfig(EEPROM_NODE_ID_ADDRESS, _nc.nodeId); debug(PSTR("id=%d\n"), _nc.nodeId); @@ -487,7 +491,7 @@ void transportRequestNodeId() { wait(2000); } -void transportSetupNode() { +void transportPresentNode() { // Open reading pipe for messages directed to this node (set write pipe to same) transportSetAddress(_nc.nodeId); // Present node and request config @@ -532,6 +536,8 @@ void transportSetupNode() { #endif } #endif + if (presentation) + presentation(); } void transportFindParentNode() { diff --git a/libraries/MySensors/core/MyTransport.h b/libraries/MySensors/core/MyTransport.h index c9b540d..18be525 100644 --- a/libraries/MySensors/core/MyTransport.h +++ b/libraries/MySensors/core/MyTransport.h @@ -92,7 +92,7 @@ typedef struct { void transportProcess(); void transportRequestNodeId(); -void transportSetupNode(); +void transportPresentNode(); void transportFindParentNode(); boolean transportSendRoute(MyMessage &message); boolean transportSendWrite(uint8_t to, MyMessage &message); diff --git a/libraries/MySensors/examples/AirQualitySensor/AirQualitySensor.ino b/libraries/MySensors/examples/AirQualitySensor/AirQualitySensor.ino index 310295c..c0ee3c3 100644 --- a/libraries/MySensors/examples/AirQualitySensor/AirQualitySensor.ino +++ b/libraries/MySensors/examples/AirQualitySensor/AirQualitySensor.ino @@ -83,17 +83,17 @@ float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from MyMessage msg(CHILD_ID_MQ, V_LEVEL); - void setup() { + Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Air Quality Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_MQ, S_AIR_QUALITY); - - Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air - //when you perform the calibration } void loop() diff --git a/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino b/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino index 117d6f6..36a28f1 100644 --- a/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino +++ b/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino @@ -50,7 +50,9 @@ void setup() #else analogReference(INTERNAL); #endif +} +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Battery Meter", "1.0"); } diff --git a/libraries/MySensors/examples/BinarySwitchSensor/BinarySwitchSensor.ino b/libraries/MySensors/examples/BinarySwitchSensor/BinarySwitchSensor.ino index b7a96a3..688541d 100644 --- a/libraries/MySensors/examples/BinarySwitchSensor/BinarySwitchSensor.ino +++ b/libraries/MySensors/examples/BinarySwitchSensor/BinarySwitchSensor.ino @@ -57,6 +57,9 @@ void setup() debouncer.attach(BUTTON_PIN); debouncer.interval(5); +} + +void presentation() { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. diff --git a/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino b/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino index 7a88465..f310138 100644 --- a/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino +++ b/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino @@ -76,7 +76,9 @@ void setup() // Activate internal pull-ups digitalWrite(PRIMARY_BUTTON_PIN, HIGH); digitalWrite(SECONDARY_BUTTON_PIN, HIGH); - +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER); diff --git a/libraries/MySensors/examples/CO2Sensor/CO2Sensor.ino b/libraries/MySensors/examples/CO2Sensor/CO2Sensor.ino index 09d7645..c12a771 100644 --- a/libraries/MySensors/examples/CO2Sensor/CO2Sensor.ino +++ b/libraries/MySensors/examples/CO2Sensor/CO2Sensor.ino @@ -60,17 +60,16 @@ MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX); void setup() { + pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0"); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_AIQ, S_AIR_QUALITY); send(msg2.set("ppm")); - - sleep(SLEEP_TIME); - - pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); - } void loop() { diff --git a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino index 9232249..48dfbbe 100644 --- a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino +++ b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino @@ -56,7 +56,9 @@ void setup() sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); +} +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Temperature Sensor", "1.1"); @@ -69,7 +71,6 @@ void setup() } } - void loop() { // Fetch temperatures from Dallas sensors diff --git a/libraries/MySensors/examples/DimmableLEDActuator/DimmableLEDActuator.ino b/libraries/MySensors/examples/DimmableLEDActuator/DimmableLEDActuator.ino index c88f6dc..190ecc3 100644 --- a/libraries/MySensors/examples/DimmableLEDActuator/DimmableLEDActuator.ino +++ b/libraries/MySensors/examples/DimmableLEDActuator/DimmableLEDActuator.ino @@ -60,12 +60,15 @@ MyMessage lightMsg(0, V_LIGHT); */ void setup() { + // Pull the gateway's current dim level - restore light level upon sendor node power-up + request( 0, V_DIMMER ); +} + +void presentation() { // Register the LED Dimmable Light with the gateway present( 0, S_DIMMER ); sendSketchInfo(SN, SV); - // Pull the gateway's current dim level - restore light level upon sendor node power-up - request( 0, V_DIMMER ); } /*** diff --git a/libraries/MySensors/examples/DimmableLight/DimmableLight.ino b/libraries/MySensors/examples/DimmableLight/DimmableLight.ino index cecebda..0480050 100644 --- a/libraries/MySensors/examples/DimmableLight/DimmableLight.ino +++ b/libraries/MySensors/examples/DimmableLight/DimmableLight.ino @@ -57,11 +57,6 @@ MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER); void setup() { - // Send the Sketch Version Information to the Gateway - sendSketchInfo(SN, SV); - - present(CHILD_ID_LIGHT, S_DIMMER ); - //Retreive our last light state from the eprom int LightState=loadState(EPROM_LIGHT_STATE); if (LightState<=1) { @@ -79,6 +74,13 @@ void setup() Serial.println( "Node ready to receive messages..." ); } +void presentation() { + // Send the Sketch Version Information to the Gateway + sendSketchInfo(SN, SV); + + present(CHILD_ID_LIGHT, S_DIMMER ); +} + void loop() { } diff --git a/libraries/MySensors/examples/DimmableLightWithRotaryEncoderButton/DimmableLightWithRotaryEncoderButton.ino b/libraries/MySensors/examples/DimmableLightWithRotaryEncoderButton/DimmableLightWithRotaryEncoderButton.ino index 330a427..64230f2 100644 --- a/libraries/MySensors/examples/DimmableLightWithRotaryEncoderButton/DimmableLightWithRotaryEncoderButton.ino +++ b/libraries/MySensors/examples/DimmableLightWithRotaryEncoderButton/DimmableLightWithRotaryEncoderButton.ino @@ -95,10 +95,6 @@ void setup() // Set analog led pin to off analogWrite( LED_PIN, 0); - // Send the Sketch Version Information to the Gateway - present(CHILD_ID_LIGHT, S_DIMMER); - sendSketchInfo(SN, SV); - // Retreive our last dim levels from the eprom fadeTo = dimValue = 0; byte oldLevel = loadLevelState(EEPROM_DIM_LEVEL_LAST); @@ -109,6 +105,12 @@ void setup() Serial.println("Ready to receive messages..."); } +void presentation() { + // Send the Sketch Version Information to the Gateway + present(CHILD_ID_LIGHT, S_DIMMER); + sendSketchInfo(SN, SV); +} + void loop() { // Check if someone turned the rotary encode diff --git a/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino b/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino index 5d3e157..7bbcb8f 100644 --- a/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino +++ b/libraries/MySensors/examples/DistanceSensor/DistanceSensor.ino @@ -49,12 +49,15 @@ boolean metric = true; void setup() { + metric = getConfig().isMetric; +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Distance Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_DISTANCE); - metric = getConfig().isMetric; } void loop() diff --git a/libraries/MySensors/examples/DustSensor/DustSensor.ino b/libraries/MySensors/examples/DustSensor/DustSensor.ino index 03eb3e6..d48c6a2 100644 --- a/libraries/MySensors/examples/DustSensor/DustSensor.ino +++ b/libraries/MySensors/examples/DustSensor/DustSensor.ino @@ -64,8 +64,7 @@ float dustDensity = 0; MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL); -void setup() -{ +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Dust Sensor", "1.1"); @@ -73,8 +72,7 @@ void setup() present(CHILD_ID_DUST, S_DUST); } -void loop() -{ +void loop() { uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value // 0 - 5V mapped to 0 - 1023 integer values diff --git a/libraries/MySensors/examples/DustSensorDSM/DustSensorDSM.ino b/libraries/MySensors/examples/DustSensorDSM/DustSensorDSM.ino index 0e4d724..d920f7f 100644 --- a/libraries/MySensors/examples/DustSensorDSM/DustSensorDSM.ino +++ b/libraries/MySensors/examples/DustSensorDSM/DustSensorDSM.ino @@ -67,6 +67,11 @@ MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX); void setup() { + pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT); + pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Dust Sensor DSM501", "1.4"); @@ -75,9 +80,6 @@ void setup() send(msgPM10.set("ppm")); present(CHILD_ID_DUST_PM25, S_DUST); send(msgPM25.set("ppm")); - - pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT); - pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT); } void loop() diff --git a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index 7d79bab..ad36fb7 100644 --- a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -67,12 +67,6 @@ MyMessage pcMsg(CHILD_ID,V_VAR1); void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Energy Meter", "1.0"); - - // Register this device as power sensor - present(CHILD_ID, S_POWER); - // Fetch last known pulse count value from gw request(CHILD_ID, V_VAR1); @@ -80,6 +74,13 @@ void setup() lastSend=millis(); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Energy Meter", "1.0"); + + // Register this device as power sensor + present(CHILD_ID, S_POWER); +} void loop() { diff --git a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino index fee90ea..3cbae74 100644 --- a/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino +++ b/libraries/MySensors/examples/HumiditySensor/HumiditySensor.ino @@ -54,16 +54,20 @@ void setup() { dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); + metric = getConfig().isMetric; +} + +void presentation() +{ // Send the Sketch Version Information to the Gateway sendSketchInfo("Humidity", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); - - metric = getConfig().isMetric; } + void loop() { delay(dht.getMinimumSamplingPeriod()); diff --git a/libraries/MySensors/examples/IrSensor/IrSensor.ino b/libraries/MySensors/examples/IrSensor/IrSensor.ino index d2101a7..29ad4aa 100644 --- a/libraries/MySensors/examples/IrSensor/IrSensor.ino +++ b/libraries/MySensors/examples/IrSensor/IrSensor.ino @@ -57,6 +57,9 @@ void setup() irrecv.enableIRIn(); // Start the ir receiver decoder.UseExtnBuf(Buffer); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("IR Sensor", "1.0"); @@ -64,7 +67,6 @@ void setup() present(CHILD_1, S_LIGHT); } - void loop() { if (irrecv.GetResults(&decoder)) { diff --git a/libraries/MySensors/examples/IrrigationController/IrrigationController.ino b/libraries/MySensors/examples/IrrigationController/IrrigationController.ino index f9e5cdf..6b10563 100644 --- a/libraries/MySensors/examples/IrrigationController/IrrigationController.ino +++ b/libraries/MySensors/examples/IrrigationController/IrrigationController.ino @@ -206,11 +206,7 @@ void setup() lastTimeRun = lastTimeRun | loadState(i + 1); // assemble 4 bytes into an ussigned long epoch timestamp } } - sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); - for (byte i = 0; i <= NUMBER_OF_VALVES; i++) - { - present(i, S_LIGHT); - } + DEBUG_PRINTLN(F("Sensor Presentation Complete")); // digitalWrite (ledPin, LOW); @@ -282,6 +278,17 @@ void setup() } lcd.clear(); } + + +void presentation() +{ + sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); + for (byte i = 0; i <= NUMBER_OF_VALVES; i++) + { + present(i, S_LIGHT); + } +} + // void loop() { diff --git a/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino b/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino index 665568c..b1a90f6 100644 --- a/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino +++ b/libraries/MySensors/examples/LightLuxSensor/LightLuxSensor.ino @@ -63,13 +63,15 @@ uint16_t lastlux; void setup() { + lightSensor.begin(); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Light Lux Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); - - lightSensor.begin(); } void loop() diff --git a/libraries/MySensors/examples/LightSensor/LightSensor.ino b/libraries/MySensors/examples/LightSensor/LightSensor.ino index 8c27775..518c633 100644 --- a/libraries/MySensors/examples/LightSensor/LightSensor.ino +++ b/libraries/MySensors/examples/LightSensor/LightSensor.ino @@ -43,8 +43,8 @@ unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; -void setup() -{ + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Light Sensor", "1.0"); diff --git a/libraries/MySensors/examples/LightningSensor/LightningSensor.ino b/libraries/MySensors/examples/LightningSensor/LightningSensor.ino index 5b85acf..4bf57ae 100644 --- a/libraries/MySensors/examples/LightningSensor/LightningSensor.ino +++ b/libraries/MySensors/examples/LightningSensor/LightningSensor.ino @@ -39,14 +39,6 @@ MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1); void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Lightning Sensor", "1.1"); - - // Register all sensors to gw (they will be created as child devices) - present(CHILD_ID_DISTANCE, S_DISTANCE); - present(CHILD_ID_INTENSITY, S_CUSTOM); - - Serial.begin(115200); Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001"); Serial.println("beginning boot procedure...."); @@ -76,6 +68,15 @@ void setup() } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Lightning Sensor", "1.1"); + + // Register all sensors to gw (they will be created as child devices) + present(CHILD_ID_DISTANCE, S_DISTANCE); + present(CHILD_ID_INTENSITY, S_CUSTOM); +} + void loop() { diff --git a/libraries/MySensors/examples/MAX6875TemperatureSensor/MAX6875TemperatureSensor.ino b/libraries/MySensors/examples/MAX6875TemperatureSensor/MAX6875TemperatureSensor.ino index fa98f90..4f0fa3a 100644 --- a/libraries/MySensors/examples/MAX6875TemperatureSensor/MAX6875TemperatureSensor.ino +++ b/libraries/MySensors/examples/MAX6875TemperatureSensor/MAX6875TemperatureSensor.ino @@ -60,8 +60,7 @@ MyMessage msg(0, V_TEMP); MAX6675 temp0(CS0, SO, SCLK, units); -void setup() -{ +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Max6675 Temp Sensor", "1.0"); diff --git a/libraries/MySensors/examples/MockMySensors/MockMySensors.ino b/libraries/MySensors/examples/MockMySensors/MockMySensors.ino index e9d37ea..f1bd985 100644 --- a/libraries/MySensors/examples/MockMySensors/MockMySensors.ino +++ b/libraries/MySensors/examples/MockMySensors/MockMySensors.ino @@ -335,7 +335,9 @@ void setup() wait(LONG_WAIT); Serial.println("GW Started"); - +} + +void presentation() { // Send the Sketch Version Information to the Gateway Serial.print("Send Sketch Info: "); sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); diff --git a/libraries/MySensors/examples/MotionSensor/MotionSensor.ino b/libraries/MySensors/examples/MotionSensor/MotionSensor.ino index 8d64c21..79d6ba6 100644 --- a/libraries/MySensors/examples/MotionSensor/MotionSensor.ino +++ b/libraries/MySensors/examples/MotionSensor/MotionSensor.ino @@ -46,13 +46,15 @@ MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { + pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Motion Sensor", "1.0"); - pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_MOTION); - } void loop() diff --git a/libraries/MySensors/examples/ParkingSensor/ParkingSensor.ino b/libraries/MySensors/examples/ParkingSensor/ParkingSensor.ino index d7a786b..42e1f84 100644 --- a/libraries/MySensors/examples/ParkingSensor/ParkingSensor.ino +++ b/libraries/MySensors/examples/ParkingSensor/ParkingSensor.ino @@ -95,11 +95,14 @@ void setup() { Serial.println("Starting distance sensor"); pixels.begin(); // This initializes the NeoPixel library. Serial.println("Neopixels initialized"); +} + #ifdef SEND_STATUS_TO_CONTROLLER +void presentation() { sendSketchInfo("Parking Sensor", "1.0"); present(CHILD_ID, S_DOOR, "Parking Status"); -#endif } +#endif void loop() { unsigned long now = millis(); diff --git a/libraries/MySensors/examples/PingPongSensor/PingPongSensor.ino b/libraries/MySensors/examples/PingPongSensor/PingPongSensor.ino index 106cbc2..f40911a 100644 --- a/libraries/MySensors/examples/PingPongSensor/PingPongSensor.ino +++ b/libraries/MySensors/examples/PingPongSensor/PingPongSensor.ino @@ -29,6 +29,9 @@ MyMessage mPing(CHILD, V_VAR1); //Ping message MyMessage mPong(CHILD, V_VAR2); //Pong message void setup() { +} + +void presentation() { present(CHILD, S_CUSTOM); // sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN ); diff --git a/libraries/MySensors/examples/PressureSensor/PressureSensor.ino b/libraries/MySensors/examples/PressureSensor/PressureSensor.ino index c7658ea..e6990c3 100644 --- a/libraries/MySensors/examples/PressureSensor/PressureSensor.ino +++ b/libraries/MySensors/examples/PressureSensor/PressureSensor.ino @@ -86,21 +86,23 @@ MyMessage forecastMsg(BARO_CHILD, V_FORECAST); void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Pressure Sensor", "1.1"); - if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } - - // Register sensors to gw (they will be created as child devices) - present(BARO_CHILD, S_BARO); - present(TEMP_CHILD, S_TEMP); metric = getConfig().isMetric; } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Pressure Sensor", "1.1"); + + // Register sensors to gw (they will be created as child devices) + present(BARO_CHILD, S_BARO); + present(TEMP_CHILD, S_TEMP); +} + void loop() { float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; diff --git a/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino b/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino index 1b723a7..a0c455b 100644 --- a/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino +++ b/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino @@ -96,12 +96,14 @@ void setup() { // configure board to read RFID tags nfc.SAMConfig(); - sendSketchInfo("RFID Lock", "1.0"); - present(CHILD_ID, S_LOCK); - lockStatus = loadState(0); // Read last lock status from eeprom setLockState(lockStatus, true); // Now set the last known state and send it to controller } + +void presentation() { + sendSketchInfo("RFID Lock", "1.0"); + present(CHILD_ID, S_LOCK); +} void loop() { boolean success; diff --git a/libraries/MySensors/examples/RGB-3D/RGB-3D.ino b/libraries/MySensors/examples/RGB-3D/RGB-3D.ino index bfc1026..e6c766e 100644 --- a/libraries/MySensors/examples/RGB-3D/RGB-3D.ino +++ b/libraries/MySensors/examples/RGB-3D/RGB-3D.ino @@ -62,15 +62,6 @@ int isShow; void setup() { - // Present sketch (name, version) - sendSketchInfo(SN, SV); - - // Register sensors (id, type, description, ack back) - present(RED_PIN, S_DIMMER, "present RED light", false); - present(GREEN_PIN, S_DIMMER, "present GREEN light", false); - present(BLUE_PIN, S_DIMMER, "present BLUE light", false); - present(0, S_LIGHT, "present Show button", false); - // Define pin mode (pin number, type) pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); @@ -114,6 +105,17 @@ void setup() Serial.println("Ready to receive messages..."); } +void presentation() { + // Present sketch (name, version) + sendSketchInfo(SN, SV); + + // Register sensors (id, type, description, ack back) + present(RED_PIN, S_DIMMER, "present RED light", false); + present(GREEN_PIN, S_DIMMER, "present GREEN light", false); + present(BLUE_PIN, S_DIMMER, "present BLUE light", false); + present(0, S_LIGHT, "present Show button", false); +} + void loop() { // Run RGB show if is set diff --git a/libraries/MySensors/examples/RainGauge/RainGauge.ino b/libraries/MySensors/examples/RainGauge/RainGauge.ino index 264ea7c..ea22e26 100644 --- a/libraries/MySensors/examples/RainGauge/RainGauge.ino +++ b/libraries/MySensors/examples/RainGauge/RainGauge.ino @@ -145,14 +145,6 @@ void setup() pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); // - sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); - wait(DWELL_TIME); - present(CHILD_ID_RAIN_LOG, S_RAIN); - wait(DWELL_TIME); - present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION); - wait(DWELL_TIME); - DEBUG_PRINTLN(F("Sensor Presentation Complete")); - // //Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal // unsigned long functionTimeout = millis(); @@ -206,17 +198,11 @@ void setup() // #ifdef DHT_ON dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); - // Register all sensors to gw (they will be created as child devices) - present(CHILD_ID_HUM, S_HUM); - wait(DWELL_TIME); - present(CHILD_ID_TEMP, S_TEMP); wait(DWELL_TIME); metric = getConfig().isMetric; - wait(DWELL_TIME); #endif // #ifdef LUX_ON - present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); wait(DWELL_TIME); lightSensor.begin(); #endif @@ -225,6 +211,31 @@ void setup() transmitRainData(); } + +void presentation() { + // Register all sensors to gw (they will be created as child devices) + sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); + wait(DWELL_TIME); + present(CHILD_ID_RAIN_LOG, S_RAIN); + wait(DWELL_TIME); + present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION); + wait(DWELL_TIME); + +#ifdef DHT_ON + present(CHILD_ID_HUM, S_HUM); + wait(DWELL_TIME); + present(CHILD_ID_TEMP, S_TEMP); + wait(DWELL_TIME); +#endif + + +#ifdef LUX_ON + present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); +#endif + + DEBUG_PRINTLN(F("Sensor Presentation Complete")); +} + void loop() { if (state) diff --git a/libraries/MySensors/examples/RealTimeClockDisplaySensor/RealTimeClockDisplaySensor.ino b/libraries/MySensors/examples/RealTimeClockDisplaySensor/RealTimeClockDisplaySensor.ino index 4d3c83a..ccdb576 100644 --- a/libraries/MySensors/examples/RealTimeClockDisplaySensor/RealTimeClockDisplaySensor.ino +++ b/libraries/MySensors/examples/RealTimeClockDisplaySensor/RealTimeClockDisplaySensor.ino @@ -61,9 +61,6 @@ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("RTC Clock", "1.0"); - // the function to get the time from the RTC setSyncProvider(RTC.get); @@ -74,6 +71,11 @@ void setup() lcd.begin(16,2); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("RTC Clock", "1.0"); +} + // This is called when a new time value was received void receiveTime(unsigned long controllerTime) { // Ok, set incoming time diff --git a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino index d31b96d..d6d7a5c 100644 --- a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino +++ b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino @@ -44,15 +44,10 @@ #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay + void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Relay", "1.0"); - - // Fetch relay status for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { - // Register all sensors to gw (they will be created as child devices) - present(sensor, S_LIGHT); // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) @@ -60,6 +55,17 @@ void setup() } } +void presentation() +{ + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Relay", "1.0"); + + for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { + // Register all sensors to gw (they will be created as child devices) + present(sensor, S_LIGHT); + } +} + void loop() { diff --git a/libraries/MySensors/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino b/libraries/MySensors/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino index 8912008..f7e2dda 100644 --- a/libraries/MySensors/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino +++ b/libraries/MySensors/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino @@ -56,10 +56,7 @@ MyMessage msg(CHILD_ID,V_LIGHT); void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Relay & Button", "1.0"); - - // Setup the button + // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); @@ -68,9 +65,6 @@ void setup() debouncer.attach(BUTTON_PIN); debouncer.interval(5); - // Register all sensors to gw (they will be created as child devices) - present(CHILD_ID, S_LIGHT); - // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode @@ -81,6 +75,13 @@ void setup() digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Relay & Button", "1.0"); + + // Register all sensors to gw (they will be created as child devices) + present(CHILD_ID, S_LIGHT); +} /* * Example on how to asynchronously check for new messages from gw diff --git a/libraries/MySensors/examples/RepeaterNode/RepeaterNode.ino b/libraries/MySensors/examples/RepeaterNode/RepeaterNode.ino index ace19da..fcde7fc 100644 --- a/libraries/MySensors/examples/RepeaterNode/RepeaterNode.ino +++ b/libraries/MySensors/examples/RepeaterNode/RepeaterNode.ino @@ -40,7 +40,11 @@ #include -void setup() +void setup() { + +} + +void presentation() { //Send the sensor node sketch version information to the gateway sendSketchInfo("Repeater Node", "1.0"); diff --git a/libraries/MySensors/examples/SecretKnockSensor/SecretKnockSensor.ino b/libraries/MySensors/examples/SecretKnockSensor/SecretKnockSensor.ino index 8030bd8..72ca65b 100644 --- a/libraries/MySensors/examples/SecretKnockSensor/SecretKnockSensor.ino +++ b/libraries/MySensors/examples/SecretKnockSensor/SecretKnockSensor.ino @@ -98,9 +98,6 @@ void setup() { pinMode(programButton, INPUT); digitalWrite(programButton, HIGH); // Enable internal pull up - sendSketchInfo("Secret Knock", "1.0"); - present(CHILD_ID, S_LOCK); - readSecretKnock(); // Load the secret knock (if any) from EEPROM. digitalWrite(lockPin, HIGH); // Unlock the door for a bit when we power up. For system check and to allow a way in if the key is forgotten @@ -111,6 +108,11 @@ void setup() { delay(500); // This delay is here because the solenoid lock returning to place can otherwise trigger and inadvertent knock. } + +void presentation() { + sendSketchInfo("Secret Knock", "1.0"); + present(CHILD_ID, S_LOCK); +} void loop() { // Listen for any knock at all. diff --git a/libraries/MySensors/examples/SecureActuator/SecureActuator.ino b/libraries/MySensors/examples/SecureActuator/SecureActuator.ino index ac52f2e..d11bf38 100644 --- a/libraries/MySensors/examples/SecureActuator/SecureActuator.ino +++ b/libraries/MySensors/examples/SecureActuator/SecureActuator.ino @@ -62,7 +62,16 @@ #define LOCK_LOCK 1 // GPIO value to write to lock attached lock #define LOCK_UNLOCK 0 // GPIO value to write to unlock attached lock -void setup() +void setup() { + for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS;lock++, pin++) { + // Set lock pins in output mode + pinMode(pin, OUTPUT); + // Set lock to last known state (using eeprom storage) + digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK); + } +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Secure Lock", "1.0"); @@ -71,10 +80,6 @@ void setup() for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS;lock++, pin++) { // Register all locks to gw (they will be created as child devices) present(lock, S_LOCK, "SecureActuator", false); - // Then set lock pins in output mode - pinMode(pin, OUTPUT); - // Set lock to last known state (using eeprom storage) - digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK); } } diff --git a/libraries/MySensors/examples/SensebenderBlink/SensebenderBlink.ino b/libraries/MySensors/examples/SensebenderBlink/SensebenderBlink.ino index d84be05..2150377 100644 --- a/libraries/MySensors/examples/SensebenderBlink/SensebenderBlink.ino +++ b/libraries/MySensors/examples/SensebenderBlink/SensebenderBlink.ino @@ -30,9 +30,10 @@ MyMessage msgCounter(CHILD_ID_COUNTER, V_VAR1); void setup() { pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LED_STATUS); - +} + +void presentation() { sendSketchInfo(SketchName, SketchVersion); - present(CHILD_ID_COUNTER, S_CUSTOM,"Millis()"); } diff --git a/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino b/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino index b66bdbd..8bcf6be 100644 --- a/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino +++ b/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino @@ -162,15 +162,6 @@ void setup() { Serial.flush(); Serial.println(F(" - Online!")); - sendSketchInfo("Sensebender Micro", RELEASE); - - present(CHILD_ID_TEMP,S_TEMP); - present(CHILD_ID_HUM,S_HUM); - -#ifdef BATT_SENSOR - present(BATT_SENSOR, S_POWER); -#endif - isMetric = getConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); @@ -181,6 +172,17 @@ void setup() { } +void presentation() { + sendSketchInfo("Sensebender Micro", RELEASE); + + present(CHILD_ID_TEMP,S_TEMP); + present(CHILD_ID_HUM,S_HUM); + +#ifdef BATT_SENSOR + present(BATT_SENSOR, S_POWER); +#endif +} + /*********************************************** * diff --git a/libraries/MySensors/examples/ServoActuator/ServoActuator.ino b/libraries/MySensors/examples/ServoActuator/ServoActuator.ino index e3aef43..d058969 100644 --- a/libraries/MySensors/examples/ServoActuator/ServoActuator.ino +++ b/libraries/MySensors/examples/ServoActuator/ServoActuator.ino @@ -55,15 +55,17 @@ bool attachedServo = false; void setup() { + // Request last servo state at startup + request(CHILD_ID, V_DIMMER); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Servo", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_COVER); - - // Request last servo state at startup - request(CHILD_ID, V_DIMMER); -} +} void loop() { diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino index 8c39a79..09a571f 100644 --- a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino +++ b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino @@ -95,9 +95,6 @@ values valueOf[NUM_READS]; // Calculated moisture percentages and resista int i; // Simple index variable void setup() { - - sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0"); - present(CHILD_ID, S_HUM); // initialize the digital pins as an output. // Pin 6,7 is for sensor 1 // initialize the digital pin as an output. @@ -109,6 +106,11 @@ void setup() { pinMode(7, OUTPUT); } +void presentation() { + sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0"); + present(CHILD_ID, S_HUM); +} + void loop() { measure(6,7,1); diff --git a/libraries/MySensors/examples/TimeAwareSensor/TimeAwareSensor.ino b/libraries/MySensors/examples/TimeAwareSensor/TimeAwareSensor.ino index cb46f14..607b1a9 100644 --- a/libraries/MySensors/examples/TimeAwareSensor/TimeAwareSensor.ino +++ b/libraries/MySensors/examples/TimeAwareSensor/TimeAwareSensor.ino @@ -40,13 +40,15 @@ unsigned long lastUpdate=0, lastRequest=0; void setup() { - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Clock", "1.0"); - // Request time from controller. requestTime(); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Clock", "1.0"); +} + // This is called when a new time value was received void receiveTime(unsigned long time) { // Ok, set incoming time diff --git a/libraries/MySensors/examples/TouchDisplaySceneControllerSensor/TouchDisplaySceneControllerSensor.ino b/libraries/MySensors/examples/TouchDisplaySceneControllerSensor/TouchDisplaySceneControllerSensor.ino index f1c478e..e50b8b8 100644 --- a/libraries/MySensors/examples/TouchDisplaySceneControllerSensor/TouchDisplaySceneControllerSensor.ino +++ b/libraries/MySensors/examples/TouchDisplaySceneControllerSensor/TouchDisplaySceneControllerSensor.ino @@ -127,13 +127,15 @@ void setup() } myButtons.drawButtons(); - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Scene Ctrl", "1.0"); - present(CHILD_ID, S_SCENE_CONTROLLER); // Request time from controller. requestTime(); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Scene Ctrl", "1.0"); + present(CHILD_ID, S_SCENE_CONTROLLER); +} int lastPressedButton = -1; diff --git a/libraries/MySensors/examples/UVSensor/UVSensor.ino b/libraries/MySensors/examples/UVSensor/UVSensor.ino index 2fb70eb..ddf7612 100644 --- a/libraries/MySensors/examples/UVSensor/UVSensor.ino +++ b/libraries/MySensors/examples/UVSensor/UVSensor.ino @@ -58,8 +58,8 @@ float uvIndex; float lastUV = -1; uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170}; -void setup() -{ + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("UV Sensor", "1.2"); diff --git a/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino b/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino index f32aa5c..9ca7f81 100644 --- a/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino +++ b/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino @@ -58,16 +58,17 @@ MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL); void setup() { + pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT); + attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected + pinMode(SensorLED, OUTPUT); +} + +void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("VIBRATION Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_VIBRATION, S_VIBRATION); - - - pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT); - attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected - pinMode(SensorLED, OUTPUT); } void loop() diff --git a/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino b/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino index 5803917..056d022 100644 --- a/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino +++ b/libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino @@ -79,12 +79,6 @@ void setup() // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion) pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP); - // Send the sketch version information to the gateway and Controller - sendSketchInfo("Water Meter", "1.1"); - - // Register this device as Waterflow sensor - present(CHILD_ID, S_WATER); - pulseCount = oldPulseCount = 0; // Fetch last known pulse count value from gw @@ -95,6 +89,13 @@ void setup() attachInterrupt(SENSOR_INTERRUPT, onPulse, FALLING); } +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("Water Meter", "1.1"); + + // Register this device as Waterflow sensor + present(CHILD_ID, S_WATER); +} void loop() {