Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beriberikix/senml-zephyr
A codec for encoding and decoding Sensor Measurement Lists (SenML) for Zephyr
https://github.com/beriberikix/senml-zephyr
codec data iot senml sensor zephyr-rtos
Last synced: about 2 months ago
JSON representation
A codec for encoding and decoding Sensor Measurement Lists (SenML) for Zephyr
- Host: GitHub
- URL: https://github.com/beriberikix/senml-zephyr
- Owner: beriberikix
- License: apache-2.0
- Created: 2024-07-27T22:31:26.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-28T02:43:41.000Z (6 months ago)
- Last Synced: 2024-11-30T19:32:33.390Z (about 2 months ago)
- Topics: codec, data, iot, senml, sensor, zephyr-rtos
- Language: C
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SenML Codec for Zephyr
The `senml-zephyr` project provides a codec for encoding and decoding Sensor Measurement Lists (SenML) as defined in [RFC 8428](https://datatracker.ietf.org/doc/html/rfc8428) & [RFC 8798](https://datatracker.ietf.org/doc/html/rfc8798). This codec supports both JSON and CBOR formats for data serialization.
## Configuration
The project provides configuration options via Kconfig:
- `SENML_CODEC`: Enable the SenML codec module.
- `SENML_FORMAT_JSON`: Enable support for JSON format.
- `SENML_FORMAT_CBOR`: Enable support for CBOR format (default).## Usage
### Encoding and Decoding SenML Records
Include the SenML codec header in your application:
```
#include "senml_codec.h"
```Create and encode a SenML record:
```
struct senml_record record = {
.bn = "device-1",
.bt = 0,
.bu = "C",
.bv = 0,
.n = "temperature",
.u = "C",
.v = 25.3,
.vs = NULL,
.vb = 0,
.vd = NULL,
.s = 0,
.ut = 0
};char buffer[256];
int ret = senml_encode_record(&record, buffer, sizeof(buffer));
if (ret == 0) {
printk("Encoded JSON: %s\n", buffer);
} else {
printk("Failed to encode JSON\n");
}
```Decode a SenML record:
```
struct senml_record decoded_record;
ret = senml_decode_record(buffer, sizeof(buffer), &decoded_record);
if (ret == 0) {
printk("Decoded JSON Record: bn=%s, bt=%f, bu=%s, bv=%f, n=%s, u=%s, v=%f, s=%f, ut=%f\n",
decoded_record.bn, decoded_record.bt, decoded_record.bu, decoded_record.bv,
decoded_record.n, decoded_record.u, decoded_record.v, decoded_record.s, decoded_record.ut);
} else {
printk("Failed to decode JSON\n");
}
```