From 091f0c084f44ba6ce1656cdc73ab034abc881620 Mon Sep 17 00:00:00 2001 From: Luca Tringali Date: Mon, 11 Mar 2019 23:02:50 +0100 Subject: Rinomina file --- ethernet-servomotore.ino | 84 ------------------------------------------------ 1 file changed, 84 deletions(-) delete mode 100644 ethernet-servomotore.ino (limited to 'ethernet-servomotore.ino') diff --git a/ethernet-servomotore.ino b/ethernet-servomotore.ino deleted file mode 100644 index a4045e3..0000000 --- a/ethernet-servomotore.ino +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - - -#include - -Servo myservo; // create servo object to control a servo -int servopin = 3; - -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address - -char serverName[] = "codice-sorgente.it"; -char serverPage[] = "/UTCTime.php?zone=Europe/Rome"; -EthernetClient client; - -////////////////////// - -void setup(){ - - if (Ethernet.begin(mac) == 0) { - Serial.println("Failed to configure Ethernet using DHCP"); - // no point in carrying on, so do nothing forevermore: - while(true); - } - - Serial.begin(9600); - myservo.attach(servopin); - Serial.println("Init"); -} - -void loop(){ - delay(3000); - sendGET(); -} - -////////////////////////// - -void sendGET() //client function to send/receive GET request data. -{ - if (client.connect(serverName, 80)) { //starts client connection, checks for connection - Serial.println("connected"); -// client.println("GET /ioprogrammo/UTCTime.php HTTP/1.0"); //download text - client.print("GET "); - client.print(serverPage); - client.println(" HTTP/1.0"); - client.print("Host: "); - client.println(serverName); - client.println(); //end of get request - } - else { - Serial.println("connection failed"); //error message if no client connect - Serial.println(); - return; - } - -String response = ""; - while(client.connected() && !client.available()) delay(1); //waits for data - while (client.connected() || client.available()) { //connected or data available - char c = client.read(); //gets byte from ethernet buffer - response += c; - } - - Serial.println(response); - int da = response.indexOf("<")+1; - int a = response.indexOf(">"); - String pageValue = response.substring(da,a); - - da = pageValue.indexOf(" ")+1; - a = pageValue.indexOf(":",da); - String hour = pageValue.substring(da,a); - int ora = hour.toInt(); - int rotazione = map(ora, 0, 23, 0, 180); //può essere 90 invece di 180 - Serial.print("Writing this value to servo: "); - Serial.println(rotazione); - myservo.write(rotazione); - - Serial.println(); - Serial.println("disconnecting."); - Serial.println("=================="); - Serial.println(); - client.stop(); //stop client - -} - -- cgit v1.1