InlfuxDb in ESP8266 Arduino

Hi,

How I can create an InfluxDBClient client with parameters stored in the EEPROM?

The concerns is that I don’t now how to load the parameters that there was stored in the EEPROM because I create InfluxDBClient client before setup.

This is a example code:

#include <EEPROM.h>
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>

#define INFLUXDB_ORG      76
#define INFLUXDB_BUCKET   96
#define INFLUXDB_URL      116
#define INFLUXDB_POINT    146
#define INFLUXDB_TOKEN    166

char influxdb_org[20];     
char influxdb_bucket[20];  
char influxdb_url[30];     
char influxdb_point[20];  
char influxdb_token[100]; 

InfluxDBClient client(influxdb_url, influxdb_org, influxdb_bucket, influxdb_token, InfluxDbCloud2CACert); 
Point sensor(influxdb_point); 

void setup()
{
  Serial.begin(115200);

  EEPROM.get(INFLUXDB_DEVICE, influxdb_device);                      
  EEPROM.get(WIFI_SSID, wifi_ssid);                              
  EEPROM.get(WIFI_PASSWORD, wifi_password);                              
  EEPROM.get(INFLUXDB_ORG, influxdb_org);                                  
  EEPROM.get(INFLUXDB_BUCKET, influxdb_bucket);                               
  EEPROM.get(INFLUXDB_URL, influxdb_url);                            
  EEPROM.get(INFLUXDB_POINT, influxdb_point);                                
  EEPROM.get(INFLUXDB_TOKEN, influxdb_token);

  if(!client.validateConnection())
  {
    Serial.println(F("**Error de conexion**"));                                     
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

Thanks,

Hello @bullt1980,
Welcome!
Hmmm I’m not familiar with EEPROM but yes you’d have to instantiate the client after you get your authentication credentials.

Id try the getting started script first to get familiar with the client:

@Jay_Clifford is more familiar with all things IoT but he’s away on PTO for a little bit.

Hi @bullt1980,
you can declare client without parameters and set connection params later in setup:

#include <EEPROM.h>
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>

#define INFLUXDB_ORG      76
#define INFLUXDB_BUCKET   96
#define INFLUXDB_URL      116
#define INFLUXDB_POINT    146
#define INFLUXDB_TOKEN    166

char influxdb_org[20];     
char influxdb_bucket[20];  
char influxdb_url[30];     
char influxdb_point[20];  
char influxdb_token[100]; 

// Client without initial params
InfluxDBClient client; 
Point sensor(influxdb_point); 

void setup()
{
  Serial.begin(115200);

  EEPROM.get(INFLUXDB_DEVICE, influxdb_device);                      
  EEPROM.get(WIFI_SSID, wifi_ssid);                              
  EEPROM.get(WIFI_PASSWORD, wifi_password);                              
  EEPROM.get(INFLUXDB_ORG, influxdb_org);                                  
  EEPROM.get(INFLUXDB_BUCKET, influxdb_bucket);                               
  EEPROM.get(INFLUXDB_URL, influxdb_url);                            
  EEPROM.get(INFLUXDB_POINT, influxdb_point);                                
  EEPROM.get(INFLUXDB_TOKEN, influxdb_token);

  // Set params to client
  client.setConnectionParams(influxdb_url, influxdb_org, influxdb_bucket, influxdb_token, InfluxDbCloud2CACert);

  if(!client.validateConnection())
  {
    Serial.println(F("**Error de conexion**"));                                     
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}