-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGalileo_full_communication.txt
160 lines (101 loc) · 3.29 KB
/
Galileo_full_communication.txt
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <SPI.h>
#include <Ethernet.h>
// include <Process.h>
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0x98, 0x4F, 0xEE, 0x01, 0xDE, 0xFD };
//the IP address for the shield:
byte ip[] = { 169, 254, 26, 102 };
byte dns[] = { 8, 8, 8, 8 };
byte gateway[] = { 169, 254, 26, 1 };
byte subnet[] = { 255, 255, 255, 0 };
int red_led = 12;
int green_led = 13;
int sensorPin = A5;
double alpha = 0.75;
int period = 100;
double change = 0.0;
double minval = 0.0;
int counter = 0;
static const int max_counter = 1;
char buf[1000];
double lastRead = 0.0;
unsigned long initialTime;
unsigned long endTime;
unsigned long readLatency = 10;
boolean debug = true;
void setup()
{
Ethernet.begin(mac, ip, dns, gateway, subnet);
//Ethernet.begin(mac, ip);
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(red_led, OUTPUT);
pinMode(green_led, OUTPUT);
}
void loop () {
initialTime = millis();
// EthernetClient client;
lastRead = readAndSendHeart();
digitalWrite(red_led, LOW); // turn the LED off by making the voltage LOW
digitalWrite(green_led, LOW); // turn the LED off by making the voltage LOW
/* if ( lastRead > 988.0 && lastRead < 991.9 ) {
sprintf(buf,"%s&value%d=%2.6f",buf, counter, lastRead );
}
if (max_counter == counter ) {
sprintf(buf,"%s\n",buf);
counter =0;
int errorCode = system(buf);
// int errorCode = 0;
if ( debug ) {
Serial.print("Sending To Server ");
Serial.print(buf);
Serial.print(" code:");
Serial.print(errorCode);
Serial.println("");
}
*/
sprintf(buf,"curl http://169.254.26.128:3000/ecgs/2/new_ecgs?value=%2.6f",lastRead);
int errorCode = system(buf);
if (errorCode == 0)
{
digitalWrite(green_led, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
digitalWrite(red_led, HIGH); // turn the LED on (HIGH is the voltage level)
}
// sprintf(buf,"curl http://169.254.26.128:3000/ecgs/2/new_ecgs?value=%2.6f",lastRead);
// }
endTime = millis();
if ( debug ) {
Serial.print("Galileo IP: ");
Serial.println(Ethernet.localIP());
Serial.print("Initial time: ");
Serial.println(initialTime);
Serial.print("End time: ");
Serial.println(endTime);
Serial.print("difference ");
endTime = endTime - initialTime;
Serial.println(endTime);
Serial.print("Delay: ");
Serial.println(endTime > readLatency ? 0 : readLatency - endTime);
}
endTime = endTime - initialTime;
delay( endTime > readLatency ? 0 : readLatency - endTime );
//delay( 100);
}
//int webUnixTime (EthernetClient &client)
int readAndSendHeart ()
{
// Serial.println(Ethernet.localIP());
// Serial.println("Trying to connect to the server \n");
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead (sensorPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;
if ( debug ) {
Serial.print (rawValue);
Serial.print (",");
Serial.println (value);
//value = 232.12;
}
oldValue = value;
return (value -970)*6;
}