Sensor doesn´t reconnect after connecting lost!?

  • Hi,
    i have sensor, and when it lose connection to the controller, it does´t reconnect.

    Serial Print after losing connection is like this:

    find parent
    send: 48-48-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:

    Even if i put the sensor direct beside the controller gateway, it doesn´t reconnect.

    is there a special way to trying to reconnect?

    if it helps, here is my sketch:

    // EEPROM Zurgiff ermöglichen
    #include <EEPROM.h>
    byte value;
    int tf_adr = 100;
    // Sleep Mode Libraries laden
    #include <avr/sleep.h>
    #include <avr/power.h> 
    // MySensor Library hinzufügen
    #include <SPI.h>
    #include <MySensor.h> 
    #define CHILD_ID 0   // Id of the sensor child
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
    //Definieren welche Sensor-ID die nachricht schickt 
    //und welcher Variablen-Typ übermittelt wird. (V_LEVEL ist in S_MOISTURE möglich)
    // Entsprechend der Sensor-Liste und Variablen-Liste
    MySensor gw;
    MyMessage flowMsg(CHILD_ID,V_FLOW);
    MyMessage volumeMsg(CHILD_ID,V_VOLUME);
    // reading liquid flow rate using Seeeduino and Water Flow Sensor from
    // Code adapted by Charles Gantt from PC Fan RPM code written by Crenn
    // http:/
    volatile int NbTopsFan; //measuring the rising edges of the signal
    float Calc;                               
    int hallsensor = 3;    //The pin location of the sensor
    int flow_sens_vcc = 7;
    unsigned int flowMilliLitres;
    unsigned int lastFlowVal;
    long totalMilliLitres;
    long lastTotalVal;
    void rpm ()     //This is the function that the interupt calls 
      NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
    //This function will write a 4 byte (32bit) long to the eeprom at
    //the specified address to address + 3.
    void EEPROMWritelong(int address, long value)
          //Decomposition from a long to 4 bytes by using bitshift.
          //One = Most significant -> Four = Least significant byte
          byte four = (value & 0xFF);
          byte three = ((value >> 8) & 0xFF);
          byte two = ((value >> 16) & 0xFF);
          byte one = ((value >> 24) & 0xFF);
          //Write the 4 bytes into the eeprom memory.
          EEPROM.write(address, four);
          EEPROM.write(address + 1, three);
          EEPROM.write(address + 2, two);
          EEPROM.write(address + 3, one);
    long EEPROMReadlong(long address)
          //Read the 4 bytes from the eeprom memory.
          long four =;
          long three = + 1);
          long two = + 2);
          long one = + 3);
          //Return the recomposed long by using bitshift.
          return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
    // The setup() method runs once, when the sketch starts
    void setup() //
      // Start Gateway Kommunikation
      //gw.begin(NULL, 2);     // assign fixed node id 2  (use anything from 1..254) Wenn kein COntroller angeschlossen ist der die NODE ID vergeben kann!;
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Water Flow Sensor", "1.0");     
      // Register all sensors to gw (they will be created as child devices)  
      gw.present(CHILD_ID, S_WATER);
      pinMode(flow_sens_vcc, OUTPUT);
      digitalWrite(flow_sens_vcc, HIGH);
      pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
      attachInterrupt(1, rpm, RISING); //and the interrupt is attached 1 = Digital Pin 3!
      // TotalFlow zurücksetzten
      EEPROMWritelong(tf_adr, 000000000);
      // Toralflow aus dem Speicher lesen
      totalMilliLitres = EEPROMReadlong(tf_adr);
      // Batteriestatus
      // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
    // the loop() method runs over and over again,
    // as long as the Arduino has power
    void loop ()    
    // Schlafmodus: entweder sensor auschalten, dann oft aufwachen zum checken ob was läuft, -> hoche wakeup frequenz aber im sleep 10sec 20uA! 2sec 6mA, 2sec 19mA
    //   oder sensor immer anlassen, dann aber dauerhaft 2mA!
     int sleepmode = 1;   // 1=Wakeup by Time (Sensor can be off) 2=wakeup by Interrupt (Sensor must leave on!)
     if(flowMilliLitres == 0){
        EEPROMWritelong(tf_adr, totalMilliLitres);
        Serial.print ("TotalFlow im EEPROM: "); 
        Serial.print ("\r\n");
        if(sleepmode == 1){
           delay (1000);   //Wait 1 second
           digitalWrite(flow_sens_vcc, LOW);
           gw.sleep(10000); //Schlafen gehen auf zeit (angabe milliseconds) dann spätestens kommt ein pol.
           digitalWrite(flow_sens_vcc, HIGH);
        if(sleepmode == 2){
           EEPROMWritelong(tf_adr, totalMilliLitres);
           Serial.print ("TotalFlow im EEPROM: "); 
           Serial.print ("\r\n");
           gw.sleep(1000000); //Schlafen gehen auf zeit (angabe milliseconds) dann spätestens kommt ein pol.
        NbTopsFan = 0;   //Set NbTops to 0 ready for calculations
        sei();      //Enables interrupts
        delay (1000);   //Wait 1 second
        cli();      //Disable interrupts
        Calc = (NbTopsFan / 7.5); //(Pulse frequency) / 7.5Q, = flow rate in L/min 
        Serial.print (Calc); //Prints the number calculated above
        Serial.print (" L/min\r\n"); //Prints "L/min" and returns a  new line
        int val=(int)Calc;
        // Divide the flow rate in litres/minute by 60 to determine how many litres have
        // passed through the sensor in this 1 second interval, then multiply by 1000 to
        // convert to millilitres.
        flowMilliLitres = (Calc / 60) * 1000;
        // Add the millilitres passed in this second to the cumulative total
        totalMilliLitres += flowMilliLitres;
      if(flowMilliLitres != 0){
        // Print the number of litres flowed in this second
        Serial.print("  Current Liquid Flowing: ");             // Output separator
        if(lastFlowVal != flowMilliLitres){
          lastFlowVal = flowMilliLitres;
        // Print the cumulative total of litres flowed since starting
        Serial.print("  Output Liquid Quantity: ");             // Output separator
        if(lastTotalVal != totalMilliLitres){
          lastTotalVal = totalMilliLitres;
          //Starting at the first byte on the eeprom.   
          //EEPROMWritelong(address, totalMilliLitres);
        // get the battery Voltage
         int sensorValue = analogRead(BATTERY_SENSE_PIN);
         #ifdef DEBUG
         // 1M, 470K divider across battery and using internal ADC ref of 1.1V
         // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
         // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
         // 3.44/1023 = Volts per bit = 0.003363075
         float batteryV  = sensorValue * 0.003363075;
         int batteryPcnt = sensorValue / 10;
         #ifdef DEBUG
         Serial.print("Battery Voltage: ");
         Serial.println(" V");
         Serial.print("Battery percent: ");
         Serial.println(" %");

  • Admin

    Is it possible to see anything in the gateway log when this happens?

  • the controller gateway doesn´t write anything to the log, when the sensor lose connection.

    when I start the sensor, it connects to the controller correctly. But wenn it is out of range, the connection will be lost, of course.
    but if the sensor is back in reachable distance, it will not be reconnecting.
    the Serial output of the sensor still stands at the above written lines, and do nothing anymore.

    only a restart of the sensor will establish a new connection.

    Is there a function for the sensor sketch to reconnect, when connection is broken?

  • Admin

    The broadcast message used when searching for parents is only transmitted once unlike the normal messages which is transmitted in quick bursts of several resends. So broadcasts is less likely to be picked up.

    Not sure what could be the issue for you. I suspect the usual powering/shielding issues.

  • @hek, thanks for your help so far!
    The sensor sends every 10 seconds data to the gateway.
    When the sensor is out of range, the transmitting fails 6 times and then stuck in "find parent" and do nothing anymore.
    Is there any counter, which catch the failed transmits in line?
    Does the "find parent" mode repeat in any intervals?
    may it is possible to repeat the interval more often?

  • Admin

    @vga said:

    Is there any counter, which catch the failed transmits in line?

    Yes, 5 failed sends in a row that triggers it.

    Does the "find parent" mode repeat in any intervals?

    Every time you try to send a new value and parent is lost, it will retry.

    Do you see a lot of transmission error when the node starts up?

  • When node is in range of gateway, there are no transmission errors on node when startup, and since the node stay in range, all went fine.

    so, when node went out of range and 5 transmits in row fails, the node starts to find the gateway again, but only for one time, and then hangs up.

  • Admin

    Weird... and you're sure the sketch continuous to run (and calls send)? It doesn't hang for some other reason in your code?

  • no, i think the sketch doesn´t work anymore.
    In Serial Monitor, after 5 fails, i can see the node calls "find parent" for one time, and after that there is nothing more happening in the serial monitor.

    but the sketch works fine all the time when transmutation is OK.

  • Mod

    It looks like you might be overwriting MySensor's routing information. That is likely to interfere with the node's ability to communicate. You should only write to EEPROM_LOCAL_CONFIG_ADDRESS and above.

  • hm, i´ve changed my eprom_write function, so that i only write to dresses above EEPROM_LOCAL_CONFIG_ADDRESS.
    this is 0x123 -> address 291, and now i begin to write at 300.

    but still the problem persists, after losing connection, no reconnect. 😕

  • Mod

    If you haven't already, run the clearEeprom sketch (Examples->MySensors). That will clear the corrupt routing table and let the sensor build a new table.

    If you eant, you can use MySesnor's saveState (described at ) instead of keeping track of the address manually. saveState will always write above the local config address.

  • @mfalkvidd
    now i´ve clears the EEPROM, and completely removed the part from sketch, with writing anything to EEPROM.

    still the same issue.
    i´m thinking about to rase the counter of fails in row, till connecting will be reinitialized.
    Sure, this is not the best way to do, but till i have no other clue, the best workaround for keeping it working.

    Or any more other ideas? 😉

  • btw,
    i downloaded the new library folder from github repo, thinking maybe there are some changes with this issue.

    Now i see, the whole MySensor function is changed, and i have to edit my sketches for the new way!?

    before update, i have to do this:
    MySensor gw;

    and now, this part is complete removed, am I right??

    is there any announcement for this changes? didn´t find anything about these changes.

  • Admin

  • Mod

    There is no announcement because it has not been released yet 🙂
    The default branch on github is the development (non-stable, non-released) version. It is assumed that developers use github and regular users use the download links in the official documentation (which points to the released version).

  • @hek said:

    Yes, 5 failed sends in a row that triggers it.

    oh, ok, I understand 🙂
    ...the link above refers to the beta, and i was wondering, why my library contains something else than this... so i just wait, thanks 😉

    ...but any other idea for the real topic issue? 😉

  • Hi!
    still have no solution for the topic-problem. 😞

    i tested both, the stable v1.5 mySensors and the beta v2.0.

    Both are working till connection is lost, then both version doesn´t reconnect. Same behavior again.

    i didn´t think it is because of some hardware issue, because it works, till connection is lost.
    also my code is reduced to the minimum, for testing this option, but same issue again.

    so there must be a problem with the "find parent" function.
    it looks like, when connection is lost and 5 send commands in line has been failed, the "find parent" is calling, but for some reason, the node sketch crashes.

    the last serial monitor output from node is this:

    find parent
    send: 48-48-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:

    ...and I got this only for one time, then nothing happens anymore, also my usual sketch operations doesn´t operate anymore and didn't make serial outputs.

    Is there nothing more i can do?? how does the reconnect is working normally?

  • @vga
    I'm having a similar problem, my battery powered motion sensors do not reconnect after going out of range, or when the controller is restarted. Restarting the sensor will allow it to reconnect to the controller.

    My mains powered motion sensors will reconnect automatically after the controller is restarted (I haven't tried taking them out of range whilst powered up). One battery powered motion sensor that is connected through a repeater node will stay connected/reconnect after the controller is restarted.

    I've cleared eeprom using the sketch on, for the controller and all nodes.

    I've tried with and without a capacitor on the radios.

    I've started with the 1.5 API and also the new 2.0 API.

    The battery powered nodes are all running a Sensebender Micro with 2 x 1.2v NiMH batteries, nRF24L01+ (from Itead), and a HC-SR501 PIR (running on the 3.3v input as on

    My next ideas are to try normal 1.5v batteries, powering the PIR from 5v on a separate power supply, and Arduino mini pros instead of Sensebenders.


  • Hi I have something similar, not sure if this is related to mysensors or the Agocontrol Home Automation.
    My scenario; My Agocontrol crashed due to corrupted SD card on my RPI, due to power outtage.
    I installed Agocontroll from scratch on a new SD card. copied most of my Agocontrol configuration files. (So I have now learned to use UPS for power backup)

    Then I plugged in my Zwave, Tellstick, Mysensors serial gateway (ver 1.5.4) and none of my sensors was accepted by the serial gateway.

    I would assume that all sensors would be found and accepted? But instead I have to reset each Arduino Pro Mini on the sensors, and this is for both battery powered and for Arduino Nano that is powered from mains via 5V USB PS

  • Admin

    @corbin Can you provide debug logs (on 2.0.0) of both, GW and node, showing what you described?

  • @tekka well after making the post above, it has started working 🙂

    Knowing that the Sensebenders operated perfectly as temp and humidity sensors with the sketch they were shipped with, I modified the Sensebender sketch ( to include motion , and added "#define MY_PARENT_NODE_ID 0". Previously I had been using the default MySensors Motion Sensor sketch.

    I'm hoping it keeps working, so far, so good!

  • @tekka said:

    @corbin Can you provide debug logs (on 2.0.0) of both, GW and node, showing what you described?

    It's been running well except for 1 node, this is the serial output, could it be damaged hardware?

    Stárting sensor (RNNNA-, 2.0.0)
    TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,ót=bc:
    TSP:MSG:REÁÄ 0-0-3 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAÒ REÓ (IÄ=0, äést=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSÐ:PING:SÅND (dest=0)
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,ô=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    ÔSP:MSG:READ 0-0-3 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    Óånsebender Micro FW 1.4 - Online!
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=ok:229
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 3-3-0-0 s=255,c=0,ô=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 3-3-0-0 s=255,ã=3,t=6,pt=1,l=1,sg=0,ft=0,st=ïk:0
    TSP:MSG:READ 0-0-3 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:ÍSG:READ 0-0-3 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=11,pt=0,l=17,sg=0,æt=0,st=ok:Senseâender Micro
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.4
    TSP:MSG:SEND 3-3-0-0 s=1,c=0,t=1,ðô=0,l=0,sg=0,æt=0,st=ok:
    TSP:MSG:SENÄ 3-3-0-0 s=199,c=0,t=13,pô=0,l=0,sg=0,ft=0,st=ok:
    Request regisôòation...
    TSP:MSG:SEND 3-3-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-3 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registòation=1
    Init complete, id=3, parent=0, distancå=1, registration=1
    TSP:MSG:SEND 3-3-0-0 s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=ok:0```