Heartbeat


  • Plugin Developer

    hello
    Has it there in the library means to control whether a node is active?
    type heartbeat
    thanks


  • Contest Winner

    @filoucaenais

    I do it by sending the status with a regular interval... so that you can see from the Last Update time in the device panel (Vera).

    like this example:

    /*
    * Motion Sensor Version 1.1
    *
    * November 7, 2014
    * -Added pushing text status to V_VAR1
    *
    * Version 1 - October 4, 2014
    * -Modified to transmit on state change
    * -removed Sleep for mains-only device
    * -Updates gateway according to UPDATE_INTERVAL
    *
    */
    #include <MySensor.h>
    #include <SPI.h>
    //
    #define DEBUG
    //
    #define DIGITAL_INPUT_SENSOR 3
    #define RADIO_ID 2
    #define CHILD_ID 1
    #define UPDATE_INTERVAL 60000UL  // 1 minute
    //
    boolean lastSensorState;
    
    //
    MySensor gw;
    //
    MyMessage stateMsg(CHILD_ID, V_TRIPPED);
    MyMessage updateMsg(CHILD_ID, V_VAR1);
    //
    void setup()
    {
      gw.begin(NULL, RADIO_ID, false);
      #ifdef DEBUG
        Serial.begin(115200);
      #endif
      gw.sendSketchInfo("MotionSensor", "V1.1");
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);
      gw.present(CHILD_ID, S_MOTION);
    }
    //
    void loop()
    {
      boolean sensorState = digitalRead(DIGITAL_INPUT_SENSOR);
      if (sensorState != lastSensorState)
      {
        #ifdef DEBUG
          digitalWrite(13, sensorState ? HIGH : LOW);
          Serial.println(sensorState ? "Tripped" : "Not Tripped");
        #endif
        gw.send(stateMsg.set(sensorState ? "1" : "0"));
      }
      lastSensorState = sensorState;
      updateStatus(UPDATE_INTERVAL);
    }
    //
    void updateStatus(unsigned long updateInterval)
    {
      static unsigned long lastUpdate;
      if (millis() - lastUpdate >= updateInterval)
      {
        gw.send(updateMsg.set(lastSensorState ? "Motion Detected" : "No Motion"));
        #ifdef DEBUG
          digitalWrite(13, lastSensorState ? HIGH : LOW);
          Serial.println(lastSensorState ? F("Tripped") : F("Not Tripped"));
        #endif
        lastUpdate += updateInterval;
      }
    }

  • Plugin Developer

    thank you for your answer


Log in to reply
 

Suggested Topics

43
Online

11.4k
Users

11.1k
Topics

112.6k
Posts