Encode sensor data with Cayenne Low Power Protocol
To create a message containing Temperature
and Humidity
readings and pack it into string use the following example:
import Ivory.Tower.Cayenne
...
(arr :: Ref ('Stack s) ('Array len ('Stored Uint8))) <- local $ izero
len <- packCayenne arr [
Temperature (lastSample ~> sample_th_temperature)
, Humidity (lastSample ~> sample_th_humidity)
]
(strbuf :: Ref ('Stack s) UARTBuffer) <- local $ izero
refCopy (strbuf ~> stringDataL) arr
store (strbuf ~> stringLengthL) (signCast len)
It is also possible to specify sensor channels with packCayenneChannels
like this:
len <- packCayenneChannels arr [
(0, Temperature (sample0 ~> sample_th_temperature))
(1, Temperature (sample1 ~> sample_th_temperature))
]