Question! I was sending data and then it stops!

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);
}

@Jay_Clifford do you have any idea here?
Thank you.

Hi @AlvaroHP,
I am not quite sure what might be going on here. It sounds like a bug needs to be submitted: GitHub - tobiasschuerg/InfluxDB-Client-for-Arduino: Simple library for sending measurements to an InfluxDB with a single network request. Supports ESP8266 and ESP32.

Could you add a full log up until the error? I would be great to see the data before the issue occurs. I was wondering if it was a connectivity issue but looks like you are catching that after. So there seems to be something that InfluxDB is not accepting at that point.

Sorry my late response and thank you for answer my question.
It’s very weird because the code show me this in the serial monitor:

19:31:23.190 -> Syncing time.
19:31:23.683 -> Synchronized time: Wed Oct 12 19:31:23 2022
19:31:23.683 -> 
19:31:25.445 -> Connected to InfluxDB: https://us-east-1-1.aws.cloud2.influxdata.com
19:31:25.522 -> Writing: BMP180 temperature=24.40,altitude=174.38,pressure=99247.00
19:31:29.062 -> Write in InfluxDB FAILS: 
19:31:29.062 -> Wait 5 minutes
19:36:29.146 -> Writing: BMP180 temperature=24.00,altitude=174.55,pressure=99261.00
19:36:32.781 -> Write in InfluxDB FAILS: 
19:36:32.781 -> Wait 5 minutes

BUUUUT, the data is being send to influx, in the following image i’m seeing the pressure:

Also, today when i connected the esp32 to a external power supply i was seeing nothing (before was working fine :frowning: ), but now that i connected the esp32 to the usb port in my computer the sensor works just fine, although it keeps telling me that there is an error in the writing.
Maybe I’m misusing that part of the code and that’s why it doesn’t tell me the type of error.