node stalled

  • Hi there,
    I've been encountering a strange issue with one my nodes and can't seem to figure out how to fix it. The node is built with an arduino nano, nrf24, and a HC-SR04 distance sensor. Things worked out o.k. for a while, then I updated the sketch so the sensor would only send a measurement every 5 minutes. Now, every time I restart the node and check via serial monitor, I only get a few lines, then the whole thing stalls.

    3 TSM:INIT
    4 TSF:WUR:MS=1
    12 TSM:INIT:STATID=151
    15 TSF:SID:OK,ID=15

    I've tried to clear the eeprom, and uploaded the sketch again, but that won't change a thing. My sketch is included below.

    Any idea is welcome at this point...


    // Enable debug prints
    #define MY_DEBUG
    #define MY_DEBUG_VERBOSE
    // define node specific configuration
    #define MY_NODE_ID 151
    #define MY_PARENT_NODE_ID 21
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #include <SPI.h>
    #include <MySensors.h>  
    #include <NewPing.h>
    #define CHILD_ID 1
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // 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 = 300000; // Sleep time between reads (in milliseconds)
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    MyMessage msg(CHILD_ID, V_DISTANCE);
    int lastDist;
    bool metric = true;
    void setup()  
      metric = getControllerConfig().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);
    void loop()      
      int dist = metric?sonar.ping_cm():sonar.ping_in();
      Serial.print("Ping: ");
      Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
      Serial.println(metric?" cm":" in");
      if (dist != lastDist) {
          lastDist = dist;

  • Mod

    @jjk is there a specific reason to use MY_PARENT_NODE_ID? Do you have also a log on gateway or gateway doesn't receive anything? Have you checked the repeater that it seems you are using?

  • @gohan: the reason I'm using MY_PARENT_NODE_ID is to ensure connection to the repeater. The sensor in question is outside in the yard and I won't get it to connect to the gateway otherwise.

    Yes, I have checked, both the repeater node and the gateway and both are talking to each other (gw and repeater), but neither is getting any signals from the node in question. Strangely enough, this setup had worked before I updated the sketch in this particular node...

  • Mod

    Have you updated boards definitions and Arduino ide?

  • @gohan yeah, it's all up to date - plus other node work as desired even after updating today...

  • Mod

    Did you try to swap radios on the nodes? Or swap the Arduinos? Or power supplies? Just try to move things around and see if the problem follows something you moved

  • @gohan no, I have not et swapped hardware... That's on my to-do for the next days, but I was hoping that the problem is a known one with a more or less easy fix. If i's a bad piece of hardware, I guess I will have to got through the swapping exercise... It's just strange that the issue showed up after updating the sketch?!

  • Mod

    Try downgrading the board definitions like to 1.6.11 or mysensors to 2.1.0

  • @gohan, hm not sure I get what you're suggesting...?! I had not changed anything before updating the sketch, so should that really make a difference? The ide and libraries are the same I have used a day or two ago to install the initial sketch - the one that worked?!

  • Mod

    Oh ok, I thought more time has passed. Never mind then. Maybe could be a faulty electronics: it can happen that faulty components break after few hours or days

  • o.k., quick update... contrary to what I reported yesterday, it now looks like my gateway is getting sensor readings from the node in question at irregular intervals. strangely enough, when I connect my Mac and launch the serial monitor, the sensor printout still stops after just the few lines above. Has anybody ever experienced something like this before?

    Still need to do the hardware swapping to see if this is related to a malfunction of any of the components.

Log in to reply

Suggested Topics