Skip to content

Commit fbe7e6a

Browse files
committed
python-ecosys/kpn-senml: Add KPN SenML library.
1 parent 0c5880d commit fbe7e6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2468
-0
lines changed

python-ecosys/kpn-senml/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 KPN IoT
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

python-ecosys/kpn-senml/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Introduction
2+
3+
The KPN SenML library helps you create and parse [senml documents](https://tools.ietf.org/html/draft-ietf-core-senml-13)
4+
in both json and cbor format.
5+
6+
# key features
7+
8+
- Object oriented design.
9+
- built in support for [senml's unit registry](https://tools.ietf.org/html/draft-ietf-core-senml-12#section-12.1)
10+
- extensible for new data types
11+
- makes use of (but doesn't restrict to) KPN's predefined list of record names.
12+
- direct support to read/write in json and cbor format.
13+
- automatically adjusts record data with respect to base time, base value & base sum.
14+
15+
Please visit our [docs site](https://kpn-iot.github.io/senml-micropython-library) for more info.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-slate

python-ecosys/kpn-senml/docs/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Welcome to the API documet site for the micro-python version of KPN's SenML library.
2+
3+
Check out the [detailed docs](https://kpn-iot.github.io/senml-library/) for an in-depth explanation of all the features in the library.
4+
5+
The following api sections are available:
6+
7+
- [senml-base](./senml_base): the base class for all senml objects.
8+
- [senml-pack](./senml_pack): the class that represents root documents.
9+
- [senml-record](./senml_record): the class that stores sensor measurements
10+
- [senml-unit](./senml_unit): the list of all unit names that can be used.
11+
12+
13+
14+
copyright © 2018 KPN
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# senml_base Module
3+
4+
5+
## senml_base.SenmlBase Objects
6+
7+
8+
the base class for all senml objects.
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
2+
# senml_pack Module
3+
4+
5+
## senml_pack.SenmlPack Objects
6+
7+
8+
represents a senml pack object. This can contain multiple records but also other (child) pack objects.
9+
When the pack object only contains records, it represents the data of a device.
10+
If the pack object has child pack objects, then it represents a gateway
11+
12+
### __enter__
13+
14+
```Python
15+
__enter__(self)
16+
```
17+
18+
for supporting the 'with' statement
19+
20+
21+
_returns_: self
22+
23+
### __exit__
24+
25+
```Python
26+
__exit__(self, exc_type, exc_val, exc_tb)
27+
```
28+
29+
when destroyed in a 'with' statement, make certain that the item is removed from the parent list.
30+
31+
32+
_returns_: None
33+
34+
### __init__
35+
36+
```Python
37+
__init__(self, name, callback=None)
38+
```
39+
40+
initialize the object
41+
42+
_parameters:_
43+
44+
- `name:` {string} the name of the pack
45+
46+
### __iter__
47+
48+
```Python
49+
__iter__(self)
50+
```
51+
52+
53+
54+
### add
55+
56+
```Python
57+
adds the item to the list of records
58+
```
59+
60+
61+
_parameters:_
62+
63+
- `item:` {SenmlRecord} the item that needs to be added to the pack
64+
65+
66+
_returns_: None
67+
68+
### base_sum
69+
70+
the base sum of the pack.
71+
72+
73+
_returns_: a number
74+
75+
### base_time
76+
77+
Get the base time assigned to this pack object.
78+
While rendering, this value will be subtracted from the value of the records.
79+
80+
81+
_returns_: unix time stamp representing the base time
82+
83+
### base_value
84+
85+
the base value of the pack. The value of the records will be subtracted by this value during rendering.
86+
While parsing, this value is added to the value of the records.
87+
88+
89+
_returns_: a number
90+
91+
### clear
92+
93+
```Python
94+
clear(self)
95+
```
96+
clear the list of the pack
97+
98+
99+
100+
_returns_: None
101+
102+
### do_actuate
103+
104+
```Python
105+
do_actuate(self, raw, naming_map, device=None)
106+
```
107+
108+
called while parsing incoming data for a record that is not yet part of this pack object.
109+
adds a new record and raises the actuate callback of the pack with the newly created record as argument
110+
111+
_parameters:_
112+
113+
- naming_map:
114+
- `device:` optional: if the device was not found
115+
- `raw:` the raw record definition, as found in the json structure. this still has invalid labels.
116+
117+
118+
_returns_: None
119+
120+
### from_cbor
121+
122+
```Python
123+
from_cbor(self, data)
124+
```
125+
126+
parse a cbor data byte array to a senml pack structure.
127+
128+
_parameters:_
129+
130+
- `data:` a byte array.
131+
132+
133+
_returns_: None
134+
135+
### from_json
136+
137+
```Python
138+
from_json(self, data)
139+
```
140+
141+
parse a json string and convert it to a senml pack structure
142+
143+
_parameters:_
144+
145+
- `data:` a string containing json data.
146+
147+
148+
_returns_: None, will call the appropriate callback functions.
149+
150+
151+
152+
### remove
153+
154+
```Python
155+
remove(self, item)
156+
```
157+
removes the item from the pack
158+
159+
160+
_parameters:_
161+
162+
- `item:` {SenmlRecord} the item that needs to be removed
163+
164+
165+
_returns_: None
166+
167+
### to_cbor
168+
169+
```Python
170+
to_cbor(self)
171+
```
172+
173+
render the content of this object to a cbor byte array
174+
175+
176+
_returns_: a byte array
177+
178+
### to_json
179+
180+
```Python
181+
to_json(self)
182+
```
183+
184+
render the content of this object to a string.
185+
186+
187+
_returns_: a string representing the senml pack object
188+
189+
## senml_pack.SenmlPackIterator Objects
190+
191+
192+
an iterator to walk over all records in a pack
193+
194+
### __init__
195+
196+
```Python
197+
__init__(self, list)
198+
```
199+
200+
201+
202+
### __iter__
203+
204+
```Python
205+
__iter__(self)
206+
```
207+
208+
209+
210+
### __next__
211+
212+
```Python
213+
__next__(self)
214+
```
215+
216+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
# senml_record Module
3+
4+
5+
## senml_record.SenmlRecord Objects
6+
7+
8+
represents a single value in a senml pack object
9+
10+
### __enter__
11+
12+
```Python
13+
__enter__(self)
14+
```
15+
16+
for supporting the 'with' statement
17+
18+
19+
_returns_: self
20+
21+
### __exit__
22+
23+
```Python
24+
__exit__(self, exc_type, exc_val, exc_tb)
25+
```
26+
27+
when destroyed in a 'with' statement, make certain that the item is removed from the parent list.
28+
29+
30+
_returns_: None
31+
32+
### __init__
33+
34+
```Python
35+
__init__(self, name, **kwargs)
36+
```
37+
38+
create a new senml record
39+
40+
_parameters:_
41+
42+
- `kwargs:` optional parameters:
43+
- value: the value to store in the record
44+
- time: the timestamp to use (when was the value measured)
45+
- name: the name of hte record
46+
- unit: unit value
47+
- sum: sum value
48+
- update_time: max time before sensor will provide an updated reading
49+
- callback: a callback function taht will be called when actuator data has been found. Expects no params
50+
51+
### do_actuate
52+
53+
```Python
54+
do_actuate(self, raw, naming_map)
55+
```
56+
57+
called when a raw senml record was found for this object. Stores the data and if there is a callback, calls it.
58+
59+
_parameters:_
60+
61+
- `raw:` raw senml object
62+
63+
64+
_returns_: None
65+
66+
### sum
67+
68+
69+
70+
### time
71+
72+
get the time at which the measurement for the record was taken.
73+
74+
75+
_returns_: a unix time stamp. This is the absolute value, not adjusted to the base time of the pack.
76+
77+
### update_time
78+
79+
get the time at which the next measurement is expected to be taken for this record.
80+
81+
82+
_returns_: a unix time stamp. This is the absolute value, not adjusted to the base time of the pack.
83+
84+
### value
85+
86+
get the value currently assigned to the object

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy