So I’m trying pull current local traffic accident data from a table on this website:
http://afc5102.scdps.gov/SCDPS_Exweb/SCDPS/HighwayPatrol/WebCad_External?Id=3
I’m grabbing the html using the http node and then feeding it to an html node:
The first html node config looks like:
The second html node looks like:
The debug output of the first few messages:
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[6]
"Status"
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[4]
"Time"
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[6]
"County"
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[8]
"Location"
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[18]
"COLLISION:INJURIES"
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[107]
"↵ IN PROGRESS↵ "
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[101]
"↵ 18:53↵ "
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[104]
"↵ ANDERSON↵ "
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[134]
"↵ THREE BRIDGES RD x[POWDERSVILLE MAIN] ↵ "
2/22/2019, 8:18:02 PM[node: 56df4fe4.abf59](https://xxxxxx.duckdns.org:1880/#)msg.payload : string[18]
So at this point I start realizing I’m a little over my head an unsure how best to go about generating the json to send to an mqtt sensor in HA. I’m also not sure whether I should have allowed the html nodes to create an array instead of single messages or not. My inclination is to take each message and build the json with some function node using string functions. Am I correct in assuming that I should create an array with each message being a record in the array? I need someone to point me in the right direction, please?
I also notice this “↵” character in many of the fields which I’m not sure where that came from. Is that a carriage return character? I’m assuming I should just strip that out unless there’s a way to prevent it from occurring in the first place?
Here is the exported flow in case anyone wants to throw me a lifeline:
[{"id":"94903c36.26e6e","type":"tab","label":"Experimentation","disabled":false,"info":""},{"id":"56df4fe4.abf59","type":"debug","z":"94903c36.26e6e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":650,"y":160,"wires":[]},{"id":"537bd8c6.6120e8","type":"inject","z":"94903c36.26e6e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":40,"wires":[["d50c357f.57ace8"]]},{"id":"d3734630.287d58","type":"html","z":"94903c36.26e6e","name":"","property":"payload","outproperty":"payload","tag":"tr","ret":"html","as":"multi","x":350,"y":160,"wires":[["5d275ae1.2fb874"]]},{"id":"d50c357f.57ace8","type":"http request","z":"94903c36.26e6e","name":"access traffic website","method":"GET","ret":"txt","url":"http://afc5102.scdps.gov/SCDPS_Exweb/SCDPS/HighwayPatrol/WebCad_External?Id=3","tls":"","x":160,"y":160,"wires":[["d3734630.287d58"]]},{"id":"5d275ae1.2fb874","type":"html","z":"94903c36.26e6e","name":"","property":"payload","outproperty":"payload","tag":"td","ret":"text","as":"multi","x":490,"y":160,"wires":[["56df4fe4.abf59"]]}]