Buona sera a tutti,
Sto cercando di sviluppare un progetto che dovrebbe:
- Rilevare temperatura ed umidità da alcuni sensori Dht11;
- Visualizzare i dati rilevati su un LCD;
- Salvare i dati rilevati Online - Tramite invio dei dati con board Enc28j60
Inizialmente ho realizzato due sketch di prova, uno per la visualizzazione ed uno per il salvataggio.
Dopo ho unito i due sketch rendendomi conto che non funziona come dovrebbe... Non veniva inviato nessun dato.
Ho pensato che il problema fosse dovuto al fatto che utilizzavo la funzione [delay per la parte che riguarda la visualizzazione] e [millis per il salvataggio], perciò ho tentato di capire come utilizzare millis, ma probabilmente invano visto che i dati vengono inviati solo una volta ogni tanto :~ :~
Ecco quì di seguito lo sketch che ho creato, sapreste aitarmi per risolvere il problema?
Ho provato in tantissimi modi, ma non sono stato capace di risolvere il problema
#include <EtherCard.h>
#include "DHT.h"
// LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define DHTPIN0 6 // what pin we're connected to
#define DHTPIN1 5 // what pin we're connected to
#define DHTPIN2 4 // what pin we're connected to
#define DHTPIN3 3 // what pin we're connected to
#define DHTPIN4 2 // what pin we're connected to
#define DHTPIN5 7 // what pin we're connected to
#define DHTPIN6 8 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT11 // DHT 11
DHT dht0(DHTPIN0, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);
DHT dht4(DHTPIN4, DHTTYPE);
DHT dht5(DHTPIN5, DHTTYPE);
DHT dht6(DHTPIN6, DHTTYPE);
// --------------------------------------------------
// ENC28J60
static byte mac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte ip[] = {192,168,1,7};
byte Ethernet::buffer[700];
#define ENC28J60_CS 10
char website[] PROGMEM= "www.fabbricaopensource.altervista.org"; // www.TUO_SITO_WEB.it
char buffer[70];
unsigned long time_last = 0;
boolean flag;
byte interval = 5; // seconds - intervello di tempo tra un invio di dati ed il successivo verso il server
static void response_callback (byte status, word off, word len){
Serial.println();
Serial.println( (char *) Ethernet::buffer + off);
Serial.println();
}
void setup (){
Serial.begin(9600);
// SENSORS
dht0.begin();
dht1.begin();
dht2.begin();
dht3.begin();
dht4.begin();
dht5.begin();
dht6.begin();
//-------------------------------------------------------------------
// ENC28J60
Serial.print("Verifica Enc28j60 ... ");
if ( ether.begin( sizeof Ethernet::buffer, mac, ENC28J60_CS) ){
Serial.println("\tsuccess");
}
else{
Serial.println("\tfailed");
}
Serial.print("Setting IP ... ");
if ( ether.dhcpSetup() ) {
Serial.println("\t\tsuccess");
}
else{
if ( ether.staticSetup(ip) ){
Serial.println("\t\tsuccess");
}
else{
Serial.println("\t\tfailed");
}
}
Serial.print("Verifica sito web ... ");
if (ether.dnsLookup( website )){
Serial.println("\tsuccess");
}
else{
Serial.println("\tfailed");
}
Serial.println();
Serial.print("Setup eseguito in :");
Serial.print(millis()/1000);
Serial.println("s");
Serial.println();
Serial.println();
}
void loop(){
//SENSORS
// data read:
float t0 = dht0.readTemperature();
float t1 = dht1.readTemperature();
float t2 = dht2.readTemperature();
float t3 = dht3.readTemperature();
float t4 = dht4.readTemperature();
float t5 = dht5.readTemperature();
float t6 = dht6.readTemperature();
float h0 = dht0.readHumidity();
float h1 = dht1.readHumidity();
float h2 = dht2.readHumidity();
float h3 = dht3.readHumidity();
float h4 = dht4.readHumidity();
float h5 = dht5.readHumidity();
float h6 = dht6.readHumidity();
// --------------------------------------------------------------
// --------------------------------------------------------------
ether.packetLoop(ether.packetReceive());
//if (millis()/1000 > time_last){
if ( (time_last = millis()/1000) % interval == 0 ){
flag = true;
}
//}
if (flag) {
flag = false;
//float temperature = dht.readTemperature();
char s_t1[5]; // 5 caratteri (5 char) perché il nostro numero decimale (float) è formato da: [ un intero a due cifre, un punto, un decimale, ed in fine si aggiungerà il terminatore di stringa (cioè \0) ]
dtostrf(t0, 4, 1, s_t1);
//float humidity = dht.readHumidity();
char s_h1[5]; // 5 caratteri (5 char) perché il nostro numero decimale (float) è formato da: [ un intero a due cifre, un punto, un decimale, ed in fine si aggiungerà il terminatore di stringa (cioè \0) ]
dtostrf(h0, 4, 1, s_h1);
sprintf(buffer, "t1=%s&u1=%s", s_t1, s_h1);
// Serial.print("sensor[]=temperature&value[]=%s&sensor[]=humidity&value[]=%s");
ether.browseUrl(PSTR("/work/pag/save.php?"), buffer, website, response_callback);
Serial.print(t0);
}
if (t0 != '0'){
// 1
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 1:");
lcd.setCursor(3, 1);
lcd.print(t0, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h0, 0);
lcd.print(" %");
delay(1000);
}
if (t1 != '0'){
// 2
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 2:");
lcd.setCursor(3, 1);
lcd.print(t1, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h1, 0);
lcd.print("%");
delay(1000);
}
if (h2 != '0.00'){
// 3
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 3:");
lcd.setCursor(3, 1);
lcd.print(t2, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h2, 0);
lcd.print("%");
delay(1000);
}/*
if (t3 != 'nan'){
// 4
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 4:");
lcd.setCursor(3, 1);
lcd.print(t3, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h3, 0);
lcd.print("%");
delay(1000);
}
if (t4 > '0'){
// 5
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 5:");
lcd.setCursor(3, 1);
lcd.print(t4, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h4, 0);
lcd.print("%");
delay(1000);
}
if (t5 > '0'){
// 6
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 6:");
lcd.setCursor(3, 1);
lcd.print(t5, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h5, 0);
lcd.print("%");
delay(1000);
}
if (t6 > '0'){
// 7
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Sensore 7:");
lcd.setCursor(3, 1);
lcd.print(t6, 0);
lcd.print(" C");
lcd.print((char)223);
lcd.print(" ");
lcd.print(h6, 0);
lcd.print("%");
delay(1000);
}
*/
}
Vi ringrazio in anticipo per l'aiuto che potrete darmi.
A presto,
Ivan.