I am working on this Fiware flow:
I have used efrecon/mqtt-client as MQTT client based on mosquitto_pub so that the data can be consumed from Grafana.
docker run -it --rm --name mqtt-publisher efrecon/mqtt-client pub -h 172.31.85.246 -p 31624 -m "AGV_Th|25" -t "/ul/5jggokgpepnvsb2uv4s40d59ov/agv001/attrs"
In the following example, a key-value pair is sent to populate a persistence with Crate DB and then consumed with Grafana.
I am testing with a new python mqtt-paho based client without achieving the same result as with the mosquitto_pub based docker client. For instance:
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.connect("172.31.85.246", 31624)
client.publish("/ul/5jggokgpepnvsb2uv4s40d59ov/agv001/attrs","{\"agv_th\":65}")
Any ideas?
As per the comments there were two issues:
Connect
function returns before the connection is fully established and without a network loop will never finish the process. If you want to connect, publish, then disconnect take a look at single
."{\"agv_th\":65}"
!= "AGV_Th|25"
publish.single("/ul/5jggokgpepnvsb2uv4s40d59ov/agv001/attrs", "AGV_Th|25", hostname="172.31.85.246", port=31624)
worked.
single
and multiple
are utility functions that connect, send message(s) and then disconnect. These are useful where you don't want to keep the connection active (or just want to simplify your code). As per the docs you can use multiple
like this:
msgs = [{'topic':"/ul/5jggokgpepnvsb2uv4s40d59ov/agv001/attrs", 'payload':"AGV_Th|25"},
{'topic':"/ul/5jggokgpepnvsb2uv4s40d59ov/agv00X/attrs", 'payload':"AGV_Th|XX"}]
publish.multiple(msgs, hostname="172.31.85.246", port=31624)