Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. Vera
  4. Vera crash loop on distance sensor update

Vera crash loop on distance sensor update

Scheduled Pinned Locked Moved Vera
14 Posts 3 Posters 3.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hekH Offline
    hekH Offline
    hek
    Admin
    wrote on last edited by
    #5

    Once per second is still pretty frequent. If the Vera box is busy on some other task it'll start queueing.

    1 Reply Last reply
    0
    • signal15S Offline
      signal15S Offline
      signal15
      wrote on last edited by
      #6

      Here's my sketch:

      /*
       * 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 <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Jay Austad
       * 
       * DESCRIPTION
       * This sketch provides an example how to implement a distance sensor using Maxbotix sensor with RS232 output 
       * http://www.mysensors.org/build/xxx
       
       Receives from the hardware serial, sends to software serial.
       Receives from software serial, sends to hardware serial.
      
       The circuit:
       * RX is digital pin 3 (connect to RXD of MAX232)
       * TX is digital pin 4 (connect to TXD of MAX232)
      
       Note:
       Not all pins on the Mega and Mega 2560 support change interrupts,
       so only the following can be used for RX:
       10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
      
       Not all pins on the Leonardo support change interrupts,
       so only the following can be used for RX:
       8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
      
       This example uses code written by Henrik EKblad, Tom Igoe, Mikal Hart, and Jay Austad
       */
      
      #include <SoftwareSerial.h>
      #include <SPI.h>
      #include <MySensor.h>  
      #include <NewPing.h>
      
      #define CHILD_ID1 1
      #define CHILD_ID2 3
      
      #define TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     6  // Arduino pin tied to echo pin on the ultrasonic sensor.
      #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
      unsigned long SLEEP_TIME = 1000; // Sleep time between reads (in milliseconds)
      
      MySensor gw;
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      MyMessage msg1(CHILD_ID1, V_DISTANCE);
      MyMessage msg2(CHILD_ID2, V_DISTANCE);
      
      boolean metric = true; 
      SoftwareSerial mySerial(3, 4); // RX, TX
      float mm1;
      float cm1;
      float inches1;
      float dist1;
      float lastDist1;
      int lastDist2;
      
      
      void setup() {
        gw.begin();
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Distance Sensor", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID1, S_DISTANCE);
        gw.present(CHILD_ID2, S_DISTANCE);
      
        metric = gw.getConfig().isMetric;
      
        Serial.println("Maxbotix RS232 Mysensors Sketch");
      
        // set the data rate for the SoftwareSerial port
        mySerial.begin(9600);
      }
      
      void loop() { // run over and over
        //Maxbotix sensor, child ID 1
        if (mySerial.available() > 0) {
          mm1 = mySerial.parseFloat();
          if (mm1 != 0) {
            inches1 = mm1/25.4;
            cm1 = mm1/10;
            dist1 = metric?cm1:inches1;
            Serial.print(dist1);
            Serial.println(metric?" cm":" in");
          }
        
          if (dist1 != lastDist1) {
            gw.send(msg1.set(dist1, 2));
            lastDist1 = dist1;
          }
        }
      //sonar sensor, child ID 2
        int uS = sonar.ping();
        if (uS==0)
        {
          Serial.println("MAX: resetting sensor");
          pinMode(ECHO_PIN, OUTPUT);
          delay(150);
          digitalWrite(ECHO_PIN, LOW);
          delay(150);
          pinMode(ECHO_PIN, INPUT);
          delay(150);
        } else {
          int dist2 = metric?sonar.ping_cm():sonar.ping_in();
          Serial.print("Ping: ");
          Serial.print(dist2); // Convert ping time to distance in cm and print result (0 = outside set distance range)
          Serial.println(metric?" cm":" in");
      
          if (dist2 != lastDist2) {
            gw.send(msg2.set(dist2));
            lastDist2 = dist2;
          }
        }
        gw.sleep(SLEEP_TIME);
        
      }
      
      BartEB 1 Reply Last reply
      0
      • signal15S signal15

        Here's my sketch:

        /*
         * 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 <henrik.ekblad@mysensors.org>
         * Copyright (C) 2013-2015 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.
         *
         *******************************
         *
         * REVISION HISTORY
         * Version 1.0 - Jay Austad
         * 
         * DESCRIPTION
         * This sketch provides an example how to implement a distance sensor using Maxbotix sensor with RS232 output 
         * http://www.mysensors.org/build/xxx
         
         Receives from the hardware serial, sends to software serial.
         Receives from software serial, sends to hardware serial.
        
         The circuit:
         * RX is digital pin 3 (connect to RXD of MAX232)
         * TX is digital pin 4 (connect to TXD of MAX232)
        
         Note:
         Not all pins on the Mega and Mega 2560 support change interrupts,
         so only the following can be used for RX:
         10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
        
         Not all pins on the Leonardo support change interrupts,
         so only the following can be used for RX:
         8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
        
         This example uses code written by Henrik EKblad, Tom Igoe, Mikal Hart, and Jay Austad
         */
        
        #include <SoftwareSerial.h>
        #include <SPI.h>
        #include <MySensor.h>  
        #include <NewPing.h>
        
        #define CHILD_ID1 1
        #define CHILD_ID2 3
        
        #define TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
        #define ECHO_PIN     6  // Arduino pin tied to echo pin on the ultrasonic sensor.
        #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
        unsigned long SLEEP_TIME = 1000; // Sleep time between reads (in milliseconds)
        
        MySensor gw;
        NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
        MyMessage msg1(CHILD_ID1, V_DISTANCE);
        MyMessage msg2(CHILD_ID2, V_DISTANCE);
        
        boolean metric = true; 
        SoftwareSerial mySerial(3, 4); // RX, TX
        float mm1;
        float cm1;
        float inches1;
        float dist1;
        float lastDist1;
        int lastDist2;
        
        
        void setup() {
          gw.begin();
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Distance Sensor", "1.0");
        
          // Register all sensors to gw (they will be created as child devices)
          gw.present(CHILD_ID1, S_DISTANCE);
          gw.present(CHILD_ID2, S_DISTANCE);
        
          metric = gw.getConfig().isMetric;
        
          Serial.println("Maxbotix RS232 Mysensors Sketch");
        
          // set the data rate for the SoftwareSerial port
          mySerial.begin(9600);
        }
        
        void loop() { // run over and over
          //Maxbotix sensor, child ID 1
          if (mySerial.available() > 0) {
            mm1 = mySerial.parseFloat();
            if (mm1 != 0) {
              inches1 = mm1/25.4;
              cm1 = mm1/10;
              dist1 = metric?cm1:inches1;
              Serial.print(dist1);
              Serial.println(metric?" cm":" in");
            }
          
            if (dist1 != lastDist1) {
              gw.send(msg1.set(dist1, 2));
              lastDist1 = dist1;
            }
          }
        //sonar sensor, child ID 2
          int uS = sonar.ping();
          if (uS==0)
          {
            Serial.println("MAX: resetting sensor");
            pinMode(ECHO_PIN, OUTPUT);
            delay(150);
            digitalWrite(ECHO_PIN, LOW);
            delay(150);
            pinMode(ECHO_PIN, INPUT);
            delay(150);
          } else {
            int dist2 = metric?sonar.ping_cm():sonar.ping_in();
            Serial.print("Ping: ");
            Serial.print(dist2); // Convert ping time to distance in cm and print result (0 = outside set distance range)
            Serial.println(metric?" cm":" in");
        
            if (dist2 != lastDist2) {
              gw.send(msg2.set(dist2));
              lastDist2 = dist2;
            }
          }
          gw.sleep(SLEEP_TIME);
          
        }
        
        BartEB Offline
        BartEB Offline
        BartE
        Contest Winner
        wrote on last edited by
        #7

        @signal15 just two foods for thought.

        1. Your sketch loops once a seconds with 2 distance sensors so there might be 2 messages a second causing the Vera to flood
        2. "#hooks: 1 upnp: 0 v:(nil)/NONE duplicate:0 <0x2f5b3680>" this look like a division by zero in the Vera plugin is there an scene linked to the distance sensor?
        signal15S 1 Reply Last reply
        0
        • BartEB BartE

          @signal15 just two foods for thought.

          1. Your sketch loops once a seconds with 2 distance sensors so there might be 2 messages a second causing the Vera to flood
          2. "#hooks: 1 upnp: 0 v:(nil)/NONE duplicate:0 <0x2f5b3680>" this look like a division by zero in the Vera plugin is there an scene linked to the distance sensor?
          signal15S Offline
          signal15S Offline
          signal15
          wrote on last edited by
          #8

          @BartE

          There are no scenes linked to the distance sensor. However, I did put in an alert for when the distance goes above a certain amount for one sensor, and below a certain level for the other. Come to think of it, I started having problems when I put in this alert. I set the alert up for the cheapy sensor first, and then had the problem. And, the problems with the other sensor started when I put in the alert for that one.

          As for the sending rate, the distance for both of these sensors changes very slowly. And, it's supposed to only send when the distance changes. I set it to every second, because the Maxbotix sensor sends data every second, and I was concerned about data queuing in it over more than a second and causing the parsing not to work properly. Maybe that fear is unfounded since I haven't tried it with more of a delay.

          1 Reply Last reply
          0
          • hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #9

            No need to send all this data to the controller. It's much better to do this processing in the sensor. You can "flip a switch" (binary senor) on vera when your distance goes above the threshold.

            signal15S 1 Reply Last reply
            1
            • BartEB Offline
              BartEB Offline
              BartE
              Contest Winner
              wrote on last edited by BartE
              #10

              And if you like to show some data sent an update of the actual distance on a much lower frequency

              1 Reply Last reply
              0
              • hekH hek

                No need to send all this data to the controller. It's much better to do this processing in the sensor. You can "flip a switch" (binary senor) on vera when your distance goes above the threshold.

                signal15S Offline
                signal15S Offline
                signal15
                wrote on last edited by
                #11

                @hek

                I need to keep an eye on the distance for one of the sensors, not just track whether it goes below a certain distance. Eventually I need to write logic where if it's increasing at a certain rate, then it will need to alert me.

                Interestingly enough, I have MySensors set to Imperial units. However, when I go into the Distance Sensor devices on Vera to set up the alert, the label on it is in centimeters. I'm wondering if that divide by zero in the log is a result of it trying to convert to inches and some code not having 2.54 where the zero/nil is.

                BartEB 1 Reply Last reply
                0
                • signal15S signal15

                  @hek

                  I need to keep an eye on the distance for one of the sensors, not just track whether it goes below a certain distance. Eventually I need to write logic where if it's increasing at a certain rate, then it will need to alert me.

                  Interestingly enough, I have MySensors set to Imperial units. However, when I go into the Distance Sensor devices on Vera to set up the alert, the label on it is in centimeters. I'm wondering if that divide by zero in the log is a result of it trying to convert to inches and some code not having 2.54 where the zero/nil is.

                  BartEB Offline
                  BartEB Offline
                  BartE
                  Contest Winner
                  wrote on last edited by BartE
                  #12

                  @signal15 like @hek is writing this requires a "high" freqency update which just works more reliable when calculated inside the sensor and not by the controller also "increasing at a certain rate" can be implemented as a smoke alarm and being triggered with a V_TRIPPED message when "certain rate" is reached

                  1 Reply Last reply
                  0
                  • hekH Offline
                    hekH Offline
                    hek
                    Admin
                    wrote on last edited by
                    #13

                    I think "cm" is hardcoded in the Vera distance plugin. You'll have to hack the plugin json to fix it.

                    BartEB 1 Reply Last reply
                    0
                    • hekH hek

                      I think "cm" is hardcoded in the Vera distance plugin. You'll have to hack the plugin json to fix it.

                      BartEB Offline
                      BartEB Offline
                      BartE
                      Contest Winner
                      wrote on last edited by BartE
                      #14

                      @hek true line 88 of the D_DistanceSensor1.json file:

                       {
                                          "ControlType": "label",
                                          "Label": {
                                              "lang_tag": "distance_unit",
                                              "text": "cm"    <------ line 88
                                          },
                                          "Display": {
                                              "Top": 30,
                                              "Left": 200,
                                              "Width": 25,
                                              "Height": 20 
                                          }
                                      }
                      
                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      12

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular