Integrating the Raspberry Pi and camera into the database

In this section, we'll see how to send data to the server and integrate the elements that we have seen during previous chapters. In the following image, we can see the finished integration of the system:

This is the Sketch for the Arduino board:

    // Example web client using the Ethernet shield

// Include libraries
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xFE, 0x40 };

//IpAddress if DHCP fails
IPAddress ip(192,168,1,50);

// IP address of the Raspberry
IPAddress server(192,168,1,108);

// Initialize the Ethernet client
EthernetClient client;

void setup() {
// Open serial communications
Serial.begin(9600);

// Start the Ethernet connection
//if (Ethernet.begin(mac) == 0) {
// Serial.println("La Dirección IP se asigna por DHCP");
Ethernet.begin(mac, ip);

// Display IP
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());

// Give the Ethernet shield a second to initialize
delay(1000);
Serial.println("Conectando...");
}
void loop()
{
//variables to deploy
Serial.println("Humidity: " + hum);

if (client.connect(server, 80)) {
if (client.connected()) {
Serial.println("connected");

// Make a HTTP request:
client.println("GET /parking.php?valor1=" + valor1 + "&valor2=" + valor2 + " HTTP/1.1");
client.println("Host: 192.168.1.108");
client.println("Connection: close");
client.println();
}
else {
// If you didn't get a connection to the server
Serial.println("failed the connection");
}

// Read the answer
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}

// If the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("desconectado.");
client.stop();
}
}
// Repeat every second
delay(5000);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.156.250