forked from micropython/micropython-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a new library that doesn't follow any existing API. The library is originally from https://github.com/kpn-iot/senml-micropython-library.
- Loading branch information
1 parent
52fcb8e
commit 9ee0257
Showing
22 changed files
with
1,829 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Introduction | ||
|
||
The SenML library helps you create and parse [senml documents](https://tools.ietf.org/html/draft-ietf-core-senml-13) | ||
in both json and cbor format. | ||
|
||
# key features | ||
|
||
- Object oriented design. | ||
- built in support for [senml's unit registry](https://tools.ietf.org/html/draft-ietf-core-senml-12#section-12.1) | ||
- extensible for new data types | ||
- direct support to read/write in json and cbor format. | ||
- automatically adjusts record data with respect to base time, base value & base sum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-slate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Welcome to the API documet site for the micro-python SenML library. | ||
|
||
The following api sections are available: | ||
|
||
- [senml-base](./senml_base): the base class for all senml objects. | ||
- [senml-pack](./senml_pack): the class that represents root documents. | ||
- [senml-record](./senml_record): the class that stores sensor measurements | ||
- [senml-unit](./senml_unit): the list of all unit names that can be used. | ||
|
||
|
||
|
||
Copyright (c) 2018 KPN | ||
Copyright (c) 2023 MicroPython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
# senml_base Module | ||
|
||
|
||
## senml_base.SenmlBase Objects | ||
|
||
|
||
the base class for all senml objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
|
||
# senml_pack Module | ||
|
||
|
||
## senml_pack.SenmlPack Objects | ||
|
||
|
||
represents a senml pack object. This can contain multiple records but also other (child) pack objects. | ||
When the pack object only contains records, it represents the data of a device. | ||
If the pack object has child pack objects, then it represents a gateway | ||
|
||
### __enter__ | ||
|
||
```Python | ||
__enter__(self) | ||
``` | ||
|
||
for supporting the 'with' statement | ||
|
||
|
||
_returns_: self | ||
|
||
### __exit__ | ||
|
||
```Python | ||
__exit__(self, exc_type, exc_val, exc_tb) | ||
``` | ||
|
||
when destroyed in a 'with' statement, make certain that the item is removed from the parent list. | ||
|
||
|
||
_returns_: None | ||
|
||
### __init__ | ||
|
||
```Python | ||
__init__(self, name, callback=None) | ||
``` | ||
|
||
initialize the object | ||
|
||
_parameters:_ | ||
|
||
- `name:` {string} the name of the pack | ||
|
||
### __iter__ | ||
|
||
```Python | ||
__iter__(self) | ||
``` | ||
|
||
|
||
|
||
### add | ||
|
||
```Python | ||
adds the item to the list of records | ||
``` | ||
|
||
|
||
_parameters:_ | ||
|
||
- `item:` {SenmlRecord} the item that needs to be added to the pack | ||
|
||
|
||
_returns_: None | ||
|
||
### base_sum | ||
|
||
the base sum of the pack. | ||
|
||
|
||
_returns_: a number | ||
|
||
### base_time | ||
|
||
Get the base time assigned to this pack object. | ||
While rendering, this value will be subtracted from the value of the records. | ||
|
||
|
||
_returns_: unix time stamp representing the base time | ||
|
||
### base_value | ||
|
||
the base value of the pack. The value of the records will be subtracted by this value during rendering. | ||
While parsing, this value is added to the value of the records. | ||
|
||
|
||
_returns_: a number | ||
|
||
### clear | ||
|
||
```Python | ||
clear(self) | ||
``` | ||
clear the list of the pack | ||
|
||
|
||
|
||
_returns_: None | ||
|
||
### do_actuate | ||
|
||
```Python | ||
do_actuate(self, raw, naming_map, device=None) | ||
``` | ||
|
||
called while parsing incoming data for a record that is not yet part of this pack object. | ||
adds a new record and raises the actuate callback of the pack with the newly created record as argument | ||
|
||
_parameters:_ | ||
|
||
- naming_map: | ||
- `device:` optional: if the device was not found | ||
- `raw:` the raw record definition, as found in the json structure. this still has invalid labels. | ||
|
||
|
||
_returns_: None | ||
|
||
### from_cbor | ||
|
||
```Python | ||
from_cbor(self, data) | ||
``` | ||
|
||
parse a cbor data byte array to a senml pack structure. | ||
|
||
_parameters:_ | ||
|
||
- `data:` a byte array. | ||
|
||
|
||
_returns_: None | ||
|
||
### from_json | ||
|
||
```Python | ||
from_json(self, data) | ||
``` | ||
|
||
parse a json string and convert it to a senml pack structure | ||
|
||
_parameters:_ | ||
|
||
- `data:` a string containing json data. | ||
|
||
|
||
_returns_: None, will call the appropriate callback functions. | ||
|
||
|
||
|
||
### remove | ||
|
||
```Python | ||
remove(self, item) | ||
``` | ||
removes the item from the pack | ||
|
||
|
||
_parameters:_ | ||
|
||
- `item:` {SenmlRecord} the item that needs to be removed | ||
|
||
|
||
_returns_: None | ||
|
||
### to_cbor | ||
|
||
```Python | ||
to_cbor(self) | ||
``` | ||
|
||
render the content of this object to a cbor byte array | ||
|
||
|
||
_returns_: a byte array | ||
|
||
### to_json | ||
|
||
```Python | ||
to_json(self) | ||
``` | ||
|
||
render the content of this object to a string. | ||
|
||
|
||
_returns_: a string representing the senml pack object | ||
|
||
## senml_pack.SenmlPackIterator Objects | ||
|
||
|
||
an iterator to walk over all records in a pack | ||
|
||
### __init__ | ||
|
||
```Python | ||
__init__(self, list) | ||
``` | ||
|
||
|
||
|
||
### __iter__ | ||
|
||
```Python | ||
__iter__(self) | ||
``` | ||
|
||
|
||
|
||
### __next__ | ||
|
||
```Python | ||
__next__(self) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
# senml_record Module | ||
|
||
|
||
## senml_record.SenmlRecord Objects | ||
|
||
|
||
represents a single value in a senml pack object | ||
|
||
### __enter__ | ||
|
||
```Python | ||
__enter__(self) | ||
``` | ||
|
||
for supporting the 'with' statement | ||
|
||
|
||
_returns_: self | ||
|
||
### __exit__ | ||
|
||
```Python | ||
__exit__(self, exc_type, exc_val, exc_tb) | ||
``` | ||
|
||
when destroyed in a 'with' statement, make certain that the item is removed from the parent list. | ||
|
||
|
||
_returns_: None | ||
|
||
### __init__ | ||
|
||
```Python | ||
__init__(self, name, **kwargs) | ||
``` | ||
|
||
create a new senml record | ||
|
||
_parameters:_ | ||
|
||
- `kwargs:` optional parameters: | ||
- value: the value to store in the record | ||
- time: the timestamp to use (when was the value measured) | ||
- name: the name of hte record | ||
- unit: unit value | ||
- sum: sum value | ||
- update_time: max time before sensor will provide an updated reading | ||
- callback: a callback function taht will be called when actuator data has been found. Expects no params | ||
|
||
### do_actuate | ||
|
||
```Python | ||
do_actuate(self, raw, naming_map) | ||
``` | ||
|
||
called when a raw senml record was found for this object. Stores the data and if there is a callback, calls it. | ||
|
||
_parameters:_ | ||
|
||
- `raw:` raw senml object | ||
|
||
|
||
_returns_: None | ||
|
||
### sum | ||
|
||
|
||
|
||
### time | ||
|
||
get the time at which the measurement for the record was taken. | ||
|
||
|
||
_returns_: a unix time stamp. This is the absolute value, not adjusted to the base time of the pack. | ||
|
||
### update_time | ||
|
||
get the time at which the next measurement is expected to be taken for this record. | ||
|
||
|
||
_returns_: a unix time stamp. This is the absolute value, not adjusted to the base time of the pack. | ||
|
||
### value | ||
|
||
get the value currently assigned to the object |
Oops, something went wrong.