I have a device, which sends weather data over MQTT to a broker on my Linux server.
On the server a bash script is running which subscribes to the topic posted to by the device.
The script just dumps the responses into a logfile using this (simplified):
When this is started it runs continuously and dumps incoming data to a logfile.
What I now want to do is adding a function that analyzes the incoming data and sends the values to a database.
But I don't know how to send the arriving data to some other function while still remaining in the mosquitto_sub loop...
So I want "something" that will take the output that now goes to the logfile and process it so it will still arrive at the logfile but also something else can be done with the data. Like extracting the numbers and sending them to a database.
If I do this I will need another script, which I would prefer not to do, and I don't know if it is even possible to pipe it like this:
Obviously now the function depends on 2 different script files, which is less than optimal.
So basically:
How can I replace the " >> ${FULLOG} " with something that can do more processing while remaining in the same script file?
On the server a bash script is running which subscribes to the topic posted to by the device.
The script just dumps the responses into a logfile using this (simplified):
Code:
#!/bin/bash#... Setup stuff for the used variables ...CMD="mosquitto_sub -h 192.168.117.131 -i $MQTTID -F '@Y-@m-@d @H:@M:@S ; %t ; %p' -t 'aspo/rainmeter/#' >> ${FULLOG}"eval "$CMD" #This command runs until killed or a system reboot
What I now want to do is adding a function that analyzes the incoming data and sends the values to a database.
But I don't know how to send the arriving data to some other function while still remaining in the mosquitto_sub loop...
So I want "something" that will take the output that now goes to the logfile and process it so it will still arrive at the logfile but also something else can be done with the data. Like extracting the numbers and sending them to a database.
If I do this I will need another script, which I would prefer not to do, and I don't know if it is even possible to pipe it like this:
Code:
CMD="mosquitto_sub -h 192.168.117.131 -i $MQTTID -F '@Y-@m-@d @H:@M:@S ; %t ; %p' -t 'aspo/rainmeter/#' | ${EXTRASCRIPT}"
So basically:
How can I replace the " >> ${FULLOG} " with something that can do more processing while remaining in the same script file?
Statistics: Posted by Bosse_B — Thu Sep 12, 2024 6:42 am