-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino.ini
88 lines (68 loc) · 2.18 KB
/
arduino.ini
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
/*
Project Name: SmartBoiler
Project Website: http://gcool.info/2013/10/20/smartboiler/
Description: Script to control arduino Yun
Version: 0.0
Author: George Koulouris
Author URI: http://gcool.info/
*/
#include <Process.h>
/* Include library to control the servo motor */
#include <Servo.h>
/* Define a variable for our servo motor */
Servo servoMain;
/* In my configuration, taking into account the length of the arm, the switch is turned off when the servo is at 160 deg */
int down = 160;
/* In my configuration, taking into account the length of the arm, the switch is turned on when the servo is at 10 deg */
int up = 10;
/* Define a variable to store the status of the switch (on or off) */
int pos;
void setup()
{
/* Initialize Bridge */
Bridge.begin();
/* Initialize Serial Port */
Serial.begin(9600);
/* The yellow cable of the servo is connected to pin 9. Red = 5V, Brown = GND */
servoMain.attach(9);
/* Switch off the heater */
pos = down;
servoMain.write(pos);
}
void loop()
{
/* Check whether the heater is turned on */
if (runCurl() == true) {
pos = up;
} else {
pos = down;
}
/* Update the position of the servo */
servoMain.write(pos);
/* Wait for 1s */
delay(1000);
}
bool runCurl() {
/* Launch "curl" command to check whether the heater is turned on
curl is command line program for transferring data using different internet protocols */
/* Create a process and call it "p" */
Process p;
/* Process that launch the "curl" command */
p.begin("curl");
/* Add the URL parameter to "curl". It actually checks a .txt file on my server. If it is 0, then the heater is switched off. Else it is switched on. */
p.addParameter("http://gcool.info/smartboiler/boiler_status.txt");
/* Run the process and wait for its termination */
p.run();
/* A process output can be read with the stream methods */
while (p.available()>0) {
char c = p.read();
/* Check whether the heater is turned on */
if (c=='0') {
/* If it is 0, then the heater is switched off... */
return false;
} else {
/* ...else it is switched on. */
return true;
}
}
}