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. GatewayESP8266MQTTClient in Development Branch

GatewayESP8266MQTTClient in Development Branch

Scheduled Pinned Locked Moved Development
13 Posts 6 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.
  • hekH Offline
    hekH Offline
    hek
    Admin
    wrote on last edited by
    #3

    @Mike-Cayouette

    #define MY_NODE_ID xxx

    But for the gateway this is not needed as they always get id=0

    @gmccarthy
    Unless you want to attach sensors to the gateway itself, you can leave presentation() and setup() empty.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mike Cayouette
      wrote on last edited by
      #4

      @hek Thank you. I should have mentioned I have the gateway working but I was wondering how to define the node id in the clients. In any case, I was coming back here to say I had figured it out.

      I have a temp sensor communicating with the gateway.

      Mike

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vickey
        wrote on last edited by
        #5

        @hek Gateway and sensor node never get communicated even after configuring manual ID. Here is arduino debug

        Starting...
        find parent
        send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
        find parent
        send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
        find parent
        send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
        

        Here is the ESP8266 12E gateway debug

        0;0;3;0;9;Starting...
        scandone
        f 0, ....scandone
        state: 0 -> 2 (b0)
        .state: 2 -> 3 (0)
        state: 3 -> 5 (10)
        add 0
        aid 1
        cnt 
        
        connected with Ahmed, channel 1
        ip:192.168.0.31,mask:255.255.255.0,gw:192.168.0.1
        .IP: 192.168.0.31
        0;0;3;0;9;gateway started, id=0, parent=0, distance=0
        0;0;3;0;9;Attempting MQTT connection...
        0;0;3;0;9;MQTT connected
        
        1 Reply Last reply
        0
        • FotoFieberF Offline
          FotoFieberF Offline
          FotoFieber
          Hardware Contributor
          wrote on last edited by
          #6

          There seems to be a bug in incomingMQTT:
          replace
          for (str = strtok_r(topic, "/", &p); str && i < 5;
          with
          for (str = strtok_r(topic, "/", &p); str && i <= 5;

          -> http://forum.mysensors.org/topic/1870/esp8266-wifi-gateway-port-for-mysensors/138

          1 Reply Last reply
          0
          • hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #7

            Ok, created a PR on this.

            https://github.com/mysensors/Arduino/pull/229

            Will just let it run through Jenkins before merging.

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

              There may be other problems in the code. I switched to ethernet gateway and wrote my own controller in node-red (wip).

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mike Cayouette
                wrote on last edited by
                #9

                @FotoFieber I switched to ethernet gateway and wrote my own controller in node-red

                I am attempting the same . For some reason though I cannot get the mysensors ESP8266Gateway to receive data from node-red. I configured a TCP node in node-red with the gateways IP on port 5003. When I connect the serial monitor I can see the client connection established, but when I send data from node-red I get nothing. I am able to telenet to the gateway and in the serial monitor I see the messages I type so I know the gateway can receive, but it does not receive from node-red. How did you get node-red and the gateway to exchange messages?

                Thank you,

                Mike

                FotoFieberF 1 Reply Last reply
                0
                • M Mike Cayouette

                  @FotoFieber I switched to ethernet gateway and wrote my own controller in node-red

                  I am attempting the same . For some reason though I cannot get the mysensors ESP8266Gateway to receive data from node-red. I configured a TCP node in node-red with the gateways IP on port 5003. When I connect the serial monitor I can see the client connection established, but when I send data from node-red I get nothing. I am able to telenet to the gateway and in the serial monitor I see the messages I type so I know the gateway can receive, but it does not receive from node-red. How did you get node-red and the gateway to exchange messages?

                  Thank you,

                  Mike

                  FotoFieberF Offline
                  FotoFieberF Offline
                  FotoFieber
                  Hardware Contributor
                  wrote on last edited by
                  #10

                  @Mike-Cayouette
                  What kind of tcp node do you use?

                  I use a tcp request node and inject a blank on startup to get the connection opened.

                  1 Reply Last reply
                  0
                  • ahmedadelhosniA Offline
                    ahmedadelhosniA Offline
                    ahmedadelhosni
                    wrote on last edited by ahmedadelhosni
                    #11

                    Hello,

                    This reply is related to another topic http://forum.mysensors.org/topic/2378/how-can-i-set-the-payload-for-mqtt-v1-6 where I wasn't able to send my buffer from my mqtt gateway to another sensor node. After spending all day today debugging the issue, I was able to find two bugs and to send the buffer correctly.

                    This is the topic which I subscribe to

                    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygatewayin"
                    

                    This is how I send my mqtt pattern using MQTTlens or Mosquitto to be published to the gateway. My message contains 1 or 0 to turn ON or OFF a relay in my sensor node with id 4, child id 19, set, no ack, V_LIGHT

                    mygatewayin/4/19/1/0/2
                    

                    The first problem which I faced is that my mqtt buffer wasn't evaluated in the callback function incomingMQTT() found in MyGatewayTransportMQTTClient.cpp

                    After checking the case switch I found out that the rest of the case switches doesn't continue because the code returns due to the following line

                    if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0)
                    {
                        return;
                    }
                    

                    According to http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#gad34d5b7d040fcb97939e939f19d88a5f

                    The strcmp_PF() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

                    Actually I haven't used this function before but according to description it will return 0 if they are identical, so using != shall be right, but actually it was solved when I replaced it with == instead of !=

                    Finally I was able to evaluate the buffer and the case switches continued.

                    But Also this didn't solve the problem and the buffer wasn't sent to the sensor node id 4

                    After lots of printing functions for debugging I found that in serial monitoring, the following is printed

                    send: 0-0-0-4 s=19,c=1,t=2,pt=0,l=1,sg=0,st=fail:1
                    

                    While when I use Serial gateway which is working well till now, the following is printed instead

                    send: 0-0-4-4 s=19,c=1,t=2,pt=0,l=1,sg=0,st=ok:1
                    

                    Thus I found that the difference is in 0-0-X-4.

                    Searching further in the code, I found that the debug function for this line is used in MyTransport.cpp in function transportSendWrite(uint8_t to, MyMessage &message)

                    debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,st=%s:%s\n"),
                    			message.sender,message.last, to, message.destination, message.sensor, mGetCommand(message), message.type,
                    			mGetPayloadType(message), mGetLength(message), mGetSigned(message), to==BROADCAST_ADDRESS ? "bc" : (ok ? "ok":"fail"), message.getString(_convBuf));
                    

                    So the difference here is that the variable to is set as 0 in case of mqttgateway, while it is set as 4 correctly using Serial gateway.

                    So finally this is what I have reached.

                    In MyTransport.cpp in function boolean transportSendRoute(MyMessage &message)

                    #if !defined(MY_REPEATER_FEATURE)
                        // None repeating node... We can only send to our parent\\
                        ok = transportSendWrite(_nc.parentNodeId, message);
                    #endif
                    

                    The above is called because MY_REPEATER_FEATURE is not defined, thus the mqttgateway sends always 0 instead of the required node id.

                    I tried to define MY_REPEATER_FEATURE but I found big memory size and the software was crazy.
                    Also in MySensor.h it is not mentioned to be defined

                    #if defined(MY_GATEWAY_MQTT_CLIENT)
                    ... some code ...
                    ... some code ...
                    #elif defined(MY_GATEWAY_FEATURE)
                    ... some code ...
                    	#if defined(MY_RADIO_FEATURE)
                    		// We assume that a gateway having a radio also should act as repeater
                    		#define MY_REPEATER_FEATURE
                    	#endif
                    

                    What I did now as a workaround because it is 2:40 AM here and I need to sleep :D Is the following

                    In MyTransport.cpp

                    	#if !defined(MY_REPEATER_FEATURE)
                    		#if defined(MY_GATEWAY_MQTT_CLIENT)
                    			ok = transportSendWrite(message.destination, message);
                    		#else
                    		// None repeating node... We can only send to our parent
                    		ok = transportSendWrite(_nc.parentNodeId, message);
                    		#endif
                    	#else
                    

                    Please check whether this will solve the problem or not. Please correct me if I was wrong. It's my first time to look around in the library today.

                    Thanks.

                    1 Reply Last reply
                    1
                    • hekH Offline
                      hekH Offline
                      hek
                      Admin
                      wrote on last edited by
                      #12

                      @ahmedadelhosni said:

                      MY_REPEATER_FEATURE

                      Good catch, I'll do some tests and check in something.

                      ahmedadelhosniA 1 Reply Last reply
                      0
                      • hekH hek

                        @ahmedadelhosni said:

                        MY_REPEATER_FEATURE

                        Good catch, I'll do some tests and check in something.

                        ahmedadelhosniA Offline
                        ahmedadelhosniA Offline
                        ahmedadelhosni
                        wrote on last edited by
                        #13

                        @hek Thanks. I am sure you will come up with a better general solution :D

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


                        7

                        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