我正在使用Intel Galileo平台开发园艺系统。我将本地传感器数据与来自openweathermaps的预测结合使用。为了显示结果,如有必要,我使用Paraimpu进行鸣叫。到目前为止,一切都很好。我现在正在寻找一种方法,使我的系统对包含触发词的传入推文做出反应。我设法使用Twython编写了一个Python脚本来检查此触发词。如果有新的推文(在最后一分钟之内),则python脚本返回1,如果不为0。
[...]
if timedelta<triggertime:
erg = 1 #Neuer Tweet vorhanden
else:
erg = 0 #Kein neuer Tweet vorhanden
print erg
我被困在这里:当我调用python脚本本身时,它就可以正常工作。但是当在arduino代码中使用系统函数时,我没有得到数字,只是一些奇怪的格式化内容,例如:|cßBð¿这就是我在arduino代码中调用系统函数的方式:
char* checkTweets() {
char result[1];
system("python /media/realroot/Files/tweetcheck.py > /media/realroot/result.txt");
FILE *tempFile;
tempFile = fopen("result.txt", "r");
fgets(result, 1, tempFile);
fclose(tempFile);
return (result);
}
我对Arduino / Python接口的经验不是很丰富。感谢您的任何建议!
我在使用Galileo与Python进行接口时使用了非常相似的代码,并且注意到可能导致错误的两个差异:
进行系统调用时,我将其另存为文件,而不是文本文件:
system("python /media/realroot/Files/tweetcheck.py > /media/realroot/result");
也许将其另存为文本文件是导致奇数输出的原因?
或者,错误在于读取文件。完成此操作后,我使用了SD Arduino库(该文件#include <SD.h>
位于程序顶部),并读取文件:
File myfile = SD.open("result");
// read from file until we hit the a newline
while (myfile.peek() != '\n') {
result = myfile.parseInt();
}
result.close();
system("rm /media/realroot/result");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句