Salut,
Je fais actuellement un projet de terminal STI2D SIN, qui est une poubelle connecté. J'ai besoin de transférer les données des capteurs sur une base de donnée MySQL, du coup, j'utilise le shield ethernet, malheureusement, sûrement du au réseau pourrit du lycée dans lequel je me trouve, il y a toujours des problèmes alors que ça fonctionne à la maison ^^ ! Enfin bref, l'arduino n'arrive pas à se connecter à mon PC qui pourtant est une adresse IP Local. Alors, je n'ai peut être pas compris comment faire, pourtant j'ai bien lu les docs sur le site d'Arduino, tout ça tout ça. Je vous met mon code :
#include <SPI.h>
#include <Ethernet.h>
// Adresse MAC du SHIELD Ethernet
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0x50, 0x27
};
// Adresse IP du réseau
IPAddress ip(193,50,175,38);
// Initialisation librairie Ethernet
EthernetClient client;
// Adresse IP du serveur
IPAddress server(172,17,20,90);
// char server[] = "www.google.com";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers
void setup() {
// Port série :
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac, ip);
// print the Ethernet board/shield's IP address:
Serial.print("Adresse IP local: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.write(c);
}
// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server:
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("Connexion en cours...");
// send the HTTP GET request:
client.println("GET 172.17.20.90/Poubelle/arduino/data.php?id_poubelle=1&weight=30&amount=10 HTTP/1.1");
client.println("Host: xxx.xxx.xxx.xxx");
client.println("User-Agent: Deewens");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
}
Du coup, si vous pouviez m'expliquer si j'ai fait une erreur, et sinon, si vous avez déjà eu un problème de ce type sur un réseau de lycée (ou d'entreprise, fin bon ^^) Merci de votre aide !
Aurevoir, merci !