Simple script for posting to DeviceHive

I’ve written a script that might be useful to someone integrating or playing on DeviceHive.

Keep in mind that this script was written for a RouterBOARD mAP 2nD and you may need to change the /system parameters if you are using CRS etc.
It posts temperature, CPU load and it posts Voltage without the decimal, so 225 is 22.5V, I was too lazy to do the lookup. There are plenty other examples that does this if you browse around.
For this script your device must be set to manual time zone 00:00 offset, DeviceHive did not like my local time and it flooded the notification board.

Make sure to enter your own Bearer token and url as mine will not work on your network. I did leave it exactly as it ran on my system, just paste your own data in.

http://forum.mikrotik.com/t/read-before-creating-yet-another-new-my-script-does-not-work-topic/122693/1


:local thisbox [/system identity get name]
:local temperature [/system health get temperature]
:local voltage [/system health get voltage]
:local cpuload [/system resource get cpu-load]
# Month Array Needed For Lookup
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
# Get Todays Date
:local currentDate [/system clock get date]
:local DateTimeComb 
# Convert The Name Of The Month To A Number
:local month [ :pick $currentDate 0 3 ]
:local monthNumber ([ :find $months $month -1 ] + 1)
:if ($monthNumber < 10) do={ :set monthNumber ("0" . $monthNumber)}
# Get The Time
:local currentTime [/system clock get time]
:set currentTime ([:pick $currentTime 0 2].":".[:pick $currentTime 3 5].":".[:pick $currentTime 6 8])
# Set The Date Format 
:set currentDate ([:pick $currentDate 7 11] ."-". $monthNumber ."-". [:pick $currentDate 4 6])
:set DateTimeComb ($currentDate."T".$currentTime."Z")
#/log info ("Posting to DeviceHive")
# Change The Url And Bearer Token (single space between Bearer and token)
/tool fetch http-method=post mode=https url="https://playground.devicehive.com:443/api/rest/device/ryan-64000/notification" http-header-field="content-type:application/json,Authorization:Bearer  eyJhbGciOiJIUzI1NiJ9.eyJwYXlsb2FkIjp7ImEiOlsyLDMsNCw1LDYsNyw4LDksMTAsMTEsMTIsMTUsMTYsMTddLCJlIjoxNTgwMDc2MDAwMDAwLCJ0IjoxLCJ1Ijo1NjEzLCJuIjpbIjU1MjUiXSwiZHQiOlsiKiJdfX0.NtNyn7e7rdALv8wz4ohe55yllirTP5TBtYl59ahR7ec" output=none http-data="{\"notification\": \"$thisbox\",\"timestamp\": \"$DateTimeComb\",\"parameters\": {\"Voltage\": \"$voltage\",\"Temperature\": \"$temperature\",\"CPU-Load\": \"$cpuload\"}}"
/log info ("$DateTimeComb DeviceHive POST Done")