树莓派传感器数据存储与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)
务必将标记位置的API密钥替换为你自己的,否则会导致运行时错误。
测试脚本步骤如下:
1. 确保代码正确输入,无拼写错误或变量名错误。
2. 运行脚本:
$ python3 ./raspi_thingspeak.py
让脚本运行几分钟,使用 Ctrl + C 中断主循环。正常运行时,输出示例如下:
Welcome to the ThingSpeak Raspberry Pi temperature sensor!
Press CTRL+C to stop.
Uploading 18.46 C, 65.23 F ... Response: 200 O
超级会员免费看
订阅专栏 解锁全文
32

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



