L'idea finale, era quella di utilizzare i dati ricavati dal trasduttore, ed inserire in un sito web (per esempio wordpress) dove calcolare la temperatura attuale (ogni 30 minuti o 1 ora viene fatta la lettura), la temperatura max e minima giornaliera e da inizio anno. Qual'è la soluzione più semplice ? Il codice senza l'implementazione di Gdrive è:
/*
Web Server
A simple web server that shows the value of the analog input pins.
using a WiFi shield.
This example is written for a network using WPA encryption. For
WEP or WPA, change the Wifi.begin() call accordingly.
Circuit:
* WiFi shield attached
* Analog inputs attached to pins A0 through A5 (optional)
created 13 July 2010
by dlf (Metodo2 srl)
modified 23 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <WiFi.h>
#define DHT11_PIN 0 // define anlog port 0
byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(!(PINC & _BV(DHT11_PIN)))
{}; // wait forever until anlog input port 0 is '1' (NOTICE: PINC reads all the analog input ports
//and _BV(X) is the macro operation which pull up positon 'X'to '1' and the rest positions to '0'. it is equivalent to 1<<X.)
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN)) //if analog input port 0 is still '1' after 30 us
result |=(1<<(7-i)); //this position is 1
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
char ssid[] = "*****"; // your network SSID (name)
char pass[] = "******"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
// start serial port:
DDRC |= _BV(DHT11_PIN); //let analog port 0 be output port
PORTC |= _BV(DHT11_PIN); //let the initial value of this port be '1'
Serial.begin(9600);
Serial.println("Ready");
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin();
// you're connected now, so print out the status:
printWifiStatus();
}
void loop() {
byte dht11_dat[5];
byte dht11_in;
byte i;// start condition
PORTC &= ~_BV(DHT11_PIN); // 1. pull-down i/o pin for 18ms
delay(18);
PORTC |= _BV(DHT11_PIN); // 2. pull-up i/o pin for 40us
delayMicroseconds(1);
DDRC &= ~_BV(DHT11_PIN); //let analog port 0 be input port
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN); // read only the input port 0
if(dht11_in)
{
Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW
delay(1000);
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN); //
if(!dht11_in)
{
Serial.println("dht11 start condition 2 not met"); //wair for second response signal:HIGH
return;
}
delayMicroseconds(80);// now ready for data reception
for (i=0; i<5; i++)
{ dht11_dat[i] = read_dht11_dat();} //recieved 40 bits data. Details are described in datasheet
DDRC |= _BV(DHT11_PIN); //let analog port 0 be output port after all the data have been received
PORTC |= _BV(DHT11_PIN); //let the value of this port be '1' after all the data have been received
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
delay(2000); //fresh time
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// 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("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of each analog input pin
// Vengono caricati i dati sul webserver
client.print("Current humdity = ");
client.print(dht11_dat[0], DEC);
client.print(".");
client.print(dht11_dat[1], DEC);
client.print("% ");
client.print("temperature = ");
client.print(dht11_dat[2], DEC);
client.print(".");
client.print(dht11_dat[3], DEC);
client.print("C ");
client.println("</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();
Serial.println("client disonnected");
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Per ora leggo soltanto la temperatura attuale dal webserver di arduino anche da remoto.