Created
November 7, 2019 01:53
-
-
Save phuctu1901/a7822ea151a67f57d35933011303c747 to your computer and use it in GitHub Desktop.
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
import getopt | |
import signal | |
import time | |
import sys | |
import json | |
import wiotp.sdk.application | |
# Cấu hình cho application có khả năng kết nối tới server | |
myConfig = { | |
"auth" :{ | |
"key": "a-mmj3og-nvnmkrh1pc", | |
"token": "VXw8sfYtIhFJibD4_5" | |
} | |
} | |
# Khởi tạo một kết nối | |
client = wiotp.sdk.application.ApplicationClient(config=myConfig) | |
# Kết nối | |
client.connect() | |
# Sự kiện khi thiết bị gởi lên server | |
def myEventCallback(event): | |
str = "%s event '%s' received from device [%s]" | |
print(str % (event.format, event.eventId, event.device)) | |
# Gán sự kiện | |
client.deviceEventCallback = myEventCallback | |
commandData={'publishEvent':1} | |
# Dùng ứng dụng để gởi tín hiệu về thiết bị | |
client.publishCommand('RaspberryPi', 'pi001', "control_device", "json", commandData) | |
# Liên tục theo dõi các sự kiện từ thiết bị | |
while True: | |
client.subscribeToDeviceEvents() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment