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. Troubleshooting
  3. gw.present(sensor, S_LIGHT) - hangs on 4th sensor

gw.present(sensor, S_LIGHT) - hangs on 4th sensor

Scheduled Pinned Locked Moved Troubleshooting
10 Posts 4 Posters 3.3k 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.
  • afulkiA Offline
    afulkiA Offline
    afulki
    wrote on last edited by
    #1

    I edited the RelayActuator sketch to include 4 relays, on pins 3 to 6. I was having an issue controlling them so dug further, I can only see 3 of the 4 sensors in MYSController and added some serial debugging to the sketch to pinpoint where things are going wrong.

    This is the output:

    send: 2-2-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
    send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-2 s=255,c=3,t=15,pt=0,l=1,sg=0:0
    read: 0-0-2 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=2, parent=0, distance=1
    send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=ok:Desk Power Relay
    send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    Init Sensor : 1, pin 3
    before present...
    send: 2-2-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    before pinMode...
    Sensor configured - OK!
    
    Init Sensor : 2, pin 4
    before present...
    send: 2-2-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    before pinMode...
    Sensor configured - OK!
    
    Init Sensor : 3, pin 5
    before present...
    send: 2-2-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    before pinMode...
    Sensor configured - OK!
    
    Init Sensor : 4, pin 6
    before present...
    

    The code was modified as follows:

      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        Serial.print("Init Sensor : ");
        Serial.print(sensor);
        Serial.print(", pin ");
        Serial.println(pin);
    
        // Register all sensors to gw (they will be created as child devices)
        Serial.println("before present...");
        gw.present(sensor, S_LIGHT);
        // Then set relay pins in output mode
        
        Serial.println("before pinMode...");
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        Serial.println("Sensor configured - OK!"); 
        Serial.println();   
      } 
    

    On the 4th sensor, it never gets past the present line.

    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      How do you power your sensor, and what capactítor(s) are you using? (Step 5 in http://forum.mysensors.org/topic/666/how-to-ask-for-help )
      Adding a 100-250ms delay after each present seems to help people, you could see if that helps in your case as well.

      1 Reply Last reply
      0
      • afulkiA Offline
        afulkiA Offline
        afulki
        wrote on last edited by
        #3

        HI, thanks for the prompt reply.

        I'm powering it via the 3.3v pin on an Arduino Nano (which is powered from the USB). I have a capacitor across the RF board (470uF).

        I added the delay(250) after the present, and the 4th completed this time (after about 2-3s).

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

          @afulki What did you change in the default sketch i've tried to reproduce you issue with this 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 - Henrik Ekblad
           * 
           * DESCRIPTION
           * Example sketch showing how to control physical relays. 
           * This example will remember relay state after power failure.
           * http://www.mysensors.org/build/relay
           */ 
          
          #include <MySigningNone.h>
          #include <MyTransportNRF24.h>
          #include <MyTransportRFM69.h>
          #include <MyHwATMega328.h>
          #include <MySensor.h>
          #include <SPI.h>
          
          #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
          #define NUMBER_OF_RELAYS 4 // Total number of attached relays
          #define RELAY_ON 1  // GPIO value to write to turn on attached relay
          #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
          
          // NRFRF24L01 radio driver (set low transmit power by default) 
          MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
          //MyTransportRFM69 radio;
          // Message signing driver (none default)
          //MySigningNone signer;
          // Select AtMega328 hardware profile
          MyHwATMega328 hw;
          // Construct MySensors library
          MySensor gw(radio, hw);
          
          void setup()  
          {   
            // Initialize library and add callback for incoming messages
            gw.begin(incomingMessage, AUTO, false);
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("Relay", "1.0");
          
            // Fetch relay status
             for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
              Serial.print("Init Sensor : ");
              Serial.print(sensor);
              Serial.print(", pin ");
              Serial.println(pin);
          
              // Register all sensors to gw (they will be created as child devices)
              Serial.println("before present...");
              gw.present(sensor, S_LIGHT);
              // Then set relay pins in output mode
              
              Serial.println("before pinMode...");
              pinMode(pin, OUTPUT);   
              // Set relay to last known state (using eeprom storage) 
              digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
              Serial.println("Sensor configured - OK!"); 
              Serial.println();   
            } 
          }
          
          
          void loop() 
          {
            // Alway process incoming messages whenever possible
            gw.process();
          }
          
          void incomingMessage(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.type==V_LIGHT) {
               // Change relay state
               digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
               // Store state in eeprom
               gw.saveState(message.sensor, message.getBool());
               // Write some debug info
               Serial.print("Incoming change for sensor:");
               Serial.print(message.sensor);
               Serial.print(", New status: ");
               Serial.println(message.getBool());
             } 
          }
          

          And my serial monitor shows this output

          send: 11-11-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
          send: 11-11-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
          send: 11-11-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
          sensor started, id=11, parent=0, distance=1
          send: 11-11-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,st=ok:Relay
          send: 11-11-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
          Init Sensor : 1, pin 3
          before present...
          send: 11-11-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
          before pinMode...
          Sensor configured - OK!
          
          Init Sensor : 2, pin 4
          before present...
          send: 11-11-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
          before pinMode...
          Sensor configured - OK!
          
          Init Sensor : 3, pin 5
          before present...
          send: 11-11-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
          before pinMode...
          Sensor configured - OK!
          
          Init Sensor : 4, pin 6
          before present...
          send: 11-11-0-0 s=4,c=0,t=3,pt=0,l=0,sg=0,st=ok:
          before pinMode...
          Sensor configured - OK!
          

          Just before this line

          sensor started, id=11, parent=0, distance=1
          

          i see 2 more lines in your log , did you add something before the for loop?

          afulkiA 1 Reply Last reply
          0
          • afulkiA Offline
            afulkiA Offline
            afulki
            wrote on last edited by
            #5

            Hi BartE,

            This is the source, I switched around the relay high low, the name of the sketch and the false on the begin statement. I have no idea where those two extra lines come from, but will try to track them down.

            #include <MySigningNone.h>
            #include <MyTransportNRF24.h>
            #include <MyTransportRFM69.h>
            #include <MyHwATMega328.h>
            #include <MySensor.h>
            #include <SPI.h>
            
            #define RELAY_1  PD3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
            #define NUMBER_OF_RELAYS 4 // Total number of attached relays
            #define RELAY_ON 0  // GPIO value to write to turn on attached relay
            #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
            
            // NRFRF24L01 radio driver (set low transmit power by default) 
            MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
            //MyTransportRFM69 radio;
            // Message signing driver (none default)
            //MySigningNone signer;
            // Select AtMega328 hardware profile
            MyHwATMega328 hw;
            // Construct MySensors library
            MySensor gw(radio, hw);
            
            void setup()  
            {   
              // Initialize library and add callback for incoming messages
              gw.begin(incomingMessage, AUTO, false);
              // Send the sketch version information to the gateway and Controller
              gw.sendSketchInfo("Desk Power Relay", "1.0");
            
              // Fetch relay status
              for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
                Serial.print("Init Sensor : ");
                Serial.print(sensor);
                Serial.print(", pin ");
                Serial.println(pin);
            
                // Register all sensors to gw (they will be created as child devices)
                Serial.println("before present...");
                gw.present(sensor, S_LIGHT);
                delay(250);
                // Then set relay pins in output mode
                
                Serial.println("before pinMode...");
                pinMode(pin, OUTPUT);   
                // Set relay to last known state (using eeprom storage) 
                digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                Serial.println("Sensor configured - OK!");    
              }
            }
            
            
            void loop() 
            {
              // Alway process incoming messages whenever possible
              gw.process();
            }
            
            void incomingMessage(const MyMessage &message) {
              // We only expect one type of message from controller. But we better check anyway.
              if (message.type==V_LIGHT) {
                 // Change relay state
                 digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                 // Store state in eeprom
                 gw.saveState(message.sensor, message.getBool());
                 // Write some debug info
                 Serial.print("Incoming change for sensor:");
                 Serial.print(message.sensor);
                 Serial.print(", New status: ");
                 Serial.println(message.getBool());
               } 
            }
            
            
            1 Reply Last reply
            0
            • sundberg84S Offline
              sundberg84S Offline
              sundberg84
              Hardware Contributor
              wrote on last edited by
              #6

              Could be unrelated but if all fails I had this issue with a normal reed switch sensor. Worked great for some time but always dead sooner or later. Never found out what the problem was but uploaded same sketch to another hardware and everything was ok.

              Controller: Proxmox VM - Home Assistant
              MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
              MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
              RFLink GW - Arduino Mega + RFLink Shield, 433mhz

              afulkiA 1 Reply Last reply
              0
              • sundberg84S sundberg84

                Could be unrelated but if all fails I had this issue with a normal reed switch sensor. Worked great for some time but always dead sooner or later. Never found out what the problem was but uploaded same sketch to another hardware and everything was ok.

                afulkiA Offline
                afulkiA Offline
                afulki
                wrote on last edited by
                #7

                @sundberg84

                I switched out both the radio and the nano, it seems to be the nano, the new one initialized fine with both radios. As a software guy my first response should have been that it was a hardware issue! :smiling_imp:

                Thanks for the help!

                Gary

                1 Reply Last reply
                0
                • BartEB BartE

                  @afulki What did you change in the default sketch i've tried to reproduce you issue with this 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 - Henrik Ekblad
                   * 
                   * DESCRIPTION
                   * Example sketch showing how to control physical relays. 
                   * This example will remember relay state after power failure.
                   * http://www.mysensors.org/build/relay
                   */ 
                  
                  #include <MySigningNone.h>
                  #include <MyTransportNRF24.h>
                  #include <MyTransportRFM69.h>
                  #include <MyHwATMega328.h>
                  #include <MySensor.h>
                  #include <SPI.h>
                  
                  #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                  #define NUMBER_OF_RELAYS 4 // Total number of attached relays
                  #define RELAY_ON 1  // GPIO value to write to turn on attached relay
                  #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
                  
                  // NRFRF24L01 radio driver (set low transmit power by default) 
                  MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
                  //MyTransportRFM69 radio;
                  // Message signing driver (none default)
                  //MySigningNone signer;
                  // Select AtMega328 hardware profile
                  MyHwATMega328 hw;
                  // Construct MySensors library
                  MySensor gw(radio, hw);
                  
                  void setup()  
                  {   
                    // Initialize library and add callback for incoming messages
                    gw.begin(incomingMessage, AUTO, false);
                    // Send the sketch version information to the gateway and Controller
                    gw.sendSketchInfo("Relay", "1.0");
                  
                    // Fetch relay status
                     for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
                      Serial.print("Init Sensor : ");
                      Serial.print(sensor);
                      Serial.print(", pin ");
                      Serial.println(pin);
                  
                      // Register all sensors to gw (they will be created as child devices)
                      Serial.println("before present...");
                      gw.present(sensor, S_LIGHT);
                      // Then set relay pins in output mode
                      
                      Serial.println("before pinMode...");
                      pinMode(pin, OUTPUT);   
                      // Set relay to last known state (using eeprom storage) 
                      digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                      Serial.println("Sensor configured - OK!"); 
                      Serial.println();   
                    } 
                  }
                  
                  
                  void loop() 
                  {
                    // Alway process incoming messages whenever possible
                    gw.process();
                  }
                  
                  void incomingMessage(const MyMessage &message) {
                    // We only expect one type of message from controller. But we better check anyway.
                    if (message.type==V_LIGHT) {
                       // Change relay state
                       digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                       // Store state in eeprom
                       gw.saveState(message.sensor, message.getBool());
                       // Write some debug info
                       Serial.print("Incoming change for sensor:");
                       Serial.print(message.sensor);
                       Serial.print(", New status: ");
                       Serial.println(message.getBool());
                     } 
                  }
                  

                  And my serial monitor shows this output

                  send: 11-11-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
                  send: 11-11-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
                  send: 11-11-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
                  sensor started, id=11, parent=0, distance=1
                  send: 11-11-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,st=ok:Relay
                  send: 11-11-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
                  Init Sensor : 1, pin 3
                  before present...
                  send: 11-11-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
                  before pinMode...
                  Sensor configured - OK!
                  
                  Init Sensor : 2, pin 4
                  before present...
                  send: 11-11-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
                  before pinMode...
                  Sensor configured - OK!
                  
                  Init Sensor : 3, pin 5
                  before present...
                  send: 11-11-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
                  before pinMode...
                  Sensor configured - OK!
                  
                  Init Sensor : 4, pin 6
                  before present...
                  send: 11-11-0-0 s=4,c=0,t=3,pt=0,l=0,sg=0,st=ok:
                  before pinMode...
                  Sensor configured - OK!
                  

                  Just before this line

                  sensor started, id=11, parent=0, distance=1
                  

                  i see 2 more lines in your log , did you add something before the for loop?

                  afulkiA Offline
                  afulkiA Offline
                  afulki
                  wrote on last edited by
                  #8

                  @BartE

                  I added some extra logging (yes even more) and the 2 extra lines are sent during the gw.begin, I think the

                  send: 3-3-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
                  

                  Is telling the gateway about the arduino node (could be wrong still looking through the code).

                  Gary

                  1 Reply Last reply
                  0
                  • afulkiA Offline
                    afulkiA Offline
                    afulki
                    wrote on last edited by
                    #9

                    I spoke too soon, it's back to not initializing the 4th output, or rather no doing returning from gw.present();

                    1 Reply Last reply
                    0
                    • afulkiA Offline
                      afulkiA Offline
                      afulki
                      wrote on last edited by
                      #10

                      I added a lot more debug output and find that it gets stuck in here:

                      	while( ! ( get_status()  & ( _BV(TX_DS) | _BV(MAX_RT) ))) {
                      		#if defined (FAILURE_HANDLING)
                      			if(millis() - timer > 75){
                      				errNotify();
                      
                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      14

                      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