Intel Galileo 和 Python - 接口

Intel Galileo and Python - Interface

我正在使用 Intel Galileo 平台开发园艺系统。我将本地传感器数据与 openweathermaps 的预测结合使用。为了显示结果,我会在必要时使用 Paraimpu 发推文。到目前为止,一切都很好。我现在正在寻找一种方法让我的系统对包含触发词的传入推文做出反应。我设法使用 Twython 编写了一个 python 脚本来检查这个触发词。如果有新推文(在最后一分钟内),python 脚本 returns 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");