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. Startup time of arduino pro mini with mysensors 2.2 - took 10 sec (guess its the radio), can I execute some code immediately (<1sec)?

Startup time of arduino pro mini with mysensors 2.2 - took 10 sec (guess its the radio), can I execute some code immediately (<1sec)?

Scheduled Pinned Locked Moved Troubleshooting
22 Posts 4 Posters 3.6k Views 5 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.
  • A Offline
    A Offline
    alterfritz
    wrote on last edited by
    #1

    Hi,

    just encounter an issue I need help on. I'm new to mysensors . Try to upgrade some of my LEDs with DimmableLED Sensors. I'm using the current development branch for 2.2 as I had issues with the radio on 2.1.

    All fine - I created a small ardunio mini with the radio and and MOSFET for switching, works. But then I encounter an issue: every time I switch on the led with the wall switch it tooks a few seconds >10 to get ON. I want it immediately to go ON with 100%, then getting old value from gateway. I tested with a simple sketch without mysensors - it switches almost immediately , especially without bootloader.

    So I guess this is related to the startup time of the mysensors lib, any way to place some code somewhere it get executed ASAP?

    Like "analogWrite( LED_PIN, 255);" to switch LED ON in milisecs, not secs?

    Thanks!
    Joerg

    A 1 Reply Last reply
    0
    • A alterfritz

      Hi,

      just encounter an issue I need help on. I'm new to mysensors . Try to upgrade some of my LEDs with DimmableLED Sensors. I'm using the current development branch for 2.2 as I had issues with the radio on 2.1.

      All fine - I created a small ardunio mini with the radio and and MOSFET for switching, works. But then I encounter an issue: every time I switch on the led with the wall switch it tooks a few seconds >10 to get ON. I want it immediately to go ON with 100%, then getting old value from gateway. I tested with a simple sketch without mysensors - it switches almost immediately , especially without bootloader.

      So I guess this is related to the startup time of the mysensors lib, any way to place some code somewhere it get executed ASAP?

      Like "analogWrite( LED_PIN, 255);" to switch LED ON in milisecs, not secs?

      Thanks!
      Joerg

      A Offline
      A Offline
      alterfritz
      wrote on last edited by
      #2

      @alterfritz ... one thing to add: of cause I tried adding it 1st line in setup(), does not work.

      1 Reply Last reply
      0
      • rozpruwaczR Offline
        rozpruwaczR Offline
        rozpruwacz
        wrote on last edited by
        #3

        @alterfritz said in Startup time of arduino pro mini with mysensors 2.2 - took 10 sec (guess its the radio), can I execute some code immediately (<1sec)?:

        d with the w

        If I correctly understood your setup you have wall switch on the high AC voltage side ? why not make it on the low voltage side ? the arduino can be powered all the time and your problem is gone.

        A 1 Reply Last reply
        0
        • M Offline
          M Offline
          manutremo
          wrote on last edited by
          #4

          In order to try help you find out... please share your sketch, serial output... which radio are you using... what makes you think it's the radio?

          A 1 Reply Last reply
          0
          • rozpruwaczR rozpruwacz

            @alterfritz said in Startup time of arduino pro mini with mysensors 2.2 - took 10 sec (guess its the radio), can I execute some code immediately (<1sec)?:

            d with the w

            If I correctly understood your setup you have wall switch on the high AC voltage side ? why not make it on the low voltage side ? the arduino can be powered all the time and your problem is gone.

            A Offline
            A Offline
            alterfritz
            wrote on last edited by
            #5

            @rozpruwacz its a normal wall switch, using 220v. The LED using a ac-dc converter with 5v output. I use pro mini with 3.3v on raw input. seesm to work, however when I switch on it took around 10 sec, even I place analogWrite( LED_PIN, 255); 1st line in setup().

            1 Reply Last reply
            0
            • M manutremo

              In order to try help you find out... please share your sketch, serial output... which radio are you using... what makes you think it's the radio?

              A Offline
              A Offline
              alterfritz
              wrote on last edited by
              #6

              @manutremo

              here it is - mostly the example... I'm using NRF24L01. Why the radio - I can check messages on gateway / mqtt (on raspPi). Took them around 10 sec to show up...

              /**

              • 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 - February 15, 2014 - Bruce Lacey
              • Version 1.1 - August 13, 2014 - Converted to 1.4 (hek)
              • DESCRIPTION
              • This sketch provides a Dimmable LED Light using PWM and based Henrik Ekblad
              • henrik.ekblad@gmail.com Vera Arduino Sensor project.
              • Developed by Bruce Lacey, inspired by Hek's MySensor's example sketches.
              • The circuit uses a MOSFET for Pulse-Wave-Modulation to dim the attached LED or LED strip.
              • The MOSFET Gate pin is connected to Arduino pin 3 (LED_PIN), the MOSFET Drain pin is connected
              • to the LED negative terminal and the MOSFET Source pin is connected to ground.
              • This sketch is extensible to support more than one MOSFET/PWM dimmer per circuit.
              • http://www.mysensors.org/build/dimmer
                */

              // Enable debug prints to serial monitor
              #define MY_DEBUG
              //#define MY_NODE_ID

              // Enable and select radio type attached
              #define MY_RADIO_NRF24
              //#define MY_RADIO_NRF5_ESB
              //#define MY_RADIO_RFM69
              //#define MY_RADIO_RFM95

              #include <MySensors.h>

              #define EPROM_LIGHT_STATE 1
              #define EPROM_DIMMER_LEVEL 2
              #define LIGHT_OFF 0
              #define LIGHT_ON 1

              #define SN "WallLight6"
              #define SV "1.0"
              #define CHILD_ID_LIGHT 1
              #define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
              #define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)

              static int16_t currentLevel = 0; // Current dim level...
              MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
              MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);

              int16_t LastLightState=LIGHT_OFF;
              int16_t LastDimValue=100;

              /***

              • Dimmable LED initialization method
                */
                void setup()
                {
                // Pull the gateway's current dim level - restore light level upon sendor node power-up
                //request( CHILD_ID_LIGHT, V_DIMMER );
                //Serial.println( "Node ready to receive messages..." );

                int LightState=loadState(EPROM_LIGHT_STATE);
                if (LightState<=1) {
                LastLightState=LightState;
                int DimValue=loadState(EPROM_DIMMER_LEVEL);
                if ((DimValue>0)&&(DimValue<=100)) {
                //There should be no Dim value of 0, this would mean LIGHT_OFF
                LastDimValue=DimValue;
                }
                }

              //Here you actualy switch on/off the light with the last known dim level
              SetCurrentState2Hardware();

              Serial.println( "Node ready to receive messages..." );

              }

              void presentation()
              {
              // Register the LED Dimmable Light with the gateway
              sendSketchInfo(SN, SV);

              present( CHILD_ID_LIGHT, S_DIMMER );
              

              }

              /***

              • Dimmable LED main processing loop
                */
                void loop()
                {
                }

              void receive(const MyMessage &message)
              {
              if (message.type == V_LIGHT || message.type == V_DIMMER) {

              	//  Retrieve the power or dim level from the incoming request message
              	int requestedLevel = atoi( message.data );
              
              	// Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
              	requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
              
              	// Clip incoming level to valid range of 0 to 100
              	requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
              	requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
              
              	Serial.print( "Changing level to " );
              	Serial.print( requestedLevel );
              	Serial.print( ", from " );
              	Serial.println( currentLevel );
              
              	fadeToLevel( requestedLevel );
              saveState(EPROM_DIMMER_LEVEL, requestedLevel);
              
              	// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
              	send(lightMsg.set(currentLevel > 0));
              
              	// hek comment: Is this really nessesary?
              	send( dimmerMsg.set(currentLevel) );
              
              
              }
              

              }

              /***

              • This method provides a graceful fade up/down effect
                */
                void fadeToLevel( int toLevel )
                {

                int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;

                while ( currentLevel != toLevel ) {
                currentLevel += delta;
                analogWrite( LED_PIN, (int)(currentLevel / 100. * 255) );
                delay( FADE_DELAY );
                }
                }

              void SetCurrentState2Hardware()
              {
              if (LastLightState==LIGHT_OFF) {
              Serial.println( "Light state: OFF" );
              } else {
              Serial.print( "Light state: ON, Level: " );
              Serial.println( LastDimValue );
              }

              //Send current state to the controller
              SendCurrentState2Controller();
              }

              void SendCurrentState2Controller()
              {
              if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
              send(dimmerMsg.set((int16_t)0));
              } else {
              send(dimmerMsg.set(LastDimValue));
              }
              }

              1 Reply Last reply
              0
              • rozpruwaczR Offline
                rozpruwaczR Offline
                rozpruwacz
                wrote on last edited by
                #7

                and why You choosed that design ? you are not able to switch on the lights remotely.

                A 1 Reply Last reply
                0
                • rozpruwaczR rozpruwacz

                  and why You choosed that design ? you are not able to switch on the lights remotely.

                  A Offline
                  A Offline
                  alterfritz
                  wrote on last edited by
                  #8

                  @rozpruwacz This is the way it was constructed. I plan to leave them on all time, maybe remove / replace them in the future - however if somebody uses the switches the lights should go on instantly, basically by set analogWrite( LED_PIN,255); like a normal switch.

                  Any way to do so?

                  rejoe2R 1 Reply Last reply
                  0
                  • A alterfritz

                    @rozpruwacz This is the way it was constructed. I plan to leave them on all time, maybe remove / replace them in the future - however if somebody uses the switches the lights should go on instantly, basically by set analogWrite( LED_PIN,255); like a normal switch.

                    Any way to do so?

                    rejoe2R Offline
                    rejoe2R Offline
                    rejoe2
                    wrote on last edited by
                    #9

                    @alterfritz
                    Try to add the "on" command not in setup() (this requires presetation() to be already passed) and use a before()-routine instead.

                    Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                    A 1 Reply Last reply
                    0
                    • rozpruwaczR Offline
                      rozpruwaczR Offline
                      rozpruwacz
                      wrote on last edited by
                      #10

                      So I would rather make it in hardware. pull-up resistor on the switching transistor will make it on at the powerup. and I would store the last dimm value into eeprom to not wait for the gateway response because you will not make it response in less that 1s - the protocol just not allow for that.

                      rejoe2R 1 Reply Last reply
                      0
                      • rozpruwaczR rozpruwacz

                        So I would rather make it in hardware. pull-up resistor on the switching transistor will make it on at the powerup. and I would store the last dimm value into eeprom to not wait for the gateway response because you will not make it response in less that 1s - the protocol just not allow for that.

                        rejoe2R Offline
                        rejoe2R Offline
                        rejoe2
                        wrote on last edited by
                        #11

                        @rozpruwacz Exactly. This is why the "on" should be issued in before() (or something like hwInit()).
                        "before()" is executed before any MySensors-specific communication....

                        Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          manutremo
                          wrote on last edited by
                          #12

                          In addition to the other advices you're already receiving, and following your suspicion that the delay might be related to the radio, you could try adding the following defines to your sketch:

                          #define MY_PARENT_NODE_ID 0
                          #define MY_PARENT_NODE_IS_STATIC
                          #define MY_TRANSPORT_MAX_TX_FAILURES 3
                          

                          The first two avoid the node from having to search for it.

                          The last one might help you determine if the problem is the radio not starting correctly if the time is reduced after you add it.

                          Let us know how it goes.

                          1 Reply Last reply
                          0
                          • rozpruwaczR Offline
                            rozpruwaczR Offline
                            rozpruwacz
                            wrote on last edited by
                            #13

                            yes, so in the before() function read the eeprom value and set it in analogWrite. hardware pull-up is optional because the delay between switching power on and before function call will be short enough, bit if You use the pull-up the delay will be even shorter.

                            1 Reply Last reply
                            0
                            • rejoe2R rejoe2

                              @alterfritz
                              Try to add the "on" command not in setup() (this requires presetation() to be already passed) and use a before()-routine instead.

                              A Offline
                              A Offline
                              alterfritz
                              wrote on last edited by
                              #14

                              @rejoe2 like this... btw - this forum is fanastic... responses more or less in real time... :-)

                              ...
                              void presentation()
                              {
                              analogWrite( LED_PIN,255);

                              }
                              ....

                              A 1 Reply Last reply
                              0
                              • A alterfritz

                                @rejoe2 like this... btw - this forum is fanastic... responses more or less in real time... :-)

                                ...
                                void presentation()
                                {
                                analogWrite( LED_PIN,255);

                                }
                                ....

                                A Offline
                                A Offline
                                alterfritz
                                wrote on last edited by
                                #15

                                @alterfritz

                                sorry ... mean before ...like this

                                void before()
                                {
                                analogWrite( LED_PIN,255);

                                }

                                This seems to have done the trick... LED switch on immediately! Thanks!

                                Btw... I also try the mysbootloader. This wirless update is great, however - does this bootloader slows down bootup time?

                                1 Reply Last reply
                                0
                                • rozpruwaczR Offline
                                  rozpruwaczR Offline
                                  rozpruwacz
                                  wrote on last edited by
                                  #16

                                  yes, because the code that will run in the node must be first uploaded to it. the bootup time will be dependent on the code size.

                                  1 Reply Last reply
                                  0
                                  • rejoe2R Offline
                                    rejoe2R Offline
                                    rejoe2
                                    wrote on last edited by rejoe2
                                    #17

                                    @alterfritz Yes, update-bootloader tries to connect to GW for updates first seconds (around 20). So it is not dependend on code size...
                                    Additional note: Waiting for RF connection to be established can also be prevented by using

                                    #define MY_TRANSPORT_WAIT_READY_MS ...
                                    

                                    Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                                    A 1 Reply Last reply
                                    0
                                    • rejoe2R rejoe2

                                      @alterfritz Yes, update-bootloader tries to connect to GW for updates first seconds (around 20). So it is not dependend on code size...
                                      Additional note: Waiting for RF connection to be established can also be prevented by using

                                      #define MY_TRANSPORT_WAIT_READY_MS ...
                                      
                                      A Offline
                                      A Offline
                                      alterfritz
                                      wrote on last edited by
                                      #18

                                      @rejoe2

                                      So
                                      #define MY_TRANSPORT_WAIT_READY_MS 1000
                                      Will wait for 1 sec?

                                      rejoe2R 1 Reply Last reply
                                      0
                                      • A alterfritz

                                        @rejoe2

                                        So
                                        #define MY_TRANSPORT_WAIT_READY_MS 1000
                                        Will wait for 1 sec?

                                        rejoe2R Offline
                                        rejoe2R Offline
                                        rejoe2
                                        wrote on last edited by
                                        #19

                                        @alterfritz Exactly. After trying to connect to the controller for 1 sec., the node will execute normal code like any other "just-arduino".
                                        Pls note: as there is no connection to the controller, the node may miss relevant info typically provided by the controller. Things like myControllerConfig, last values for counters etc... If you use this, you should make sure, these are set correctly later on.

                                        Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          alterfritz
                                          wrote on last edited by
                                          #20

                                          So - thanks for all your help. Great forum. Let me summarize what I understand so far:

                                          1.) by using the before() procedbure I can execute immediately. Quickly tested. Seems perfect for me... however... :-)
                                          2.) I really like this mysbootloader. But by using this it always takes up around 20 sec to boot up. There is NO way to switch on my LED directly when I power it up...

                                          Correct?

                                          rejoe2R 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          20

                                          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