consentiumthings 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ import requests
2
+ from urllib.parse import urljoin
3
+
4
+
5
+ class ConsentiumThings:
6
+ BASE_URL = "https://consentiuminc.online/api/board/"
7
+
8
+ def __init__(self, board_key):
9
+ self.board_key = board_key
10
+ self.send_url = urljoin(self.BASE_URL, "updatedata")
11
+ self.receive_url = urljoin(self.BASE_URL, "getdata")
12
+ self.receive_recent_url = urljoin(self.BASE_URL, "getdata/recent")
13
+ self.session = requests.Session()
14
+
15
+ def begin_send(self, send_key):
16
+ self.send_key = send_key
17
+ self.send_url = f"{self.send_url}?key={send_key}&boardkey={self.board_key}"
18
+
19
+ def begin_receive(self, receive_key, recent=True):
20
+ self.receive_key = receive_key
21
+ base_url = self.receive_recent_url if recent else self.receive_url
22
+ self.receive_url = f"{base_url}?receivekey={receive_key}&boardkey={self.board_key}"
23
+
24
+ def send_data(self, data_buff, info_buff):
25
+ if len(data_buff) > 4 or len(info_buff) > 4:
26
+ raise ValueError("Only four sensor data points are allowed.")
27
+
28
+ sensor_data = [{"info": info, "data": str(data)} for data, info in zip(data_buff, info_buff)]
29
+ payload = {
30
+ "sensors": {"sensorData": sensor_data},
31
+ "boardInfo": {"firmwareVersion": "0.0", "architecture": "GenericPython"}
32
+ }
33
+
34
+ try:
35
+ response = self.session.post(self.send_url, json=payload)
36
+ response.raise_for_status()
37
+ print(response.text)
38
+ except requests.exceptions.RequestException as e:
39
+ print(f"An error occurred during sending data: {e}")
40
+
41
+ def receive_data(self):
42
+ try:
43
+ response = self.session.get(self.receive_url)
44
+ response.raise_for_status()
45
+ data = response.json().get('sensors', [])
46
+ except (requests.exceptions.RequestException, ValueError) as e:
47
+ print(f"An error occurred during receiving data: {e}")
48
+ return {}
49
+
50
+ sensor_data = {}
51
+ for item in data:
52
+ for sensor in item.get('sensorData', []):
53
+ sensor_type = sensor.get('info')
54
+ if sensor_type:
55
+ sensor_data.setdefault(sensor_type, []).append({'data': sensor.get('data'),
56
+ 'updatedAt': sensor.get('updatedAt')})
57
+ return sensor_data
@@ -0,0 +1 @@
1
+ from ConsentiumThings.ConsentiumThings import ConsentiumThings
@@ -0,0 +1 @@
1
+ from ConsentiumThings.ConsentiumThings import ConsentiumThings
@@ -0,0 +1,57 @@
1
+ import requests
2
+ from urllib.parse import urljoin
3
+
4
+
5
+ class consentiumthings:
6
+ BASE_URL = "https://consentiuminc.online/api/board/"
7
+
8
+ def __init__(self, board_key):
9
+ self.board_key = board_key
10
+ self.send_url = urljoin(self.BASE_URL, "updatedata")
11
+ self.receive_url = urljoin(self.BASE_URL, "getdata")
12
+ self.receive_recent_url = urljoin(self.BASE_URL, "getdata/recent")
13
+ self.session = requests.Session()
14
+
15
+ def begin_send(self, send_key):
16
+ self.send_key = send_key
17
+ self.send_url = f"{self.send_url}?key={send_key}&boardkey={self.board_key}"
18
+
19
+ def begin_receive(self, receive_key, recent=True):
20
+ self.receive_key = receive_key
21
+ base_url = self.receive_recent_url if recent else self.receive_url
22
+ self.receive_url = f"{base_url}?receivekey={receive_key}&boardkey={self.board_key}"
23
+
24
+ def send_data(self, data_buff, info_buff):
25
+ if len(data_buff) > 4 or len(info_buff) > 4:
26
+ raise ValueError("Only four sensor data points are allowed.")
27
+
28
+ sensor_data = [{"info": info, "data": str(data)} for data, info in zip(data_buff, info_buff)]
29
+ payload = {
30
+ "sensors": {"sensorData": sensor_data},
31
+ "boardInfo": {"firmwareVersion": "0.0", "architecture": "GenericPython"}
32
+ }
33
+
34
+ try:
35
+ response = self.session.post(self.send_url, json=payload)
36
+ response.raise_for_status()
37
+ print(response.text)
38
+ except requests.exceptions.RequestException as e:
39
+ print(f"An error occurred during sending data: {e}")
40
+
41
+ def receive_data(self):
42
+ try:
43
+ response = self.session.get(self.receive_url)
44
+ response.raise_for_status()
45
+ data = response.json().get('sensors', [])
46
+ except (requests.exceptions.RequestException, ValueError) as e:
47
+ print(f"An error occurred during receiving data: {e}")
48
+ return {}
49
+
50
+ sensor_data = {}
51
+ for item in data:
52
+ for sensor in item.get('sensorData', []):
53
+ sensor_type = sensor.get('info')
54
+ if sensor_type:
55
+ sensor_data.setdefault(sensor_type, []).append({'data': sensor.get('data'),
56
+ 'updatedAt': sensor.get('updatedAt')})
57
+ return sensor_data
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ConsentiumInc
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.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: consentiumthings
3
+ Version: 0.1
4
+ Summary: Sending sensor data to IoT server
5
+ Author: Debjyoti Chowdhury, Ph.D.
6
+ Author-email: <consentium.inc@gmail.com>
7
+ Keywords: Python,Internet of Things
8
+ Classifier: Development Status :: 1 - Planning
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: Unix
12
+ Classifier: Operating System :: MacOS :: MacOS X
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: requests
17
+
18
+
19
+ # ConsentiumThings
20
+ Python API to send and receive data for Consentium Cloud.
21
+
22
+ # Example usage
23
+
24
+ ```python
25
+ ct = ConsentiumThings("board-key")
26
+ ct.begin_send("send-key")
27
+ ct.send_data([1, 2, 3, 4, 5], ['info1', 'info2', 'info3'])
28
+
29
+ ct.begin_receive("receive-key", recent=False)
30
+ print(ct.receive_data())
31
+ ```
@@ -0,0 +1,9 @@
1
+ ConsentiumThings/ConsentiumThings.py,sha256=Oyko32zn6kDHX4LzWjdUwjEiaJAucn5RcoC6kDSgvuc,2412
2
+ ConsentiumThings/__init__.py,sha256=57XU_WX3xkvVdfNBSO6EAlOufOgaotGTcakD95uwky8,62
3
+ consentiumthings/__init__.py,sha256=57XU_WX3xkvVdfNBSO6EAlOufOgaotGTcakD95uwky8,62
4
+ consentiumthings/consentiumthings.py,sha256=haxu4l8wgypX8yReF1PGjffwm6cLCVLnUA44FtEmqm8,2412
5
+ consentiumthings-0.1.dist-info/LICENSE,sha256=PiDLg80aqwghi_SjUVR3cTwtVeBOeMxpql9ty3k0fds,1070
6
+ consentiumthings-0.1.dist-info/METADATA,sha256=o3pLB3k17EIng8LPRyKl3PnhSU1s_ihITrJeMlATIJY,879
7
+ consentiumthings-0.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
8
+ consentiumthings-0.1.dist-info/top_level.txt,sha256=Ws-ax-2yYkmUKZKIDPCHpUJZsdw9uaINg_Sj81BTEDU,17
9
+ consentiumthings-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.38.4)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ consentiumthings