Using before()


  • Hardware Contributor

    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()?


  • Mod

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


  • Mod

    @Yveaux lokks like VER=2.0.1-beta


  • Mod

    @mfalkvidd said:

    @Yveaux lokks like VER=2.0.1-beta

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


  • Mod

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


  • Hardware Contributor

    Hi,

    Indeed it is 2.0.1 beta.

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

    Thanks.


  • Hardware Contributor

    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.


  • Hardware Contributor

    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?


  • Mod

    @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?


Log in to reply
 

Suggested Topics

20
Online

11.2k
Users

11.1k
Topics

112.5k
Posts