pythoninterfacearduinointel-galileo

Intel Galileo and Python - Interface


I am working on a gardening system with the Intel Galileo platform. I'm using local sensor data in combination with forecasts from openweathermaps. To display the results, I use Paraimpu to tweet if necessary. So far, so good. I'm now looking for a way to let my system react to incoming tweets that contain a trigger word. I managed to write a python script using Twython that checks for this trigger word. If there is a new tweet (within the last minute), the python script returns 1, if not 0.

[...]
if timedelta<triggertime: 
    erg = 1 #Neuer Tweet vorhanden
else: 
    erg = 0 #Kein neuer Tweet vorhanden
print erg

And here I'm stuck: When I call the python script itself, it works just fine. But when using the system function in the arduino code, I don't get the number, just some weird formatted stuff like: |cßBð¿ That's how I call the system function in my arduino code:

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

I'm not very experienced in the Arduino / Python Interface. Thanks for any suggestions!


Solution

  • I have very similar code working with my Galileo interfacing with Python, and I notice two differences that could be causing your errors:

    When I make the system call, I save it as a file, not a text file:

    system("python /media/realroot/Files/tweetcheck.py > /media/realroot/result");
    

    Maybe saving it as a text file is what caused the odd output?

    Or, the error is in reading the file. When I did this, I used the SD Arduino library, which requires #include <SD.h> at the top of your program, and to read the file:

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