Salve a tutti, sto realizzando un piccolo sensore (BMP180) che, cablato ad un ESP01 dovrebbe fare richieste POST con i vari dati al mio server.
Con ESP32 ho sempre usato la libreria HTTPClient.h ma compilando per "Generic ESP8266 Module" che è la board che ho sempre utilizzato per gli ESP01 noto che il compiler non riesce a linkare la libreria perché non la trova.
A voi il codice, grazie in anticipo.
#include <WiFiClientSecure.h>
#include <Adafruit_BMP085.h>
#include <HTTPClient.h> // Libreria che fa capricci
#include <Wire.h>
#define seaLevelPressure_hPa 1028.10
Adafruit_BMP085 bmp;
String temperature, pressure, alt;
String sensor = "BMP180";
const char* ssid = "***";
const char* password = "***";
const char* serverName = "***";
unsigned long lastTime = 0;
unsigned long timerDelay = 180000; // 3 MINUTES
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
delay(180000);
temperature = bmp.readTemperature();
pressure = bmp.readPressure();
alt = bmp.readAltitude();
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
HTTPClient http;
client.setInsecure(); // To allow unsecure connection
http.begin(client, serverName);
// If you need an HTTP request with a content type: application/json, use the following:
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{\"sensor\":\"" + sensor + "\",\"temperature\":\"" + temperature + "\",\"pressure\":\"" + pressure + "\",\"altitude\":\"" + alt + "\"}");
http.end();
}
lastTime = millis();
}
}