pikapython/test/python/iotcloud/test_basic_aliyun.py

35 lines
793 B
Python
Raw Normal View History

2022-12-16 22:27:19 +08:00
from PikaStdDevice import Time
import iotcloud
clientId = "pikascript"
productKey = "xxx"
deviceName = "test1"
deviceSecret = "xxxxx"
topic = "/" + productKey + "/" + deviceName + "/user/update"
print("iotcloud aliyun test")
c = iotcloud.new()
c.aliyun(clientId, productKey, deviceName, deviceSecret)
def up_cb(signal):
recv_msg = c.client.getMsg(signal)
recv_topic = c.client.getTopic(signal)
recv_qos = c.client.getQos(signal)
print("cb: %s-qos:%d-->>%s" % (recv_topic, recv_qos, recv_msg))
2022-12-16 22:27:19 +08:00
e = c.connect()
print("connect:", e)
if e == 0:
2022-12-16 23:57:27 +08:00
print("subcribe status:", c.subsribe(topic, up_cb))
2022-12-16 22:27:19 +08:00
for i in range(10):
2022-12-16 23:57:27 +08:00
print("publish status:", c.publish(topic, '{"id":'+str(i)+'}'))
Time.sleep_s(3)
2022-12-16 22:27:19 +08:00
a = c.disconnect()
print("disconnect status:", a)