Skip to content

Commit eab875a

Browse files
v0.1.9-rc1
- Improved ValueStore realtime update support - Bugfixes and improvements
2 parents 8eeb9b0 + 493248f commit eab875a

17 files changed

Lines changed: 188 additions & 108 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6+
tests/test.py
7+
development/
68
# Distribution / packaging
79
.Python
810
build/

HISTORY.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
11
# Release History
22

3+
## 0.1.9
4+
- Bugfixes and improvements
5+
6+
## 0.1.8
7+
- Support for realtime ValueStore Updates
8+
- Bugfixes
9+
10+
## 0.1.7
11+
- Improves support for commands
12+
- Bugfixes
13+
- Documentation improvements
14+
15+
## 0.1.6
16+
- Bug fixes
17+
- Added support for Command status update
18+
19+
## 0.1.5
20+
- Bug fixes
21+
22+
## 0.1.4
23+
- Bug fixes and improvement
24+
25+
## 0.1.3
26+
- Data submission to Anedya
27+
- Log submission to Anedya
28+
- Time synchronization
29+
- Device Binding
30+
31+
## 0.1.2
32+
- Bugfixes and improvements
33+
34+
## 0.1.1
35+
- Bugfixes
36+
37+
## 0.1.0
38+
- Introducing preliminary MQTT support for the Anedya SDK
39+
40+
## 0.0.9
41+
- Updated dependencies
42+
43+
## 0.0.8
44+
- Added support for Time Synchronization APIs
45+
46+
## 0.0.7
47+
- Bug fixes and improvement
48+
349
## 0.0.6
450
- Introducing Millisecond level resolution
551
- Streamlined Function Arguments
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# Emulate Hardware Sensor?
66
virtual_sensor = True
77
# Set the ID of the physical device
8-
deviceID = "<PHYSICAL-DEVICE-ID>"
8+
deviceID = "PHYSICAL_DEVICE_ID"
99
# Set the connection key for the device
10-
connectionKey = "<NODE-CONNECTION-KEY>"
10+
connectionKey = "CONNECTION_KEY"
1111

1212
# Note: It is assumed that the humidity sensor is attached at GPIO23 of the Raspberry Pi
1313

@@ -20,7 +20,7 @@
2020
def main():
2121
# Create a configuration object
2222
config = anedya.default_config()
23-
config.connection_mode = anedya.ConnectionMode.MQTT
23+
config.connection_mode = anedya.ConnectionMode.MQTT # Set the connection mode, HTTP or MQTT
2424
# Set the config parameters
2525
config.set_deviceid(deviceID)
2626
config.set_connection_key(connectionKey)
@@ -30,11 +30,10 @@ def main():
3030

3131
time.sleep(1)
3232
# Client is created, now connect with the MQTT server
33-
client.connect()
33+
client.connect() # if connection mode is http so comment this line
3434

3535
time.sleep(2)
36-
print(client._mqttclient.is_connected())
37-
36+
3837
if not virtual_sensor:
3938
for proc in psutil.process_iter():
4039
if proc.name() == "libgpiod_pulsein" or proc.name() == "libgpiod_pulsei":
@@ -86,8 +85,9 @@ def main():
8685
data.append(dp2)
8786

8887
client.submit_data(data)
89-
print("Data Pushed!")
88+
print("Data pushed to Anedya!")
9089
data.reset_datapoints()
90+
print("=============================")
9191
time.sleep(15)
9292

9393
client.disconnect()

examples/submitdata_http.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/valuestore_updates.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import anedya
2+
import time
3+
4+
# Set the ID of the physical device
5+
deviceID = "PHYSICAL_DEVICE_ID"
6+
# Set the connection key for the device
7+
connectionKey = "CONNECTION_KEY"
8+
9+
10+
def main():
11+
config = anedya.default_config()
12+
config.connection_mode = anedya.ConnectionMode.MQTT
13+
config.set_deviceid(deviceID)
14+
config.set_connection_key(connectionKey)
15+
config.set_on_vsupdate(callback=on_VSUpdate_callback)
16+
17+
# Create a client
18+
client = anedya.AnedyaClient(config)
19+
20+
time.sleep(1)
21+
# Client is created, now connect with the MQTT server
22+
client.connect()
23+
time.sleep(2)
24+
25+
input("Press Enter to continue after sending command...\n")
26+
print("Disconnecting")
27+
client.disconnect()
28+
29+
30+
def on_VSUpdate_callback(vs):
31+
print(f"Received VS updates from platform!")
32+
print(f"Namespace: {vs.namespace}, Type: {vs.type}, Key: {vs.key}, Value: {vs.value}, Modified: {vs.modified}")
33+
return
34+
35+
if __name__ == '__main__':
36+
main()

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = anedya-dev-sdk
3-
version = 0.1.7
3+
version = 0.1.9
44
url = https://github.com/anedyaio/anedya-dev-sdk-python
55
author = Anedya Systems
66
author_email = support@anedya.io
@@ -21,7 +21,7 @@ classifiers =
2121
Topic :: Software Development :: Libraries :: Python Modules
2222
project_urls =
2323
Documentation = https://docs.anedya.io
24-
Release notes = https://github.com/anedyaio/anedya-dev-sdk-python
24+
Release notes = https://github.com/anedyaio/anedya-dev-sdk-python/blob/main/HISTORY.md
2525
Source = https://github.com/anedyaio/anedya-dev-sdk-python
2626

2727
[bdist_wheel]

src/anedya/anedya.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, config: AnedyaConfig):
4646
self.on_connect = config.on_connect
4747
self.on_disconnect = config.on_disconnect
4848
self.on_command = config.on_command
49+
self.on_vsupdate = config.on_vsupdate
4950
self._mqttclient.on_connect = self._onconnect_handler
5051
self._mqttclient.on_disconnect = self._ondisconnect_handler
5152
# self._mqttclient.on_message = self.onmessage_handler
@@ -108,4 +109,4 @@ def disconnect(self):
108109
from .client.commandsNext import next_command
109110
from .client.timeSync import get_time
110111
from .client.mqttHandlers import _onconnect_handler, _ondisconnect_handler
111-
from .client.callbacks import _error_callback, _response_callback, _command_callback
112+
from .client.callbacks import _error_callback, _response_callback, _command_callback, _vsupdate_callback

src/anedya/client/bindDevice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _bind_device_http(self, binding_secret: str, timeout: float | None = None) -
4141
jsonResponse = r.json()
4242
payload = json.loads(jsonResponse)
4343
if payload['success'] is not True:
44-
raise AnedyaTxFailure(payload['error'], payload['errCode'])
44+
raise AnedyaTxFailure(payload['error'], payload['errorcode'])
4545
except ValueError:
4646
raise AnedyaTxFailure(message="Invalid JSON response")
4747
return True
@@ -75,5 +75,5 @@ def _bind_device_mqtt(self, binding_secret: str, timeout: float | None = None):
7575
self._transactions.clear_transaction(tr)
7676
# Check if transaction is successful or not
7777
if data['success'] is not True:
78-
raise AnedyaTxFailure(data['error'], data['errCode'])
78+
raise AnedyaTxFailure(data['error'], data['errorcode'])
7979
return

src/anedya/client/callbacks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from ..models import CommandDetails
2+
from ..models import CommandDetails, VSUpdate
33

44

55
def _response_callback(self, client, userdata, message):
@@ -32,3 +32,15 @@ def _command_callback(self, client, userdata, message):
3232
except Exception:
3333
pass
3434
return
35+
36+
37+
def _vsupdate_callback(self, client, userdata, message):
38+
payload_data = json.loads(message.payload)
39+
# This callback is called when a valuestore update is received.
40+
# Call the client callback
41+
try:
42+
vsupdate = VSUpdate(payload_data)
43+
self.on_vsupdate(vsupdate)
44+
except Exception:
45+
pass
46+
return

src/anedya/client/commandsNext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _next_command_http(self, timeout: float | None = None) -> tuple[CommandDetai
4040
jsonResponse = r.json()
4141
payload = json.loads(jsonResponse)
4242
if payload['success'] is not True:
43-
raise AnedyaTxFailure(payload['error'], payload['errCode'])
43+
raise AnedyaTxFailure(payload['error'], payload['errorcode'])
4444
# Payload has success now create a CommandDetails object and return
4545
command = CommandDetails()
4646
command.id = uuid.UUID(payload["commandId"])
@@ -89,7 +89,7 @@ def _next_command_mqtt(self, timeout: float | None = None) -> tuple[CommandDetai
8989
self._transactions.clear_transaction(tr)
9090
# Check if transaction is successful or not
9191
if data['success'] is not True:
92-
raise AnedyaTxFailure(data['error'], data['errCode'])
92+
raise AnedyaTxFailure(data['error'], data['errorcode'])
9393
try:
9494
if data['available'] is not True:
9595
return None, None

0 commit comments

Comments
 (0)