hi,
I have problem executing Python script from arduino code.
Python script do_p.py is located in /mnt/sda1/arduino/www/test.
It is inserting data to sqlite database by accepting script parameters ie. ./do_p.py 11.0 76.0
Script is working well under linux (adds record to table in database with values given as arguments).
Python script do_p.py
#!/usr/bin/python
import sqlite3 as lite
import sys
from sys import argv
script,Temp,Wilg = argv
con = lite.connect('test1.db')
with con:
cur = con.cursor()
cur.execute("INSERT INTO tablica VALUES(null,?,?)",(Temp,Wilg))
con.commit()
con.close()
Using arduino "Process" i try to run above script but without success...I tried runShellCommand() and begin-run with various configurations
Arduino sketch
Could somebody point me proper syntax to execute this Python script?
Another thing is that finally I want Script arguments be passed as arduino variables I belive something symilar to this:
I've executed some python scripts by similar way that your statement line commented and I haven't had problems. Even with passing parameters in the same way to you.
Make sure to give 755 permissions in /mnt/sda1/arduino/www/test folder.
hi,
I got it working with fixed values in python script. Changing line pointing to database in do_p.py fixed everything
#!/usr/bin/python
import sqlite3 as lite
import sys
con = lite.connect('/mnt/sda1/arduino/www/test/test1.db')
with con:
cur = con.cursor()
cur.execute("INSERT INTO tablica VALUES(null,111,222)"
con.commit()
con.close()
However I still don't know how can I pass value to Python script in Arduino sketch.
int i = 111;
int j = 112;
Process p;
p.runShellCommand("python /mnt/sda1/arduino/www/test/do_p.py $i $j");
it's not working (Python script from my first post). Any help what should I put instead of $i $j?
You do not need to declare these integer variables for passing to the python script call through Process.
I would make it by passing the parameters without '$' symbols. Then, you should parse these values of variables into the python script to do the db query.
#include <Process.h>
void setup() {
// Initialize Bridge
Bridge.begin();
// Initialize Serial
Serial.begin(9600);
// Wait until a Serial Monitor is connected.
while (!Serial);
}
void loop() {
// Do nothing here.
Process p; // Create a process and call it "p"
p.begin("/mnt/sda1/do_p.py"); // Process that launch the "do_p.py" command
p.addParameter("500"); // Add the parameter to "Temp"
p.addParameter("1000"); // Add the parameter to "Wilg"
p.run(); // Run the process and wait for its termination
// Print arduino logo over the Serial
// A process output can be read with the stream methods
while (p.available() > 0) {
char c = p.read();
Serial.print(c);
}
// Ensure the last bit of data is sent.
Serial.flush();
delay(10000);
}