Hi,
I am not sure if this is the correct place to ask this question, but the question relates to the Yun and runShellCommand.
I have written a sketch that requires a numeric input from the Console, it then reads a file to resolve the number to a name.
I have decided to write a python script that reads the file, the sketch passes the number to python via runShellCommand and python then returns the name. The sketch works, but I am now trying to move the reading of the file to a function and I am having issues. The function only reads or returns the First letter of the name.
Working script with runShellCommand python script in loop:
#include <Console.h>
#include <Process.h>
#include <Bridge.h>
String text;
void setup() {
Bridge.begin();
Console.begin();
Bridge.begin();
while (!Console);
Console.println("Select a number between 0..3");
}
void loop() {
Process p_read_list;
String person;
if (Console.available() > 0) {
char c = Console.read();
if (c == '\n') {
Console.print("You entered number: ");
Console.println(text);
Console.println("Searching for print...");
p_read_list.runShellCommand("/usr/bin/python /root/python/read_finger_file_txt/search_finger.py " + text);
while (p_read_list.running());
while (p_read_list.available()>0) {
char output = p_read_list.read();
person = person + output;
}
Console.print("Finger belongs to ");
Console.println(person);
Console.println("Select a number between 0..3");
text = "";
}
else {
text += c;
}
}
}
The not working script with runShellCommand python script in a function:
#include <Console.h>
#include <Process.h>
#include <Bridge.h>
String text;
void setup() {
Bridge.begin();
Console.begin();
Bridge.begin();
while (!Console);
Console.println("Select a number between 0..3");
}
void loop() {
if (Console.available() > 0) {
char c = Console.read();
if (c == '\n') {
Console.print("You entered number: ");
Console.println(text);
Console.println("Searching for print...");
String finger_result = id_finger_print(text);
Console.print("Finger belongs to ");
Console.println(finger_result);
Console.println("Select a number between 0..3");
text = "";
}
else {
text += c;
}
}
}
String id_finger_print(String f) {
Process p_read_list;
String person;
p_read_list.runShellCommand("/usr/bin/python /root/python/read_finger_file_txt/search_finger.py " + f);
while (p_read_list.running());
while (p_read_list.available()>0) {
char output = p_read_list.read();
person = person + output;
Console.println (output);
return person;
}
}
The Python Script(/root/python/read_finger_file_txt/search_finger.py):
#!/usr/bin/python
import sys
import os
found = 0
search = sys.argv[1]
f = open("/mnt/sda1/arduino/finger/prints.txt")
lines = f.readlines()
num = len(lines)
for finger in lines:
if search in finger:
line_split = finger.split (",")
person = line_split[1]
person = person.rstrip()
print (person)
found = 1
if found == 0:
print ("!NOBODY!")
f.close()
The contents of file(/mnt/sda1/arduino/finger/prints.txt):
0,Fernado
1,Fernado
2,George
3,George
I would really appreciate if someone could point out what I am doing wrong.
This is part of a larger project in which I have a fingerprint scanner with LED's and a Display. When all is completed it will HOPEFULLY send a Tweet and update Google Calender when a finger is scanned. Because I am not a programer the program is going to be too large for the Arduino, hence I am choosing python to read the file, update Twitter and Google Calender.
Thanks
Gregg