python - 在raspberrypi上使用python将arduino的数据存储在mysql中

标签 python mysql python-2.7 arduino raspberry-pi

我已从此链接引用了代码:http://www.daviom.com/tutorial/tutorial-store-arduino-data-with-raspberry-pi-to-mysql/ arduino代码工作正常,但是python代码通过给出以下输出来执行,但不将值存储在数据库中,甚至在python代码执行时arduino上的tx灯闪烁,但值没有存储在数据库中

enter image description here

请有人帮助我,因为我是Python新手

在Python代码中取消注释打印语句后的输出 enter image description here #print("收到的值:"+string+ "解释为:项目 Id = "+projectId+"且 value = "+value) 不显示任何输出 arduino 的值不一致,第二条打印语句 enter image description here enter image description here enter image description here

最佳答案

你的arduino代码

Serial.println("xyz123 " + tempAsString);

发送

"xyz123 value"     ("value" is any float value)

到你的rasbperry,这个字符串存储在ardString中。
如果您写的是:

Serial.println("xyz123" + tempAsString);

然后

ardString  ->  "xyz123value"

valueMatrix = ardString.split(' ')  -> ["xyz123value"]

因此,len(valueMatrix) 等于 1,因此不会在数据库中写入任何内容。

<小时/>

相对于纠正arduino代码时打印中出现的下一个错误,将打印语句修改为(将string更改为ardString):

print("value received:" + ardString + " interpreted as: project Id = " + projectId + " and value = " + value)

关于python - 在raspberrypi上使用python将arduino的数据存储在mysql中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20922734/

相关文章:

python - 如何在 python 中使用 C 扩展来绕过 GIL

python - 为什么 python 不需要 python 的类型声明,其他方式是什么 adv。不声明类型?

php - 用于检查 MySQL 的 JavaScript 时间戳

python 2.7 : ImportError: DLL load failed: The specified module could not be found

python - "Flatten"列表中的一串单词

python - 删除所有包含字典中未包含单词的行

python - turtle 图形中的 turtle 方向?

c# - 如何使其成为适用于每台 Windows PC 的程序?

php - Crypt() 用户 ID 为字母数字,用于 API 请求 URL

python - Pygit2:为什么 merge 离开分支处于不干净状态?