Hallo zusammen.
Ich bin zum ersten mal im Arduino Forum unterwechs und somit noch nicht so vertraut mit der Materie.
Mein aktuelles Problem besteht darin, dass ich mit ein Temperatur / Luftdruck Sketch, welchen ich für den EPS8266 und MPL3115A2 angepasst habe, nicht korrekt nutzen kann.
Demnach werden beim ersten Durchlauf die korrekten Sensordaten ausgegeben, jedoch danach nur noch die temperatur.
Leider komme ich nicht von selbst auf den fehler.
Es kommt mir fast so vor, als wenn die Adafruit_MPL3115A2.h hier etwas im Hintergrund verändert.
Anbei der Code meines Sketchs:
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/cloud-weather-station-esp32-esp8266/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_MPL3115A2.h>
#include <Wire.h>
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
const char* ssid = "FRITZ!Box 7590 OE";
const char* password = "********";
//Your Domain name with URL path or IP address with path
const char* serverName = "http://********/esp-post-data.php";
// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /esp-post-data.php also needs to have the same key
String apiKeyValue = "********";
String sensorName = "MPL3115A2";
String sensorLocation = "Gewaechshaus";
//#define SEALEVELPRESSURE_HPA (1013.25)
unsigned long timerDelay = 10000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
if (! baro.begin()) {
Serial.println("Couldnt find sensor");
return;
}
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
float pascals = baro.getPressure();
pascals = pascals/100,0;
Serial.print(pascals); Serial.print(" hpa");
float altm = baro.getAltitude();
Serial.print(altm); Serial.print(" meters");
float tempC = baro.getTemperature();
Serial.print(tempC); Serial.println("*C");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
+ "&location=" + sensorLocation + "&value1=" + String(tempC)
+ "&value2=" + String(pascals) + "&value3=" + String(altm) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
// You can comment the httpRequestData variable above
// then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
//String httpRequestData = "api_key=tPmAT5Ab3j7F9&sensor=BME280&location=Office&value1=24.75&value2=49.54&value3=1005.14";
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
// If you need an HTTP request with a content type: text/plain
// http.addHeader("Content-Type", "text/plain");
//int httpResponseCode = http.POST("Hello, World!");
// 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("{\"value1\":\"19\",\"value2\":\"67\",\"value3\":\"78\"}");
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
Wie gesagt, wurde der Sketch ursprünglich für den BME280 geschrieben.
Das komplette Programm mit Code für die Datenbank und HTML-Seite findet man unter der im Code angegebenen URL.
Gruß
Domenico