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. mqtt_esp8266_gateway and 1mhz node

mqtt_esp8266_gateway and 1mhz node

Scheduled Pinned Locked Moved Troubleshooting
21 Posts 4 Posters 4.7k Views 2 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.
  • cimba007C cimba007

    @mfalkvidd

    I only recently got into the jboard and thought abou trying out 1mhz as described here:

    https://forum.mysensors.org/topic/3018/tutorial-how-to-burn-1mhz-8mhz-bootloader-using-arduino-ide-1-6-5-r5/64

    I plan to use the jboard with 2x AA so 3,0Volt and the only valid option is 1mhz.

    I can only guess that an esp8266 as an gateway in combination with 1mhz nodes is "special".

    Now I will check the esp8266 gateway code to look if there are some assumptions on delays etc.

    EDIT: For now I can see that the gatway is receiving the PING message .. and that the node is waiting.

    		transportRouteMessage(build(_msgTmp, _nc.nodeId, targetId, NODE_SENSOR_ID, C_INTERNAL, I_PING, false).set((uint8_t)0x01));
    		// Wait for ping reply or timeout
    		//Serial.print("WAITING");
    		transportWait(2000, C_INTERNAL, I_PONG);
    

    EDIT2: And that the gateway want's to send out the I_PONG

    my debug code got this

    WE GOT SOME PING?!11<\r><\n>
    We got an message for11 type: I_PONG<\r><\n>
    We got an message for11 type: OTHER<\r><\n>
    
    

    So .. let me try to state the timing:

    Node sends I_PING message to Gateway .. at 21:42:52,314
    Gateway receives I_PING at 21:42:52,281

    waiiiiittt .. the node is still debugging on the serial as the gateway already got the message like 25ms ago? This might be an artifact of my hterm serial console but lets assume it is right.

    gateway send I_PONG at 21:42:52,284

    So the gateway takes 3ms to process the message including serial overhead .. nice timing

    the node reports TSP:CHKUPL:FAIL (hops=255)<\n> at 21:42:54,404

    assuming transportWait(2000, C_INTERNAL, I_PONG); takes 2000ms then the node began listeing at

    21:42:52,404

    whereas the gateway responded at:

    21:42:52,281 .. so there seems a whopping 120ms delay caused by some serial output or just the slow 1mhz of the node ..

    The gateway already responded while the node didn't even move to the "LISTEN" code ..

    This is just a "rough guess" as the timings are only measured using my terminal program but I think this might narrow down my issue

    cimba007C Offline
    cimba007C Offline
    cimba007
    wrote on last edited by cimba007
    #12

    @mfalkvidd

    I might have been wrong regarding the timing.

    My latest test indicates gateway sends pong at:

    573.8

    Node starts listeing at

    572.8

    Still there is not too much time ...

    To be extra sure I popped an delay on the gateway side:

    	Serial.println(message.type == I_PONG ? "I_PONG" : "OTHER");
    	delay(2);
    	//Serial.println("")
    	bool ok = transportSendWrite(route, message);
    

    Now my node is working again .. I would say the whole issue is an race condition resulting from the great difference in speed.

    I found a workaround that is acceptable (for me at least):

    In MyTransport.cpp I added an delay(2).
    I_PING messages should not be too common to have an impact on battery life and the node now has enough time to switch to receiving mode.

    				// general
    				if (type == I_PING) {
    					delay(2);
    					//Serial.print("WE GOT SOME PING?!");
    					//Serial.println(sender);
    					debug(PSTR("TSP:MSG:PINGED (ID=%d, hops=%d)\n"), sender, _msg.getByte());
    					transportRouteMessage(build(_msgTmp, _nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_PONG, false).set((uint8_t)0x01));
    					return; // no further processing required
    				}
    

    https://github.com/mysensors/MySensors/issues/578

    tekkaT 1 Reply Last reply
    1
    • cimba007C cimba007

      @mfalkvidd

      I might have been wrong regarding the timing.

      My latest test indicates gateway sends pong at:

      573.8

      Node starts listeing at

      572.8

      Still there is not too much time ...

      To be extra sure I popped an delay on the gateway side:

      	Serial.println(message.type == I_PONG ? "I_PONG" : "OTHER");
      	delay(2);
      	//Serial.println("")
      	bool ok = transportSendWrite(route, message);
      

      Now my node is working again .. I would say the whole issue is an race condition resulting from the great difference in speed.

      I found a workaround that is acceptable (for me at least):

      In MyTransport.cpp I added an delay(2).
      I_PING messages should not be too common to have an impact on battery life and the node now has enough time to switch to receiving mode.

      				// general
      				if (type == I_PING) {
      					delay(2);
      					//Serial.print("WE GOT SOME PING?!");
      					//Serial.println(sender);
      					debug(PSTR("TSP:MSG:PINGED (ID=%d, hops=%d)\n"), sender, _msg.getByte());
      					transportRouteMessage(build(_msgTmp, _nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_PONG, false).set((uint8_t)0x01));
      					return; // no further processing required
      				}
      

      https://github.com/mysensors/MySensors/issues/578

      tekkaT Offline
      tekkaT Offline
      tekka
      Admin
      wrote on last edited by
      #13

      @cimba007 That's an interesting finding, I'll look into that.

      1 Reply Last reply
      1
      • cimba007C Offline
        cimba007C Offline
        cimba007
        wrote on last edited by
        #14

        @tekka
        I just realized that this might affect all request-response operations and a solution might be difficult to find without affecting all users that don't use this particular setup.

        It would be ideal if an potential fix could be made so it would only affect the esp8266_mqtt code .. but again .. this might have further implications.

        tekkaT 1 Reply Last reply
        0
        • cimba007C cimba007

          @tekka
          I just realized that this might affect all request-response operations and a solution might be difficult to find without affecting all users that don't use this particular setup.

          It would be ideal if an potential fix could be made so it would only affect the esp8266_mqtt code .. but again .. this might have further implications.

          tekkaT Offline
          tekkaT Offline
          tekka
          Admin
          wrote on last edited by tekka
          #15

          @cimba007 Yes - and now thinking of the upcoming RPI GW port running at 1.2GHz ... :) I think a delay of ~300ms should be safe.

          cimba007C 1 Reply Last reply
          0
          • tekkaT tekka

            @cimba007 Yes - and now thinking of the upcoming RPI GW port running at 1.2GHz ... :) I think a delay of ~300ms should be safe.

            cimba007C Offline
            cimba007C Offline
            cimba007
            wrote on last edited by
            #16

            @tekka

            Update: https://github.com/mysensors/MySensors/issues/578#issuecomment-244421537

            Have a look at the timing diagram ;-)

            1 Reply Last reply
            0
            • scalzS Offline
              scalzS Offline
              scalz
              Hardware Contributor
              wrote on last edited by scalz
              #17

              Lol I don't think/hope that the 1.2ghz will break the 8mhz node :)

              @cimba007 I already noticed this behaviour as I use 1Mhz nodes. but didn't digged too much because for me this was a racing issue and was making sense, especially when serial debug was enabled. But even if not, 1mhz detunes timers etc so 1ms is not anymore.
              Finally, for my network stability, I have decided to use 8Mhz when radio is active. Because imho it was making more sense, that for all nodes 1ms=1ms. So, if i don't need radio, i use 1mhz, else 8mhz. So I always have a decent speed process for the communication. And when radio is active, the 1mhz power savings of atmel is too small regarding radio power consumption..

              I think there is no problem to go as low as 1.8v with 328p
              0_1472891902251_328p_clock.png

              Also interesting about 250 000kbps baudrate, 0% error...
              0_1472892062467_ulpnode-uart-speed.jpg
              (I have only tried this for 4mhz, i'm not sure if it could work for 1mhz, from the datasheet it shouldn't. And that wasn't with Arduino Serial Monitor (250k).

              1 Reply Last reply
              2
              • cimba007C Offline
                cimba007C Offline
                cimba007
                wrote on last edited by
                #18

                With 1Mhz I could get working was 115200.

                I would like to switch to 8mhz but I have a dilemma.

                I got ten 2xAA battery holders which would give me (with batteries) a working range from ~2.00V - 3.00V (approx).

                The only option left is trying out the whole stuff with 16mhz / 8 = 2mhz but .. well .. I can't reflash the fuses on the jnode after assembly.

                The other option I have is to switch to LDO + LiPo battery but I was not too sure to put lipo batteries all over my place for safety concerns. Don't know what will happen if on a hot summer day the lipo might get a full day of sun radiation when placed near a window for example.

                1 Reply Last reply
                0
                • cimba007C Offline
                  cimba007C Offline
                  cimba007
                  wrote on last edited by cimba007
                  #19

                  Update: I missed one important point .. OSCCAL doesn't range from 140 to 200 but actually from 0 to 255

                  0_1472922468980_upload-676b3c85-462c-468f-9799-199fb1b6044d

                  I changed the ranges and ...

                  void setup() {
                    Serial.begin(250000);
                    Serial.println(OSCCAL);
                  }
                  
                  // Use hterm to repeatatly send the same message unti you cacn read it
                  void loop() {
                    static uint8_t val = 0;
                    OSCCAL=val;
                    //Serial.println();
                    Serial.print("Osccal= ");  
                    Serial.println(OSCCAL,DEC);
                  
                    delay(100);
                    //while(Serial.available())
                    //  Serial.write(Serial.read());
                    val++;
                    if(val > 250)
                    {
                      while(true);
                    }
                  }
                  

                  Believe it or not

                  0_1472922508285_upload-9e7bca92-f9e7-40c4-920a-fcbecfcacd21

                  Starting from osccal 239 .. which is technically 12/8 = 1,5mhz and not 1mhz .. I was able to receive some data .. with the drawback that all delay functions etc. might be "a little bit" off.

                  Wohoo .. 1,5mhz @ 250.000baud

                  Might be some artifact but .. it is still nice to know ^^

                  1 Reply Last reply
                  0
                  • cimba007C Offline
                    cimba007C Offline
                    cimba007
                    wrote on last edited by cimba007
                    #20

                    Somehow the graph from the datasheet doesn't fit at all for my internal oscillator.

                    Just an example .. I programmed the fuse to output the clock on PortB0 and I got:

                    OSCCAL=66;
                    Serial.begin(57600);
                    ~973 KHz

                    OSCCAL=66;
                    Serial.begin(115200);
                    ~973 KHz

                    OSCCAL=240;
                    Serial.begin(250000);
                    ~1.88 MHz

                    I would expect OSCCAL = 66 to get me ~ 6/8 = 800KHz

                    1 Reply Last reply
                    0
                    • cimba007C Offline
                      cimba007C Offline
                      cimba007
                      wrote on last edited by
                      #21

                      Using Serial.begin(115200) I experienced some lockups of the atmega328p .. serial communication stopped completely as well as all other operation .. WTF ?!

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


                      18

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 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