-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSEPINO_YUN_Arduino_sketch.ino
95 lines (69 loc) · 2.63 KB
/
SEPINO_YUN_Arduino_sketch.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <FileIO.h>
#include <Bridge.h>
Process myscript;
Process p;
Process chmod;
String path_to_file = //insert the path to the script file
// This function writes a Script in the path specified as input and make it executable
void uploadScript() {
File script = FileSystem.open(path_to_file, FILE_WRITE);
script.print("#!/bin/python\n");
script.print("\n");
script.print("import sys\n");
script.print("sys.path.insert(0, '/mnt/sda1/SEPA')\n");
script.print("from SEPINO import SEPA\n");
script.print("from JSAP import JSAP_file\n");
script.print("SEPA(JSAP_file).Subscribe('select * from <http://demoSEPINO> where { ?s ?p ?o }')");
script.close(); // close the file
chmod.begin("chmod"); // chmod: change mode
chmod.addParameter("755");
chmod.addParameter(path_to_file); // path fino al file al quale è riferito il processo
chmod.run();
}
// This function run the scripts written before
void runScript() {
myscript.begin("python" );
myscript.addParameter("path_to_file);
myscript.addParameter("-u");
myscript.runAsynchronously();
}
void setup() {
// First we delete last script to rewrite another one new
p.begin("rm" + path_to_file);
// Initialising PIN 9 and 13 setting them as OUTPUT
pinMode(13,OUTPUT);
pinMode(9,OUTPUT);
// Initialising Bridge and FileSystem communication
Bridge.begin();
Serial.begin(9600);
while (!Serial); // wait for Serial port to connect.
FileSystem.begin();
// Uploading and running the script specified before
uploadScript();
runScript();
}
void loop() {
// While there are data produced from the script, we stock them in a string and print it on serial monitor
while (myscript.available() > 0) {
String c = myscript.readString();
Serial.print(c);
// In this particular example, we check the temperature and humidity values contained in the notification messages:
// if they are higher than a treshold, arduino turns on alert LED, in particular a red LED on PIN 13 id it's too warm,
// a green LED on PIN 9 if it's too wet.
if (c.indexOf("caldo") > 0) {
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
}
if (c.indexOf("umido") > 0) {
digitalWrite(9, HIGH);
delay(5000);
digitalWrite(9, LOW);
}
}
// If there aren't incoming data from the script, we print dots on serial monitor
Serial.println(".");
// we continue flushing buffer to make them empty and ready to receive data from the script
Serial.flush();
delay(3000);
}