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. Development
  3. Using before()

Using before()

Scheduled Pinned Locked Moved Development
9 Posts 3 Posters 2.6k 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.
  • JapioJ Offline
    JapioJ Offline
    Japio
    Hardware Contributor
    wrote on last edited by
    #1

    Hi,

    I have created a "MyVersion" of the ESP8266 Mqtt gateway. To show detailed state of the gateway (things like message received, message sent, wifi connection and strength) I connected a Neopixel Stick (8 RGB leds) to the ESP8266.

    To initialize the leds I created a function setup_leds() that initializes the Neopixel library and does some sort of walking light across the RGB colors of each LED.

    So far no problems.

    However, when I call the setup_leds() from the void before() function, the gateway is not able to get an IP address. If I move this call to setup() it does get an ip address.

    This output is with setup_leds() in before():

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.0.1-beta
    0;255;3;0;9;MCO:BGN:BFR
    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 8
    cnt 
    
    connected with XXXX, channel x
    dhcp client start...
    ip:192.168.X.XX,mask:255.255.255.0,gw:192.168.X.XXX
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY
    f r0, scandone
    .pm open,type:2 0
    ............................................................................
    

    This reproduces 100% of the time. My question is: What is the problem here? Is it possible to use the before? Are there time constraints on placing code in before()?

    YveauxY 2 Replies Last reply
    0
    • JapioJ Japio

      Hi,

      I have created a "MyVersion" of the ESP8266 Mqtt gateway. To show detailed state of the gateway (things like message received, message sent, wifi connection and strength) I connected a Neopixel Stick (8 RGB leds) to the ESP8266.

      To initialize the leds I created a function setup_leds() that initializes the Neopixel library and does some sort of walking light across the RGB colors of each LED.

      So far no problems.

      However, when I call the setup_leds() from the void before() function, the gateway is not able to get an IP address. If I move this call to setup() it does get an ip address.

      This output is with setup_leds() in before():

      0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.0.1-beta
      0;255;3;0;9;MCO:BGN:BFR
      scandone
      state: 0 -> 2 (b0)
      state: 2 -> 3 (0)
      state: 3 -> 5 (10)
      add 0
      aid 8
      cnt 
      
      connected with XXXX, channel x
      dhcp client start...
      ip:192.168.X.XX,mask:255.255.255.0,gw:192.168.X.XXX
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSM:INIT:TSP OK
      0;255;3;0;9;TSM:INIT:GW MODE
      0;255;3;0;9;TSM:READY
      f r0, scandone
      .pm open,type:2 0
      ............................................................................
      

      This reproduces 100% of the time. My question is: What is the problem here? Is it possible to use the before? Are there time constraints on placing code in before()?

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @Japio what version of the mysensors library are you using?

      http://yveaux.blogspot.nl

      mfalkviddM 1 Reply Last reply
      0
      • YveauxY Yveaux

        @Japio what version of the mysensors library are you using?

        mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by
        #3

        @Yveaux lokks like VER=2.0.1-beta

        YveauxY 1 Reply Last reply
        0
        • mfalkviddM mfalkvidd

          @Yveaux lokks like VER=2.0.1-beta

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @mfalkvidd said:

          @Yveaux lokks like VER=2.0.1-beta

          Someone should post a topic requesting the code windows to be enlarged :blush:

          http://yveaux.blogspot.nl

          1 Reply Last reply
          1
          • JapioJ Japio

            Hi,

            I have created a "MyVersion" of the ESP8266 Mqtt gateway. To show detailed state of the gateway (things like message received, message sent, wifi connection and strength) I connected a Neopixel Stick (8 RGB leds) to the ESP8266.

            To initialize the leds I created a function setup_leds() that initializes the Neopixel library and does some sort of walking light across the RGB colors of each LED.

            So far no problems.

            However, when I call the setup_leds() from the void before() function, the gateway is not able to get an IP address. If I move this call to setup() it does get an ip address.

            This output is with setup_leds() in before():

            0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.0.1-beta
            0;255;3;0;9;MCO:BGN:BFR
            scandone
            state: 0 -> 2 (b0)
            state: 2 -> 3 (0)
            state: 3 -> 5 (10)
            add 0
            aid 8
            cnt 
            
            connected with XXXX, channel x
            dhcp client start...
            ip:192.168.X.XX,mask:255.255.255.0,gw:192.168.X.XXX
            0;255;3;0;9;TSM:INIT
            0;255;3;0;9;TSM:INIT:TSP OK
            0;255;3;0;9;TSM:INIT:GW MODE
            0;255;3;0;9;TSM:READY
            f r0, scandone
            .pm open,type:2 0
            ............................................................................
            

            This reproduces 100% of the time. My question is: What is the problem here? Is it possible to use the before? Are there time constraints on placing code in before()?

            YveauxY Offline
            YveauxY Offline
            Yveaux
            Mod
            wrote on last edited by
            #5

            @Japio could you try with 2.1? Some things have changed in the startup order.

            http://yveaux.blogspot.nl

            1 Reply Last reply
            0
            • JapioJ Offline
              JapioJ Offline
              Japio
              Hardware Contributor
              wrote on last edited by
              #6

              Hi,

              Indeed it is 2.0.1 beta.

              Yes, I 'll try tonight, and report back on the result.

              Thanks.

              1 Reply Last reply
              1
              • JapioJ Offline
                JapioJ Offline
                Japio
                Hardware Contributor
                wrote on last edited by
                #7

                I installed 2.2.0 beta and indeed something has changed, but nothing that helps me:

                Placed the setup_led() in before():

                0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.2.0-beta
                0;255;3;0;9;MCO:BGN:BFR
                scandone
                state: 0 -> 2 (b0)
                state: 2 -> 3 (0)
                state: 3 -> 5 (10)
                add 0
                aid 8
                cnt 
                
                connected with XXXX, channel 6
                dhcp client start...
                ip:192.168.X.x,mask:255.255.255.0,gw:192.168.X.X
                Going to MySensors Application mode
                - Broker Ip Address: 192.168.X.X
                - Broker Port: 1883
                - Network name: XXXX
                0;255;3;0;9;TSF:LRT:OK
                0;255;3;0;9;TSM:INIT
                0;255;3;0;9;TSF:WUR:MS=0
                0;255;3;0;9;TSM:INIT:TSP OK
                0;255;3;0;9;TSM:INIT:GW MODE
                0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
                0;255;3;0;9;MCO:REG:NOT NEEDED
                f r0, scandone
                .....0;255;3;0;9;TSF:MSG:READ,20-20-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
                0;255;3;0;9;TSF:MSG:BC
                0;255;3;0;9;TSF:MSG:FPAR REQ,ID=20
                0;255;3;0;9;TSF:PNG:SEND,TO=0
                0;255;3;0;9;TSF:CKU:OK
                0;255;3;0;9;TSF:MSG:GWL OK
                0;255;3;0;9;TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
                ...0;255;3;0;9;TSF:MSG:READ,20-20-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
                0;255;3;0;9;TSF:MSG:PINGED,ID=20,HP=1
                0;255;3;0;9;TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
                ..0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2660
                0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
                pm open,type:2 0
                .....................0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2590
                0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
                .....................0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2590
                0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
                ..................
                

                Well, anyway. I moved the setup_led function to the setup() so I am ok for now. But this is still a weird situation.

                1 Reply Last reply
                0
                • JapioJ Offline
                  JapioJ Offline
                  Japio
                  Hardware Contributor
                  wrote on last edited by
                  #8

                  One more thing I just found out: if I take out the walking-light from the setup_led() it works fine as well.

                  As this takes some time, might there be some kind of race condition during initialization of the MySensors stack?

                  YveauxY 1 Reply Last reply
                  0
                  • JapioJ Japio

                    One more thing I just found out: if I take out the walking-light from the setup_led() it works fine as well.

                    As this takes some time, might there be some kind of race condition during initialization of the MySensors stack?

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #9

                    @Japio I think I've seen the esp start some wifi stuff in parallel to the arduino startup code. Could be that if the gateway setup is delayed the wifi will not start as expected.
                    You could use a timer, initialized from before() to cycle the leds during startup.
                    Just wondering, do you call some form of yield() during the led setup?

                    http://yveaux.blogspot.nl

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


                    10

                    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