How can I set the payload for MQTT v1.6



  • 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.


  • Admin



  • 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.



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


  • Admin

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

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



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



  • 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.


  • Admin

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



  • @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.




Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.