And I guess to complete the 7.16/7.17 new scripting commands examples… While above shows new [:serialize to=json $myarray options=json.pretty] … Mikrotik also added [:serialize]/[:deserialize] to CSV to RouterOS arrays – to me that actually more generically useful than byte-array things (but spreadsheets are less fun). And, it’s be easy to miss in the release notes, since they talk about “DSV”. But that because [:serialize]/[:deserialize] take a delimiter=“\t” options to support things like TSV (tab-separated) or whatever. Adding the subtleties, from=dsv has a nice option=dsv.array which make a CSV work well with :foreach.
So to test my function, I downloaded a CSV file from the lorawan-server container in-between that contains the received LoRa frame. It’s called “rxframes.csv” and copied to root of 7.17beta RouterOS. File has the format:
Dir,Time,Application,Location,DevAddr,MAC,U/L RSSI,U/L SNR,FCnt,Confirm,Port,> Data
up,2024-10-08 10:40:20,test,6263XXXX,31333XXXXC00XX00,-54,9.75,50,false,2,> CBD308AA025101087F7FFF
up,2024-10-08 06:20:21,test,6263XXX,31333XXXXC00XX00,-55,9.25,37,false,2,> CBD5087502340108407FFF
So to get the temperature readings from the CSV (without a multi-hop voyage to MQTT on-message=) … it could be 4-6 lines depending on what you’re trying to do:
:global rxframes [:deserialize from=dsv delimiter=, options=dsv.array [/file get rxframes.csv contents as-string]]
:global temps [:toarray ""]
:foreach k,v in=$rxframes do={
:local tempC ([$decodeDriago ($v->"Data")]->"_intTempRawC")
:if ($tempC > 0) do={:set $temps ($temps,$tempC) }
}
:put [:serialize to=dsv delimiter=" " $temps ]
2181 2292 2388 2537 2730 2742 2741 2738 2936 3040 2887 2936 2887 2963 2906 2881 2821 2812 2809 2707 2804 2726 2669 2781
since those 1/100th of C temperatures, “2707” is “27.07ºC”…
note… the space-separate output using :serialize to=dsv delimiter=" " & theoretically the CSV file could be download via /tool/fetch to server’s HTTP API to avoid manual copy step here.
A more complete example using “CSV files” (aka DSV) with :serialize/:deserialize is here: http://forum.mikrotik.com/t/ros-scripting-question/179108/1