(sorry - ignore the earlier truncated post) I cooked up a bash script that subscribes, calls a python script to reformat, then publishes. The bash script sleeps a second between loops to not eat up your cpu. You 'should' be able to change the variables in the bash script to match your configuration pretty easily...
This subscribes to ORIGINAL_TOPIC and publishes to FINAL_TOPIC in the bash script. To test: - open a bash window and subscribe to the FINAL_TOPIC - open a second window and run the bash script which will listen/reformat/publish - if you're not querying your gps currently, open a third window and publish to the ORIGINAL_TOPIC ala mosquitto_pub -h 192.168.1.171 -t RV/original -m '[{"dateTime":"1693128700.0","gpsLat":"52.152435"},{"dateTime":"1693128700.0","gpsLong":"9.929356"}]' What you should see in window1 that is subscribing is output ala: {"dateTime": "1693128700.0", "gpsLat": "52.152435", "gpsLong": "9.929356"} That kind of data should be ok to subscribe to in weewx for your lat/lon data.... #---- reformat_mqtt.bash ---- #!/bin/bash # # ip address of MQTT broker BROKER="192.168.1.171" ORIGINAL_TOPIC="RV/original" FINAL_TOPIC="RV/final" while true; do # subscribe to a topic # run the python script to reformat to stdout # publish to a final topic mosquitto_sub -C 1 -h ${BROKER} -t ${ORIGINAL_TOPIC} \ | python3 reformat_mqtt.py \ | mosquitto_pub --stdin-line -h ${BROKER} -t ${FINAL_TOPIC} # sleep a bit to not eat up your cpu sleep 1 done #---- reformat_mqtt.py ----- # # this reformats the GPS information # to a more normal looking output # # it assumes your input data is always in the same order and always complete # ala: [{"dateTime":"1693128700.0","gpsLat":"52.152435"},{"dateTime":"1693128700.0","gpsLong":"9.929356"}] import json import sys for line in sys.stdin: jsondata = json.loads(line) reorganized_data = {} reorganized_data['dateTime'] = jsondata[0]['dateTime'] reorganized_data['gpsLat'] = jsondata[0]['gpsLat'] reorganized_data['gpsLong'] = jsondata[1]['gpsLong'] print(json.dumps(reorganized_data)) On Monday, August 28, 2023 at 5:19:15 AM UTC-7 Stefan Gliessmann wrote: > I asked in the community forum for my router and I was told that this is > the only way they can currently forward data via MQTT. > A future firmware release shall allow more formatting. > > I might now play around with this > https://github.com/mrtncls/mqtt-translator to get the MQTT payload from > an array in one single statement ... > Anybody used the MQTT Translator for this purpose? > > On Monday, August 28, 2023 at 11:01:41 AM UTC+2 Stefan Gliessmann wrote: > >> Which code do you refer to? >> [image: Screenshot 2023-08-28 at 11.00.03.png] >> This is what I specified in the GPS/Router to push via MQTT to my broker >> ... >> On Sunday, August 27, 2023 at 8:39:40 PM UTC+2 vince wrote: >> >>> We'd have to see your code to see what you are publishing. >>> >>> Your MQTT log looks very odd and likely needs some tweaking >>> >>> MQTT: >>> [{"dateTime":"1693128700.0","gpsLat":"52.152435"},{"dateTime":"1693128700.0","gpsLong":"9.929356"}] >>> >>> >>> >>> I'd expect something like {"dateTime":"1233456", "gpsLat":"52.1234", >>> "gpsLong": "9.987"} for a more typical set of JSON to publish. You want >>> one element (not in an array) with three items therein - dateTime/lat/lon. >>> >>> -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/85f68c80-1ef6-40f8-a95b-da98642ecca5n%40googlegroups.com.