Rijkswaterstaat, owner of the regional roads and highways in The Netherlands, provide on their website rijkswaterstaatstrooit.nl a virtual map with road temperatures and also locations of trucks that are putting salt on the roads. I’m driving motorcycle myself all year long, except in snowy conditions, so I’m curious about the road temperatures. Besides the weather conditions (rain forecast https://www.rutg3r.com/buienradar-nl-precipitationrain-forecast-php-script/), the temperature of the road is interesting as well. After searching for a long time into the sourcecode from the website, I’ve found out that all temperature measurepoints are visible with one single web command: link. As you can see, all data on this page is available in JSON format. Every temperature sensor contains four strings of data. When I take a closer look to the sensor nearby Venlo, it looks like this:
{"id":"0850","temperature":4.5,"bbox":[6.1282,51.3937,6.1282,51.3937]}},{"type":"Feature","id":"road_temperatures.fid-3c390e6_16e4cca5ea3_-44ac","geometry":{"type":"Point","coordinates":[6.1282,51.3937]},"geometry_name":"geometry","properties": {"id":"0850","temperature":4.4,"bbox":[6.1282,51.3937,6.1282,51.3937]}},{"type":"Feature","id":"road_temperatures.fid-3c390e6_16e4cca5ea3_-44ab","geometry":{"type":"Point","coordinates":[6.1282,51.3937]},"geometry_name":"geometry","properties": {"id":"0850","temperature":4.4,"bbox":[6.1282,51.3937,6.1282,51.3937]}},{"type":"Feature","id":"road_temperatures.fid-3c390e6_16e4cca5ea3_-44aa","geometry":{"type":"Point","coordinates":[6.1282,51.3937]},"geometry_name":"geometry","properties": {"id":"0850","temperature":4.3,"bbox":[6.1282,51.3937,6.1282,51.3937]}},{"type":"Feature","id":"road_temperatures.fid-3c390e6_16e4cca5ea3_-44a9","geometry":{"type":"Point","coordinates":[5.7864,50.9703]},"geometry_name":"geometry","properties":
To have a closer look into the global JSON output for all sensors, it’s easier to copy and past the code into a JSON viewer, like http://jsonviewer.stack.hu/. Paste all the JSON code into the “Text” tab and select afterwards the “Viewer” tab. The results will be shown like this:
Uncollapse the “Features” folder and you’ll find all the sensor data here, one by one.
Based on the latitude and longitude from your “home” location, compared to the data in the JSON, you can find the sensor number that is nearby. In my case it’s id number “0850”.
Homeseer devices
The script will create automatic virtual devices based on the data that is available for the sensor_id you enter in the script on line 21 and the location_name you give to it on line 22. Because the data in the JSON is not consistent (the id’s are not always on the same spot in the JSON output), the script will do a loop through all sensor id’s to find the one you have entered in the script. When found, it will store the data in variables.
The “Temperature4” value is the latest value provided by the sensor in degrees Celcius. For documentation purposes I’ve made available the other three values as well.
Script changes
The following lines of code has to be changed by the user before an Homeseer event should fire the script:
LINE | NAME | COMMENT |
13 | Public Shared Debug | true = debug enabled. false – debug disabled. |
14 | Public Shared useMySQL | I’ve made a recurring event to save the values every 10 minutes into a MySQL table. true = data will be stored in MySQL. |
15 | Public Shared CreateDevices | This will create the virtual devices in Homeseer (true), or not (false). default = true. |
16-20 | MySQL tabel credentials | |
21 | Dim sensor_id | the id number from the JSON output, nearby your personal location. |
22 | Dim location_name | a name of the measurement point (sensor) that you can define yourself. (streetname, highway number, etc) |
When the variable “use MySQL” is set to true, the values will be stored into a MySQL table. To prevent duplicate entries, a check will be done on the unique sensor id value sequence number. In case the sequence number don’t exist in the table, an INSERT command will be done. In case the sequence number already exist, the script will skip inserting the values.
Example of available data in the MySQL table:
Future improvements
- Reverse geocode to define automatically the address of the sensor (will replace the manual set of the location_name variable).
- Replace input for one sensor with array of multiple ones
Downloads
Road_temperatures.vb (11.6 KiB, 975 hits)
Source: https://www.rijkswaterstaatstrooit.nl/
Related Posts
December 5, 2018
Monitor your “The Things Network” Gateway
August 20, 2017
Buienradar (NL) precipitation/rain forecast PHP script
October 9, 2016