Issue: send Downlink to end device trough MQTT using python
Setup:MQTT
LoRa® Server:RAK7258
Details:
I would like to automatically send a message to a node through my RAK7258 using a python program.
I know how to do it manually thanks to the Topic “How can I send Downlink to end device through MQTT”, but I need to know if it is possible to make a python program that calls my RAK7258 and sends a message to the node. Any suggestions?
Thanks
Hello
Yes, I know that the topic ends in how to send the message from the console. I have a broker that can send the downstream message but I don’t know how to send it. The Downlink Topic
It is {{application_name}} / {{device_name}} / down but I need an example of how to send it so that the RAK will forward it to the node
I am an advanced python programmer
Yes, uplinks like this appear {“applicationID”:“5”,“applicationName”:“Data_Pig”,“devEUI”:“a84041af31828e9b”,“deviceName”:“2/DRAGINO/ES/0”,“timestamp”:1618438941,“fCnt”:411,“fPort”:2,“data”:“00000000000000003CFF41”,“data_encode”:“hexstring”,“adr”:true,“rxInfo”:[{“gatewayID”:“60c5a8fffe783da9”,“loRaSNR”:10.8,“rssi”:-50,“location”:{“latitude”:0.000000,“longitude”:0.000000,“altitude”:0}}],“txInfo”:{“frequency”:867700000,“dr”:0}}
I am trying to post this message to simiar a mqtt download message
mosquitto_pub -d -t ‘Data_Pig / 2 / DRAGINO / ES / 0 / down’ -m ‘{“port”: 1, “data”: “030100”}’
Without setting up a test, I think the use of / in the device name is probably confusing the whole setup given that the / is used as a path separator - how can the software tell which part of the path is which?
Can you setup a test device with a plain name without / in it even if it doesn’t really exist, so you can try with that?
Ok. I renamed the device like DRAGINO_IO The message now is Wed Apr 14 22:42:51 2021 daemon.info appSrv[23626]: [Uplink] - {“applicationID”:“5”,“applicationName”:“Data_Pig”,“devEUI”:“a84041af31828e9b”,“deviceName”:“DRAGINO_IO”,“timestamp”:1618440171,“fCnt”:452,“fPort”:2,“data”:“00000000000000003CFF41”,“data_encode”:“hexstring”,“adr”:true,“rxInfo”:[{“gatewayID”:“60c5a8fffe783da9”,“loRaSNR”:10.0,“rssi”:-45,“location”:{“latitude”:0.000000,“longitude”:0.000000,“altitude”:0}}],“txInfo”:{“frequency”:867300000,“dr”:0}}
We already have 3 RAK7258 and we are very happy with the product. All the systems are equal
RAK7258 as Lora Gateway
An MQTT broker installed on a raspy
One DRAGINO MULTIPLE I / O CONTROLLER LT22222-L network node
Gateway configuration is
This is the message that the LT22222-L sends every so often
Sat Apr 24 12:43:37 2021 daemon.info appSrv[31418]: [Uplink] - {“applicationID”:“1”,“applicationName”:“Data_Pig”,“devEUI”:“a84041af31828e9b”,“deviceName”:“DRAGINO_IO”,“timestamp”:1619261017,“fCnt”:48,“fPort”:2,“data”:“00000000000000003CFF41”,“data_encode”:“hexstring”}
Now a new goal is to send a downlink message to DRAGINO MULTIPLE I / O CONTROLLER LT22222-L to open or close a intarnal relay
If I do it from here it works
But I need send a automatic message to the node, but if I run the following program into the raspy to post a message to the node it doesn’t work (I try 3 different formats)
import paho.mqtt.client as paho
broker=“localhost”
port=1883
def on_publish(client,userdata,result): #create function for callback
print(“data published \n”)
pass
client1= paho.Client(“control1”) #create client object
client1.on_publish = on_publish #assign function to callback
client1.connect(broker,port) #establish connection
data=’{“confirmed”: “true”, “fPort”: 1, “data”: “030100”}’
ret= client1.publish(‘Data_Pig/DRAGINO_IO/down’,data) # publish option 1
ret= client1.publish(‘Data_Pig/1/DRAGINO_IO/a84041af31828e9b/tx’,data) # publish option 2
ret= client1.publish(‘gateway/a84041af31828e9b/tx’,data) # publish option 3
I can’t see anything
It seems that the message does not go from the Gateway to the Node Could it be some incorrect configuration of the gateway?
Yes, it is possible. The downlink topic format we use is: 3087/application/{{application_EUI}}/device/{{device_EUI}}/tx
with 3087 being the Client ID.
Good luck!