Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ethernet2.h>
- #include <SoftwareSerial.h>
- #include <SPI.h>
- int ledPin = 12;
- int sensorPin = 4;
- int sensorValue;
- int lastTiltState = HIGH; // the previous reading from the tilt sensor
- // the following variables are long's because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long lastDebounceTime = 0; // the last time the output pin was toggled
- long debounceDelay = 50; // the debounce time; increase if the output flickers
- //communication serveur
- String tiltword = "boff";
- byte mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x59, 0x9B }; //mac arduino
- IPAddress ip(192,168,0,125); // ip arduino
- char server[] = "192.168.0.29"; // ip serveur (serveur maison)
- EthernetClient client;
- void setup(){
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB
- }
- Ethernet.begin(mac, ip);
- delay(1500); //delay
- Serial.println("ethernet !");
- pinMode(sensorPin, INPUT);
- digitalWrite(sensorPin, HIGH);
- pinMode(ledPin, OUTPUT);
- }
- void loop(){
- sensorValue = digitalRead(sensorPin);
- // If the switch changed, due to noise or pressing:
- if (sensorValue == lastTiltState) {
- // reset the debouncing timer
- lastDebounceTime = millis();
- }
- if ((millis() - lastDebounceTime) > debounceDelay) {
- // whatever the reading is at, it's been there for longer
- // than the debounce delay, so take it as the actual current state:
- lastTiltState = sensorValue;
- }
- digitalWrite(ledPin, lastTiltState);
- if (sensorValue == 1) {
- if (client.connect(server, 80)) {
- client.print("GET http://192.168.0.29/tilt/index.php?");
- client.print("tilt=");
- client.print(tiltword);
- client.println(" HTTP/1.1"); // Part of the GET request
- client.println("Host: 192.168.0.29");
- // client.println("Host: 10.73.3.1");
- client.println("Connection: close"); // ip serveur
- client.println();
- client.stop();
- }else {
- // If Arduino can't connect to the server (your computer or web page)
- // Serial.println("--> connection failed\n");
- }
- }
- Serial.println(sensorValue);
- delay(400);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement