Ciao a tutti,
con un arduino 2009 sto cercando di leggere i dati di due sensori.
Il BME280 e il SDS011 e inviare tutto via chiamata post con un esp01.
il BME280 funziona senza problemi.
Non appena importo la libreria SdsDustSensor.h e la decommento tutto il codice non sembra più funzionare e sulla Serial vengono stampati i caratteri sotto forma di punti interrogativi rovesciati (⸮). ho anche provato a cambiare il baudrate nel monitor ma la situazione non migliora.
Il sensore BME280 è collegato alle uscite A4 e A5, mentre esp01 alle uscite 8 e 9
C'è qualcosa che sto ignorando e che non riesco a vedere?
#include "WiFiEsp.h"
#include <Adafruit_BME280.h>
#include "SoftwareSerial.h"
//#include <SdsDustSensor.h>
void(* Reset_Arduino)(void) = 0;
SoftwareSerial esp8266(8, 9);
Adafruit_BME280 bme;
WiFiEspClient webClient;
int status = WL_IDLE_STATUS;
char ssid[] = "";
char password[] = "";
char server[] = "192.168.1.11";
int port = 5000;
void setup() {
Serial.begin(9600);
esp8266.begin(9600);
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
WiFi.init(&esp8266);
while ( status != WL_CONNECTED) {
status = WiFi.begin(ssid, password);
}
Serial.println("Connection ok");
}
void loop() {
Serial.println("loop");
float temperature;
float humidity;
float pressure;
float pm10;
float pm25;
temperature = bme.readTemperature();
pressure = bme.readPressure() / 100.0F;
humidity = bme.readHumidity();
char http_post[80];
char str_temperature[10];
char str_pressure[10];
char str_humidity[10];
char str_pm10[10];
char str_pm25[10];
dtostrf(temperature, 6, 2, str_temperature);
dtostrf(pressure, 6, 2, str_pressure);
dtostrf(humidity, 6, 2, str_humidity);
dtostrf(pm10, 6, 2, str_pm10);
dtostrf(pm25, 6, 2, str_pm25);
sprintf(http_post, "{\"t\":\"%s\", \"p\":\"%s\", \"h\":\"%s\", \"pm10\":\"%s\", \"pm25\":\"%s\"}", str_temperature, str_pressure, str_humidity, str_pm10, str_pm25);
if (webClient.connect(server, port)) {
webClient.println("POST /save-data HTTP/1.1");
webClient.println("Host: 192.168.1.11"); // or generate from your server variable to not hardwire
webClient.println("Connection: close");
webClient.print("Content-Length: ");
webClient.println(strlen(http_post));// number of bytes in the payload
webClient.println();// important need an empty line here
webClient.println(http_post);// the payload
}
else
{
Serial.println("Reset_Arduino");
Reset_Arduino();
}
delay(10000);
}