python - 英特尔伽利略和 Python - 接口(interface)

标签 python interface arduino intel-galileo

我正在使用英特尔伽利略平台开发园艺系统。我将本地传感器数据与 openweathermaps 的预测结合使用。为了显示结果,如有必要,我会使用 Paraimpu 发推文。到目前为止,一切都很好。我现在正在寻找一种方法,让我的系统对包含触发词的传入推文使用react。我设法使用 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 接口(interface)不太有经验。感谢您的任何建议!

最佳答案

我的 Galileo 与 Python 接口(interface)的代码非常相似,我注意到两个差异可能会导致您的错误:

当我进行系统调用时,我将其保存为文件,而不是文本文件:

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");

关于python - 英特尔伽利略和 Python - 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28034877/

相关文章:

python - 如何减少 Python selenium Pyperclip.paste 执行时间

Python 简单 TCP 中继

interface - 在两个应用程序之间共享一个界面?

interface - Vagrant 正在尝试以需要 TTY 的方式与 UI 交互

java.lang.UnsatisfiedLinkError : no usbJava in java. 库路径

python - 用 Pandas 快速删除标点符号

python - 在 Python 中创建出版质量的几何图形

C# 最佳实践 : Using a delegate or an interface as a class dependency

c++ - 芯片的数据表没有说明如何与之通信

c - 将前导零添加到整数不起作用(arduino,c)