树莓派传感器数据存储与MySQL数据库使用指南
1. ThingSpeak数据上传脚本测试
在将传感器数据上传到ThingSpeak时,需要确保代码的正确性,特别是要替换API密钥和通道编号,否则会导致运行时错误。以下是处理连接异常和键盘中断的代码:
except Exception as err:
print("WARNING: ThingSpeak connection failed: {0}, "
"data: {1}".format(err, data))
# Sleep for 20 seconds
time.sleep(20)
except KeyboardInterrupt:
print("Thanks, bye!")
exit(0)
测试脚本时,按照以下步骤操作:
1. 输入命令运行脚本: $ python3 ./raspi_thingspeak.py 。
2. 让脚本运行几次迭代,然后使用 Ctrl+C 中断主循环。
运行脚本后,正常的输出示例如下:
Welcome to the ThingSpeak Raspberry Pi temperature sensor!
Press CTRL+C to stop.
Uploading 18.46 C, 65.23 F ... Response: 200 OK
Uploading 18.49 C, 65
超级会员免费看
订阅专栏 解锁全文
30

被折叠的 条评论
为什么被折叠?



