utilizzo esp8266 per collegarmi con il wifi ma non carica i dati..
#include "DHT.h"
#include <SFE_BMP180.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define SSID "xxxxx"
#define PASS "yyyyy"
#define SERVER "www.ma3.altervista.org"
String path_page = "/inserisci.php";
SoftwareSerial mySerial(9, 10);
SFE_BMP180 pressure; //Creo istanza pressione
#define DHTPIN 2 //Pin per rilevare la temperatura
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); //Creo istanza temperatura del tipo DHTTYPE
int count;
char status_p;
String cosaMandare;
double T, P, p0, a;
int errore_pressione = 0; //Per vedere se ci sono errori nell'inizializzazione del sensore BMP180. Impongo flag a zero.
String temp_title = "t=";
String umid_title = "u=";
String press_title = "p=";
String lux_title = "l=";
String temp, pressi, umid, lux; //Dati da inviare con il Wifi
int inLux = A2; //Pin per rilevare la luce
String response, response2;
void setup() {
Serial.begin(9600);
mySerial.begin(115200); //Solo per debug
delay(3000);
//Serial.println("INIZIO"); //Per debug
Serial.println("Start...");
}
void loop() {
sendData("AT+RST\r\n", 3000); //Resetta modulo
sendData("AT+GMR\r\n", 3000); //Ottieni info
//sendData("AT+CWLAP\r\n", 3000); //Momentaneamente tolto
sendData("AT+CWMODE=1\r\n", 1000);
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"\r\n";
sendData(cmd, 7000);
sendData("AT+CIFSR\r\n", 5000);
//Serial.println(" ");
if (pressure.begin())
{
// Serial.println("BMP180 inizializzato."); //Inizializzato con successo il sensore BMP180
}
else
{
// Serial.println("BMP180 non inizializzato.\n\n");
errore_pressione = 1; // errore pressione. Flag = 1.
}
//Serial.println(" ");
if (errore_pressione == 0) //Se il sensore è stato inizializzato correttamente...
{
status_p = pressure.startTemperature(); //Inizia a misurare la temperatura con sensore BMP180
if (status_p != 0) {
delay(status_p); // Wait for the measurement to complete
status_p = pressure.getTemperature(T);
if (status_p != 0)
{
// Print out the measurement:
/*Serial.print("Temperatura: ");
Serial.print(T,2); //Scrivi la temperatura (con due cifre dopo la virgola) in gradi Celsius
Serial.print("^C ");
*/
status_p = pressure.startPressure(3); //Inizia a misurare la pressione con sensore BMP180
if (status_p != 0)
{
// Wait for the measurement to complete:
delay(status_p);
status_p = pressure.getPressure(P, T);
if (status_p != 0)
{
// Print out the measurement:
/*Serial.print("Pressione: ");
Serial.print(P,2); //Scrivi pressione in mbar
Serial.print(" mb, ");
Serial.print(P*0.0295333727,2);
Serial.println(" inHg"); //e in inHg
*/
}
else
{
//Serial.println("error retrieving pressure measurement\n");
}
}
else
{
//Serial.println("error starting pressure measurement\n");
}
}
else
{
//Serial.println("error retrieving temperature measurement\n");
}
}
else
{
//Serial.println("error starting temperature measurement\n");
}
}
//Rilevazione temperatura e umidità
float temperatura; /*Temperatura che verrà inviata (scelgo la media tra i due valori misurati
DHT22 e BMP180)*/
delay(3000); //Attenzione: per il DHT22 frequenza di campionamento non superiore a 0,5 Hz (una volta ogni 2 secondi)
int temp_dht22 = (int)dht.readTemperature(); //Leggo il valore della temperatura in gradi C dall'istanza dht
delay(3000);
int umi_dht22 = (int)dht.readHumidity(); //Leggo il valore dell'umidità dall'istanza dht
delay(3000);
if ((float)temp_dht22 > 0 && errore_pressione == 0)
{
temperatura = (float)((temp_dht22 + T) / 2); //faccio la media
}
else
{
temperatura = (float)temp_dht22;
}
delay(2000);
int lux_value = analogRead(inLux); //Leggi valore di luce in una scala da 0 a 1023
int lux_perc = map(lux_value, 1023, 0, 0, 100); //percentuale
/*Serial.print("Luminosita': ");
Serial.print(lux_perc);
Serial.println("%");
*/
delay(2000);
temp = temp_title + (int)temp_dht22;
umid = umid_title + (int)umi_dht22;
pressi = press_title + (int)(P);
lux = lux_title + lux_perc;
cosaMandare=temp;
cosaMandare+="&";
cosaMandare+=umid;
cosaMandare+="&";
cosaMandare+=pressi;
cosaMandare+="&";
cosaMandare+=lux;
String cmd55 = "AT+CIPSTART=\"TCP\",\"";
cmd55 += SERVER;
cmd55 += "\",80\r\n";
sendData(cmd55, 2000); //Avvia connessione con server
//invio temperatura
String cmd2 = "GET ";
cmd2 += path_page;
cmd2 += "?";
cmd2 += cosaMandare;
cmd2 += " HTTP/1.1\r\nHost: ";
cmd2 += SERVER;
cmd2 += "\r\n\r\n";
String cmd3 = "AT+CIPSEND=";
cmd3 += cmd2.length();
cmd3 += "\r\n";
sendData(cmd3, 2000);//Lunghezza della richiesta
//delay(1000);
sendData(cmd2, 3000); //Richiesta
}
String sendData(String command, const int timeout)
{
response = "";
response2 = "";
count = 0;
mySerial.print(command); // invia il comando all' esp8266
long int time = millis();
while ((time + timeout) > millis())
{
while (mySerial.available())
{
char c = mySerial.read(); // componi la risposta coi caratteri ricevuti dal modulo
if (c == '\n' or c == '\r')
response2 += ' ';
else
response2 += c;
response += c;
count++;
}
}
Serial.print(response);
Serial.print(count);
return response;
}
che soluzione avete voi?
grazie.
[EDIT] canellato la password per ragioni di sicurezza e provacy Uwe [/EDIT]