Vera crash loop on distance sensor update



  • I have two distance sensors. It appears that one of them is causing the LuaUPnP to crash and restart repeatedly. It seemed to be working fine for the past week. No changes were made. And today it just started going bananas. It always seems to crash right after this log entry:

    50	05/22/16 17:35:32.432	luup_log:194: Arduino: urn:micasaverde-com:serviceId:HaDevice1,LastUpdateHR, 05:35 PM, 205 <0x2f5b3680>
    50	05/22/16 17:35:32.491	luup_log:194: Arduino: Set variable: 2;3;1;0;13;28 <0x2f5b3680>
    50	05/22/16 17:35:32.492	luup_log:194: Arduino: Setting variable 'CurrentDistance' to value '28' <0x2f5b3680>
    50	05/22/16 17:35:32.492	luup_log:194: Arduino: urn:micasaverde-com:serviceId:DistanceSensor1,CurrentDistance, 28, 206 <0x2f5b3680>
    06	05/22/16 17:35:32.492	Device_Variable::m_szValue_set device: 206 service: urn:micasaverde-com:serviceId:DistanceSensor1 variable: CurrentDistance was: 27 now: 28 #hooks: 1 upnp: 0 v:(nil)/NONE duplicate:0 <0x2f5b3680>
    
    
    2016-05-22 17:35:32 - LuaUPnP Terminated with Exit Code: 245
    
    
    
    2016-05-22 17:35:32 - LuaUPnP crash
    

    Any ideas here?



  • So it started doing it again. This particular node has 2 distance sensors on it. One is the standard cheap sonar one used in the examples, and the other is a $150 Maxbotix which talks via RS232. When this was happening above, it was happening when the cheapy sonar sensor sent an update. Instant LUA engine crash. To resolve it, I deleted that distance sensor device from the Vera.

    It was working fine for a couple of weeks, but it started crashing again. Now it crashes when the Maxbotix sensor sends an update. I just deleted the whole node from the Vera, and now it's not crashing anymore. But I no longer have the distance sensor data in Vera.

    I'm using the 1.5 vera plugin on UI5. Are there known issues with it?

    On the Micasaverde forums, someone said this:


    The "Sending" is likely the symptom.

    You likely are sending "Events" faster than some logic is "Consuming" the events.
    If the consumer, falls behind, when you queue the third (I think that's the number) of events for the consumer, it will trip a Vera "Deadlock" restart.


    Does anyone have any insight?

    As a side note, I've got a Vera Plus on the way so I can convert everything to UI7. Will the UI7 plugin for Mysensors be more stable?


  • Admin

    Are you sending data too frequent perhaps? Spamming the controller...?



  • @hek

    I don't think so. It sleeps for 1 second, and only sends an update on change. From the logs, it only appears to send one update before it crashes. I'll post my code when I get back to my computer.


  • Admin

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



  • 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);
      
    }
    

  • Contest Winner

    @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?


  • @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.


  • Admin

    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.


  • Contest Winner

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



  • @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.


  • Contest Winner

    @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


  • Admin

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


  • Contest Winner

    @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 
                        }
                    }
    

Log in to reply
 

Suggested Topics

  • 2
  • 1
  • 1
  • 5
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts