Hi all, im currently sending data from a DHT22 sensor to InfluxDB Cloud without a problem.
I also had the idea of doing the same with the BMP180 sensor, but here i got a problem:
Yesterday I could not send information, apparently because i have accents in the bucket name and the fields, i fixed that and the circuit worked. But after 40 minutes app the error came back and the ESP32 stop sending data to InfluxDB.
Another problem it is that i don’t get the Error Message, its just a blank space.
Like: “Error Writing in InfluxDB: ‘Here should be the error code or message’”
client.writePoint(sensorReadings);
if(!client.writePoint(sensorReadings));
{
Serial.print("Error writing in InfluxDB: ");
Serial.println(client.getLastErrorMessage()));
}
Has anyone here had the same problem? the sensor itself works fine, just the influxDB part its giving me the headache.
My code is the following:
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#if defined(ESP32)
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#define DEVICE "ESP32"
#elif defined(ESP8266)
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti wifiMulti;
#define DEVICE "ESP8266"
#define WIFI_AUTH_OPEN ENC_TYPE_NONE
#endif
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
// WiFi AP SSID
#define WIFI_SSID "XXXXX"
// WiFi password
#define WIFI_PASSWORD "XXXXX"
// InfluxDB v2 server url, e.g. https://eu-central-1-1.aws.cloud2.influxdata.com (Use: InfluxDB UI -> Load Data -> Client Libraries)
#define INFLUXDB_URL "XXXXX"
// InfluxDB v2 server or cloud API authentication token (Use: InfluxDB UI -> Load Data -> Tokens -> <select token>)
#define INFLUXDB_TOKEN "XXXXXX"
// InfluxDB v2 organization id (Use: InfluxDB UI -> Settings -> Profile -> <name under tile> )
#define INFLUXDB_ORG "XXXXXXX"
// InfluxDB v2 bucket name (Use: InfluxDB UI -> Load Data -> Buckets)
#define INFLUXDB_BUCKET "XXXXXX"
// Set timezone string according to https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
// Examples:
// Pacific Time: "PST8PDT"
// Eastern: "EST5EDT"
// Japanesse: "JST-9"
// Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
#define TZ_INFO "WART4WARST,J1/0,J365/25"
// InfluxDB client instance with preconfigured InfluxCloud certificate
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
// InfluxDB client instance without preconfigured InfluxCloud certificate for insecure connection
//InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN);
// Data point
Point sensorReadings("BMP180");
//BME280
Adafruit_BMP085 bmp; // I2C
float temperature;
float altitude;
float pressure;
// Initialize BMP180
void initBMP(){
if (!bmp.begin(0x77)) {
Serial.println("Check your wiring!!");
while (1);
}
}
void setup() {
Serial.begin(115200);
// Setup wifi
WiFi.mode(WIFI_STA);
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
//Init BMP180 sensor
initBMP();
// Add tags
// sensorReadings.addTag("device", DEVICE);
// sensorReadings.addTag("location", "office");
// sensorReadings.addTag("sensor", "bme280");
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
// Check server connection
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection fails: ");
Serial.println(client.getLastErrorMessage());
}
}
void loop() {
// Get latest sensor readings
temperature = bmp.readTemperature();
altitude = bmp.readAltitude();
pressure = bmp.readPressure();
// Add readings as fields to point
sensorReadings.addField("temperature", temperature);
sensorReadings.addField("altitude", altitude);
sensorReadings.addField("pressure", pressure);
// Print what are we exactly writing
Serial.print("Writing: ");
Serial.println(client.pointToLineProtocol(sensorReadings));
// Write point into buffer
client.writePoint(sensorReadings);
if(!client.writePoint(sensorReadings));
{
Serial.print("Error writing in InfluxDB: ");
Serial.println(client.getLastErrorMessage()));
}
// Clear fields for next usage. Tags remain the same.
sensorReadings.clearFields();
// If no Wifi signal, try to reconnect it
if (wifiMulti.run() != WL_CONNECTED) {
Serial.println("Wifi connection lost");
}
// Wait 10s
Serial.println("Wait 10s");
delay(10000);
}