Domotica spicciola con Arduino

Stimolato da questo incontro, ho preso qualche componente da Robot Italy (bravi e veloci), ho preso un DNS dinamico gratuito, e mi sono fatto la domotica più semplice e veloce possibile: il server della temperatura e della luce.

Il codice (che terrò aggiornato man mano che lo modifico):

/*
  Web Server Temp
 
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe
 modified 15 jan 2012
 by Gaspar Torriero
 
 */

#include <SPI.h>
#include <Ethernet.h>

int pagine = 0;
int inPin = 0; // Pin di lettura
int temp = 0; // variabile temperatura
int luce = 0; //variabile luce

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,30, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
{
  // start the Ethernet connection and the server:
  pinMode(9, OUTPUT);  
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  digitalWrite(9, LOW);    // set the LED off
  temp = ( 5.0 * analogRead(inPin) * 100.0) / 1024.0; // Conversione voltaggio sensore in temperatura
  luce = (analogRead(5) * 10000.0) / 1024.0; //Conversione voltaggio sensore in Lux
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("<html><head><title>Gasparduino Web Server Ver. 0.3</title><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ></head><body>");

          // output the value of analog input pins
          client.print("<h1>Gaspar Torriero gone Arduino</h1><hr />");
          client.println("<br />");
          client.print("Temperatura corrente: ");
          client.print(temp);
          client.print("°C");
          client.println("<br />");
          client.print("La luce è ");
          if (luce > 300) {
            client.print("accesa.");
          }
          else {
            client.print("spenta.");
          }
          client.println("<br />");
          pagine=pagine+1;
          client.print("Visite dall'ultimo riavvio: ");
          client.print(pagine);
          client.println("</body></html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    digitalWrite(9, HIGH);   // set the LED on
    delay(300);              // wait for a sec
    digitalWrite(9, LOW);    // set the LED off
    delay(300);              // wait for a sec
  }
}

Arduino a Lugano

Alle 18:00 di oggi presso la SUPSI di Canobbio si terrà un incontro con Tom Igoe dal titolo Quando il physical computing incontra il design e le arti multimediali. All’incontro sarà presente anche Massimo Banzi.

Mi chiedo se riuscitò a farmi autografare l’arduino.

 

Aggiornamento:

La presentazione di Tom Igoe si è incentrata sugli affascinanti lavori dei suoi studenti presso l’ITP. Quote of note:

if it is powered electrically, it has an internet connection by default

Quando l’ha detto, volevo abbracciarlo. Tra parentesi, il mio arduino è raggiungibile qui.

The evil 1%

Non mi riferisco alla distribuzione della ricchezza negli Stati Uniti ma al consumo della banda di internet nel mondo, e agli articoli allarmisitici che periodicamente ritornano a sbigottirsi davanti a un diagramma di Pareto.

Il succo del pezzo del NY Times a me pare un altro: le società telefoniche nel mondo sono rimaste parecchio indietro rispetto alla tecnologia che la gente ha già in casa o si porta già in tasca, e oggi rappresentano un vero e proprio freno all’adozione di internet.

Google+ o meno

Dave Winer:

The thing that makes Facebook great is that it incubated in the market with real users. It was made by real users. It was formed by actual use. One day at a time, one feature at a time, in public, every home run visible, and every mis-step.

Products like the one Google just announced are hatched at off-sites at resorts near Monterey or in the Sierra, and were designed to meet the needs of the corporation that created it. A huge scared angry corporation.

John Battelle:

(e Dave rincara la dose qui)