Skip to content

Commit 9dc9ed9

Browse files
committed
added main
1 parent 0a14a87 commit 9dc9ed9

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

datagen/bms/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import logging
2+
import time
3+
from kaa_client import KaaClient
4+
from bms_gateway import BMSGateway
5+
6+
# Change application version
7+
application_version = ''
8+
# If you revoked the token, update this value with new one
9+
token = 'room-1'
10+
11+
mqtt_host = 'mqtt.cloud.kaaiot.com'
12+
mqtt_port = 1883
13+
14+
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
15+
kaa_client = KaaClient(host=mqtt_host,
16+
port=mqtt_port,
17+
application_version=application_version,
18+
token=token)
19+
bms_gateway = BMSGateway(kaa_client)
20+
21+
# Command handlers
22+
kaa_client.add_command_handler("sensor_toggle", bms_gateway.sensor_toggle)
23+
kaa_client.add_configuration_status_handler(bms_gateway.configuration_handler)
24+
logging.info(
25+
f"""
26+
Connect to kaa using:
27+
Host: [{mqtt_host}]
28+
Port: [{mqtt_port}]
29+
Application version name: [{application_version}]
30+
Token: [{token}]
31+
"""
32+
)
33+
kaa_client.connect()
34+
35+
logging.info(f"Send device metadata [{bms_gateway.get_device_metadata()}]")
36+
kaa_client.publish_metadata(bms_gateway.get_device_metadata())
37+
while True:
38+
logging.info("Send BMS data")
39+
data_sample = bms_gateway.get_data_sample()
40+
logging.info(f"{data_sample}")
41+
kaa_client.publish_data_collection(data_sample)
42+
time.sleep(5)

0 commit comments

Comments
 (0)