我尝试使用mqtt发布多个随机数据,以将数据从raspberry pi发送到ThingSpeakes。我想把temp的10个值发布到thingspeaks字段,但是它限制了我每15秒一个值。那么,有没有必要每隔15秒发送一个值列表,在thingspeaks频道中用图表表示时间??在
temp = []
current = []
while(1):
# get the system performance data over 20 seconds.
for i in range(10):
temp.append(random.randint(0, 100))
current.append(random.randint(0, 100))
# build the payload string.
payload = "field1=" + str(temp) + "&field2=" + str(current)
# attempt to publish this data to the topic.
try:
publish.single(topic, payload, hostname=mqttHost, transport=tTransport, port=tPort,auth={'username':mqttUsername,'password':mqttAPIKey})
print (" Published temp =",temp," current =", current," to host: " , mqttHost , " clientID= " , clientID)
except (keyboardInterrupt):
break
except:
print ("There was an error while publishing the data.")
time.sleep(15)
ThingSpeak支持批量更新,但您需要使用HTTP API而不是MQTT。在
下面是如何从Raspberry Pi收集数据并一次发送多个值。在
相关问题 更多 >
编程相关推荐