Void loop

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.9 kB
1
Indexable
Never
void loop() {
  // try to parse packett
int packetSize = LoRa.parsePacket ();
Donnee donnee;
if (packetSize) {

uint8_t* x_tab = new uint8_t [sizeof (Donnee)];
int i = 0;
while (LoRa.available()) {
uint8_t     incoming = LoRa.read();
x_tab[i]  = incoming;
i++;
}
Donnee* x = (Donnee *) x_tab;
  Serial.print("L'identicatif de l'émetteur: ");
  Serial.println(x->id);
  Serial.print("Temperature1: ");
  Serial.print(x->temp1);
  Serial.print( "°C");
  Serial.print(" | Humidité1: ");
  Serial.print(x->hum);
  Serial.println("%");
  Serial.println("-----------------------------------");

delete x_tab;

}
    delay(1000);
      // wait for WiFi connection
  if (WiFi.status() == WL_CONNECTED) {

    HTTPClient http;

    //Set HTTP Request Final URL with Location and API key information
    http.begin(URL + "lat=" + lat + "&lon=" + lon + "&units=metric&appid=" + ApiKey);

    // start connection and send HTTP Request
    int httpCode = http.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {

      //Read Data as a JSON string
      String JSON_Data = http.getString();
      //Serial.println(JSON_Data);
            //Retrieve some information about the weather from the JSON format
      DynamicJsonDocument doc(2048);
      deserializeJson(doc, JSON_Data);
      JsonObject obj = doc.as<JsonObject>();

      //Display the Current Weather Info
      const char* description = obj["weather"][0]["description"].as<const char*>();
      const float temp = obj["main"]["temp"].as<float>();
      const float humidity = obj["main"]["humidity"].as<float>();

      Serial.println(description);
      Serial.print("Temperature : ");
      Serial.print(temp);
      Serial.print(" °C | ");
      Serial.print(" Humidité: ");
      Serial.print(humidity);
      Serial.println(" %");

    }
    http.end();
   
  }
  delay(10000);

}