-
Notifications
You must be signed in to change notification settings - Fork 13
/
Luminosidad_GET.ino
70 lines (57 loc) · 1.61 KB
/
Luminosidad_GET.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
#include <Ethernet.h>
#include <SPI.h>
#define NUM_ARDUINO "X" //Poner en X el número de Arduino
const int LDRPin = A0;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY}; //Sustituir YY por el numero de MAC correcto
byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi
EthernetClient client;
void setup()
{
Serial.begin(9600);
// start the Ethernet connection:
Serial.println("inicializando red...");
//Ethernet.begin(mac, ip, DNS, gateway, subnet);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
for (;;)
;
}
else {
Serial.print("IP asignada por DHCP: ");
Serial.println(Ethernet.localIP());
}
delay(1000);
}
void loop()
{
//Leo datos de luminosidad
int luminosidad = analogRead(LDRPin);
//Conecto a Raspberry Pi
if (client.connect(ip_raspberrypi, 80)) {
Serial.println("connected");
client.println("GET /Graba_GET.php?arduino=" + String(NUM_ARDUINO) + "&IntensidadLuminosa=" + String(luminosidad) + " HTTP/1.1");
client.println("Host: miraspberry");
client.println("Connection: close");
client.println();
}
else {
Serial.println("connection failed");
}
//Espero respuesta raspberry Pi
while (client.available() == 0) {
//espero
Serial.print(".");
delay(100);
}
String webString = "";
//Leo respuesta Raspberry Pi
do {
char caracter_leido = client.read();
webString += caracter_leido;
delay(5);
} while (client.available() > 0);
Serial.print("He recibido de Raspberry Pi: ");
Serial.println(webString);
client.stop();
delay(5000);
}