How to Downlink Using mosquitto

Hello
I’m trying to set a downlink on The Things Stack v3 application using mosquitto(v.2.0.11)

Followed the mosquitto manual in the things stack.There was a problem doing [Publishing Downlink Messages]. I seem to have copied the manual, but I don’t know the cause of the problem. :disappointed_relieved: :disappointed_relieved:

An error occurred while executing the following code:

mosquitto_pub -h "eu1.cloud.thethings.network" -p "1883" -u "my_userID" -P "my_api_key" -t "v3/(my application ID)/devices/(my end-devices ID)/down/push" -m '{"downlinks":[{"f_port": 15,"frm_payload":"vu8=","priority": "NORMAL"}]}'

The following error occurs when executing this code.

Error: Unknown option '15,frm_payload:vu8=,priority:'.
Use 'mosquitto_pub --help' to see usage.

In addition, changing the content of -m to any sentence, such as Hi, SUBSCRIBER, caused the following problems.(Output using -d)

Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending PUBLISH (d0, q0, r0, m1, 'v3/(my application ID)/devices/(my end-devices ID)/down/push', ... (2 bytes))
Client (null) sending DISCONNECT

mosquitto_pub

Of course mosquitto_sub could not receive the message.

What kind of mistake did I make? Would you mind helping me? :sob: :sob: :sob:

Hi, Yesterday I set up downlink as well and this publish using mosquitto_pub worked for me:

mosquitto_pub -h eu1.cloud.thethings.network -t "v3/<app-id>/devices/<device-id>/down/push" -u "<app-id>@ttn" -P "<API-key>" -m '{"downlinks":[{"f_port": dlPort,"frm_payload": "AAM=","priority": "HIGHEST","confirmed": true,}]}' -d

Not sure if this addresses your problem but it might be of help.
I just post this rapidly in between meetings.

1 Like

Thank you very much. Thanks to you, I was able to solve the first problem. :grinning_face_with_smiling_eyes:

However, I still don’t understand why the above code shows such an error. :disappointed_relieved: :disappointed_relieved:

But thank you very much for solving my first problem! :heart_eyes: :heart_eyes:

1 Like

It’s confused by the " and ’ in the command line and thinks the payload details are actual commands for mosquitto_pub rather than being the JSON to send.

1 Like

Confirmed downlinks are a bad idea. There have been several topics where @cslorabox explained the why in great detail, so I won’t repeat the reasons but it’s best to remove it and use application level logic if you need acknowledgement of a successful downlink.

2 Likes

Oh, I think I understand! Thank you very much!

Can I get an answer to this?

You can, you can wait on the volunteers here or you can commission someone to answer - but even then the good people are busy with other projects.

But as I’m here, what do you mean by “mosquitto_sub could not receive the message” - you’ve published a message and you’ve marked the issue as solved - where is ‘sub’ in all of this??

I used the community function for the first time, so my explanation was insufficient.

mosquitto_sub subscribed to topic #. Similar to mosquitto_pub created above, we have also set -h “eu1.cloud.the things.network”

However, mosquitto_sub could not receive the message sent in mosquitto_pub.

In my opinion, mosquitto_pub is not able to issue a message properly. (I made a decision by looking at -d)

What I want to ask is that there is a problem with my code and I cannot issue it? Or is there any other problem other than the code?

Below is the code I created.

Mosquitto_sub –h "eu1.cloud.thethings.network"  –t  #  –u "<My_AppID>" –P "<ApI_Key>" –v

If you publish a downlink, does it appear in the device console?

That will tell you if the pub is working - then we can figure out the sub issue not showing the pub.

1 Like

Seeing that there is no response, it seems that there is another problem with my situation. Thank you for your kind reply :blush:

Live data

Assuming the screenshot is from a time period when you issued a pub, you do indeed have a problem, the biggest one being filling in all the details so someone can help you:

Device manufacturer, model, version, firmware - with link to docs
Does the device uplink successfully?
Gateway manufacturer, model, version, firmware
What other devices are uplinking successfully.

And anything else you can think of, even if YOU think it’s not relevant, because we have hundreds of threads where the pieces all come together about response 60. This will not be that thread :wink:

1 Like

When I ran mosquitto_sub, these contents were added to Live data.

mosquitto_sub_ttn

(I’m glad something came out. :joy: :joy:)

There seems to have been a problem connecting mosquitto_sub.

[Data preview] says [invalid token], but I don’t know what this means. :disappointed_relieved:

What does [invalid token] mean and where can I check and fix it?

Is there any document that I can refer to to solve this problem? :thinking:

Bottom right corner of every single console page …

But it’s game over for me - I asked for details which haven’t been supplied.

This Shell-Command is incorrect. the # is used as Delimiter for a Comment. You have to include it in Apostrophs ‘#’

mosquitto_sub –h "eu1.cloud.thethings.network" –t '#' –u "<My_AppID>" –P "<ApI_Key>" –v

That depends on the OS you are using to run the command. Windows in the default CMD ‘shell’ happily accepts the original command.