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. General Discussion
  3. How can I set the payload for MQTT v1.6

How can I set the payload for MQTT v1.6

Scheduled Pinned Locked Moved General Discussion
10 Posts 2 Posters 3.3k Views
  • 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.
  • ahmedadelhosniA Offline
    ahmedadelhosniA Offline
    ahmedadelhosni
    wrote on last edited by
    #1

    Hello,

    In the mysensors v1.6 notes (https://docs.google.com/document/d/1NKq5uuNdnxF5jWnum7VT32mbKLjuvqlx2A5D1qQ-H3Q/edit#) it was mentioned that the following pattern is used for mqtt usage

    MY-MQTT-TOPIC-PREFIX/NODE-ID/SENSOR-ID/CMD-TYPE/ACK-FLAG/SUB-TYPE
    
    Example topic:
    my-mqtt-gateway/1/2/2/0/1
    

    But Actually I don't understand where do I assign the payload ? Also the gateways subscribes only to mygateway/+/+/+/+/+

    They are 5 not 6.

    Using the serial interface there is a payload to be set
    7;5;1;0;2;1

    Thanks.

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

      http://forum.mysensors.org/topic/2352/guide-setting-up-and-testing-mqtt-client-gateway

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

        Sorry Hek but I still don't get it.

        When I set my mqtt gateway, it subscribes to mygateway-prefex/+/+/+/+/+

        When I was using serial gateways, I was doing the following to turn on or off a relay.

        7;5;1;0;2;1 This sets node id 7, child id 5, message type '1' (set), no ack, sub-type '2' (V_LIGHT), to be >>> equal 1 (ON)
        7;5;1;0;2;0 This sets node id 7, child id 5, message type '1' (set), no ack, sub-type '2' (V_LIGHT), to be >>> equal 0 (OFF)

        While using mqtt, what I expected that we subscribe to a topic name like mygateway1-in then I shall normally add my 6 bits which are 7/5/1/0/2/1 or 7/5/1/0/2/0

        So my question is about setting the payload to 1 or 0. I still can see that you mentioned that MQTT frame is like this
        MY-MQTT-TOPIC-PREFIX/NODE-ID/SENSOR-ID/CMD-TYPE/ACK-FLAG/SUB-TYPE
        while the serial frame has one more option for payload
        node-id;child-sensor-id;message-type;ack;sub-type;payload\n

        I hope that you understood my problem. Thanks.

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

          Looks like I misunderstood something..payload will be the message itself. I'll test it now and will be back again

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

            Using moquitto_pub command line tool you would send it like this:

            > mosquitto_pub -t 'mygateway1-in/7/5/1/0/2' -m '1'

            ahmedadelhosniA 1 Reply Last reply
            0
            • hekH hek

              Using moquitto_pub command line tool you would send it like this:

              > mosquitto_pub -t 'mygateway1-in/7/5/1/0/2' -m '1'

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

              @hek well I don't have a problem in setting the mqtt environment using mosquitto. I just noticed two things now.

              First, I am working on windows and using chrome plugin MQTTlens. I decided using mosiquitto as you said.But using

              mosquitto_pub -t 'mygateway1-in/7/5/1/0/2' -m '1' 
              

              didn't work, I used instead

              mosquitto_pub -t mygateway1-in/7/5/1/0/2 -m 1
              

              It was received by the gateway and printed

              Message arrived on topic: mygateway1in/23/19/1/0/2
              

              But the second thing is that incomingMQTT() function, the frame is not evaluated at all. It goes to case 0 and return

              case 0: {
                  // Topic prefix
                  if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0)
                  {
                      // Message not for us or malformed!
              	    Serial.println("DOOLA - incomingMQTT - case 0 ERROR");
                          return;
                   }
                  Serial.println("DOOLA - incomingMQTT - case 0");
                  break;
              }
              
              

              I tried commenting the if condition and I frame was evaluated but i received st=fail:1

              I suppose that it is working and tested and maybe I have a problem, right ?

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

                Still unable to connect with a node.

                Serial gateway is working with the same pattern sent.

                I made sure that the buffer sent using serial or using mqtt are the same. I send ;23;19;1;0;2;1 using serial, and mygateway1in/23/19/1/0/2 using mqtt. and both printed same buffer.

                RF24::write > startFastWrite > RF24::write_payload
                023101219490

                I changed the nRF also but it didn't solve the problem.

                1 Reply Last reply
                0
                • ahmedadelhosniA ahmedadelhosni

                  @hek well I don't have a problem in setting the mqtt environment using mosquitto. I just noticed two things now.

                  First, I am working on windows and using chrome plugin MQTTlens. I decided using mosiquitto as you said.But using

                  mosquitto_pub -t 'mygateway1-in/7/5/1/0/2' -m '1' 
                  

                  didn't work, I used instead

                  mosquitto_pub -t mygateway1-in/7/5/1/0/2 -m 1
                  

                  It was received by the gateway and printed

                  Message arrived on topic: mygateway1in/23/19/1/0/2
                  

                  But the second thing is that incomingMQTT() function, the frame is not evaluated at all. It goes to case 0 and return

                  case 0: {
                      // Topic prefix
                      if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0)
                      {
                          // Message not for us or malformed!
                  	    Serial.println("DOOLA - incomingMQTT - case 0 ERROR");
                              return;
                       }
                      Serial.println("DOOLA - incomingMQTT - case 0");
                      break;
                  }
                  
                  

                  I tried commenting the if condition and I frame was evaluated but i received st=fail:1

                  I suppose that it is working and tested and maybe I have a problem, right ?

                  hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #8

                  @ahmedadelhosni said:

                  mosquitto_pub -t mygateway1-in/7/5/1/0/2 -m 1
                  It was received by the gateway and printed

                  Message arrived on topic: mygateway1in/23/19/1/0/2

                  Looks like the dash-character is swallowed when you don't quote the topic on windows.

                  Can't debug this on my mac. Just change the topic prefix in sketch to something without without dash.

                  You seem to have problem with your radio. This has been discussed elsewhere on forum and there is a troubleshoot guide on man site.

                  ahmedadelhosniA 1 Reply Last reply
                  0
                  • hekH hek

                    @ahmedadelhosni said:

                    mosquitto_pub -t mygateway1-in/7/5/1/0/2 -m 1
                    It was received by the gateway and printed

                    Message arrived on topic: mygateway1in/23/19/1/0/2

                    Looks like the dash-character is swallowed when you don't quote the topic on windows.

                    Can't debug this on my mac. Just change the topic prefix in sketch to something without without dash.

                    You seem to have problem with your radio. This has been discussed elsewhere on forum and there is a troubleshoot guide on man site.

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

                    @hek sorry this was a typo.

                    Actually it printed Message arrived on topic: mygateway1-in/23/19/1/0/2 on arduino serial. meaning that it received it correctly. I just copied the one without dash with mistake because I was testing with a topic without the dash, cas I thought that this line

                        if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0)
                    

                    have problem with the dash.

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

                      I guess I solved the problem. Please check http://forum.mysensors.org/topic/2193/gatewayesp8266mqttclient-in-development-branch/11

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


                      23

                      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