Nodemcu dht22 lettura in seriale ok invio dati a weather underground problemi

Buongiorno e buone feste a tutti,
tanto per non annoiarmi in questi giorni mi sono messo un po a trastullarmi con arduino, mi piacciono molto i dati sul meteo e dopo aver scoperto weather underground non ho saputo resistere.

Ho preso un NodeMcu, ci ho attaccato un sensore dht22, e da seriale riesco a leggere i dati, con questo codice:

#include "DHT.h"

#define DHTPIN 2

#define DHTTYPE DHT22 

DHT dht(DHTPIN, DHTTYPE, 6);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 
  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}

Poi ho fatto questa integrazione, ma delle variabili mi vanno out of scope :confused:

/**

#include "DHT.h"
#include <SoftwareSerial.h>

#define SSID "NETGEAR24" //Qua ho messo i dati della mia wifi
#define PASS "*********"

#define DHTPIN 2    
#define DHTTYPE DHT22 

char server [] = "weatherstation.wunderground.com";    
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "IARCOLA4";        //wunderground weather station ID            
String PASSWORD  = "******";   // wunderground weather station password  


SoftwareSerial esp8266Module(10, 11); // RX, TX

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.setTimeout(2000);

  while(!Serial) { }

  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("Running DHT!");
  Serial.println("-------------------------------------");

}

int timeSinceLastRead = 0;
void loop() {

  if(timeSinceLastRead > 2000) {
    float h = dht.readHumidity();
    float tempf = dht.readTemperature();
    float f = dht.readTemperature(true);

    if (isnan(h) || isnan(tempf) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      timeSinceLastRead = 0;
      return;
    }

    float hif = dht.computeHeatIndex(f, h);
    float hic = dht.computeHeatIndex(tempf, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\tempf");
    Serial.print("Temperature: ");
    Serial.print(tempf);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\tempf");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");

    timeSinceLastRead = 0;
  }
  delay(100);
  timeSinceLastRead += 100;
}

//-------------------------------------------------------------------
// Invio dati a weather underground
//-------------------------------------------------------------------

void wunderground(void)
{
 String cmd1 = "AT+CIPSTART=\"TCP\",\"";
  cmd1 += "rtupdate.wunderground.com"; // wunderground
  cmd1 += "\",80";
  esp8266Module.println(cmd1);

  if(esp8266Module.find("Error")){
    Serial.println("AT+CIPSTART error");
    return;
  }
   
  String cmd = "GET /weatherstation/updateweatherstation.php?ID=";
  cmd += ID;
  cmd += "&PASSWORD=";
  cmd += PASSWORD;
  cmd += "&dateutc=now&winddir=";  //Non ho compreso bene il suo significato
  cmd += "&tempf=";
 // cmd += tempf; Commentata perchè mi dice out of scope
  cmd += "&humidity=";
//  cmd += h;       Commentata perchè mi dice out of scope
  cmd += "&action=updateraw";  
  cmd += "/ HTTP/1.1\r\nHost: host:port\r\nConnection: close\r\n\r\n";

  delay(2500);
}

Guarda dove sono definite le variabili che danno errore e vedrai che sono effettivamente in un'altra funzione. O le rendi globali o le passi come parametri.

Guarda dove sono definite le variabili che danno errore e vedrai che sono effettivamente in un'altra funzione. O le rendi globali o le passi come parametri.

Grazie, le ho rese globali e tutto sembra funzionare.
Posso chiedere qualche delucidazione su questa riga? cmd += "&dateutc=now&winddir="; non riesco a capirla bene, devo mettere un orologio?

Non credo, è un parametro che passi al server, evidentemente quest'ultimo interpreta la stringa "now" e salva i dati con l'ora corrente.