mercredi 25 février 2015

How can I remove a carriage return, add a time stamp and ignore some data from a live MQTT feed


I type mosquitto_sub -d -t +/# from the Ubuntu terminal to access the MQTT stream.


The output is this:



Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Received PUBLISH (d0, q0, r0, m0, 'm/jsyd/TEST/001/d/status', ... (34 bytes))
Sending PINGREQ
Received PINGRESP
Received PUBLISH (d0, q0, r0, m0, 'm/jsyd/TEST/001/d/SVlts', ... (28 bytes))
Sending PINGREQ
Received PINGRESP


To filter I add mosquitto_sub -d -t +/# 2> >(grep PUBLISH) this will only allow lines with PUBLISH in it, hence the ouput is:



Received PUBLISH (d0, q0, r0, m0, 'm/gf/TMX6BP/075/d/status', ... (38 bytes))
86,637999,164563,-33.836465,151.051189
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/SVlts', ... (26 bytes))
806,3040421,7549 7750 3904
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/status', ... (39 bytes))
806,3069000,59666,-33.836465,151.051189
Received PUBLISH (d0, q0, r0, m0, 'm/gf/TMX6BP/075/d/SVlts', ... (28 bytes))
86,1224830,27610 27869 17565
Received PUBLISH (d0, q0, r0, m0, 'm/gf/TMX6BP/075/d/status', ... (39 bytes))
86,1243000,164573,-33.836465,151.051189
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/SVlts', ... (26 bytes))
806,3640483,7463 7721 3933
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/status', ... (39 bytes))
806,3674000,59676,-33.836465,151.051189
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/SVlts', ... (26 bytes))
806,4240543,7291 7750 3933
Received PUBLISH (d0, q0, r0, m0, 'm/NWRL/TMX/098/d/status', ... (39 bytes))
806,4279000,59687,-33.836465,151.051189
Received PUBLISH (d0, q0, r0, m0, 'm/gf/MXE/065/d/SVlts', ... (25 bytes))
455,24715,28041 28041 967


How would I be able to eliminate a few of the fields and also add a time stamp everytime I receive something; I 've tried using sed but had no luck. I entered $ mosquitto_sub -d -t +/# 2< <(grep PUBLISH) 2< <(sed "s/^/ date/") , $ mosquitto_sub -d -t +/# 2< <(grep PUBLISH) 2< <(sed "s/^/$date`/")


Q: How can I change my input to the terminal so that the output from the above live feed would be:



'm/gf/TMX6BP/075/d/status', 86,637999,164563,-33.836465,151.051189,[timestamp]
'm/NWRL/TMX/098/d/SVlts', 806,3040421,7549 7750 3904,[timestamp]
'm/NWRL/TMX/098/d/status', 806,3069000,59666,-33.836465,151.051189,[timestamp]
'm/gf/TMX6BP/075/d/SVlts', 86,1224830,27610 27869 17565,[timestamp]
'm/gf/TMX6BP/075/d/status', 86,1243000,164573,-33.836465,151.051189,[timestamp]
'm/NWRL/TMX/098/d/SVlts', 806,3640483,7463 7721 3933,[timestamp]
'm/NWRL/TMX/098/d/status', 806,3674000,59676,-33.836465,151.051189,[timestamp]
'm/NWRL/TMX/098/d/SVlts', 806,4240543,7291 7750 3933,[timestamp]
'm/NWRL/TMX/098/d/status', 806,4279000,59687,-33.836465,151.051189,[timestamp]
'm/gf/MXE/065/d/SVlts', 455,24715,28041 28041 967,[timestamp]


Aucun commentaire:

Enregistrer un commentaire