0
votes

I have been working most of the day to get a Capacitive Soil Sensor to talk through my ESP32 DEVKITV1 to my InfluxDB setup on my Pi Server. I have successfully gotten my setup to read the sensor and to connect to the WIFI in my house, but I have not been able to get it to talk to my InfluxDB yet.

I am using the libraries for InfluxDB handling forked by davidgs at https://github.com/davidgs/ESP8266_Influx_DB_V2. This is my first ESP32 project, and I haven't touched C since college 15 years ago....

My setup:

  • Hardware: ESP32 DEVKIT (ESP32-WROOM-32)
  • Software: Arduino IDE 1.8.13, Linux Mint 19.3 with Kernel 5.4.0-39-generic
  • Server = Raspberry PI 4, with influxdb installed to Docker via Portainer, using 8086 and 8083 ports.

My Code for the ESP32:

#include "WiFi.h"
#include "InfluxDbV2.h"

//Setup variables and definitions

//definitions for WIFI
#define WIFI_SSID "redacted"
#define WIFI_PASS "redacted"

int status = WL_IDLE_STATUS;//initial status for setup start

#define INFLUXDB_HOST "192.168.1.220"//pi_server static ip
#define INFLUXDB_PORT 8086//port for influxdb on pi_server

InfluxdbV2 influx(INFLUXDB_HOST, INFLUXDB_PORT);

float asoilmoist=analogRead(34);//variable holding moisture reading for sensor 1
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 600         /* Time ESP32 will go to sleep (in seconds) */

void setup()
{
  Serial.begin(115200); //Serial Print Deactivated if not needed
  delay(10);

    //Connect to WIFI   
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(WIFI_SSID);

    status = WiFi.begin(WIFI_SSID, WIFI_PASS);
    WiFi.setSleep(false);//to protect from it going to sleep 
    
  //While it's connecting, print a .
  while (status != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
    status = WiFi.begin(WIFI_SSID, WIFI_PASS);
  }
  //Success message once connected to wifi
  Serial.println("WiFi Connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  //influxdb setups
  influx.setOrg("default");
  influx.setBucket("db_soil_moisture");
  influx.setToken();

  //Success message
  Serial.println("Setup complete");

}
void loop()
{

   Serial.println((String)"Sensor 1 Soil Mosture:="+asoilmoist); //Debug Only

  //Setup data to be written to db
  InfluxDataV2 measurement ("Soil_Moisture");
  measurement.addTag("Sensor", "1");
  measurement.addValue("Value", asoilmoist);
  
  //Write the data to table
  influx.write(measurement);
  delay(5000); //wait for it to write if slow
 
   esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Go to Sleep for Time X 
   Serial.println((String)"Going to sleep "+TIME_TO_SLEEP); //for debugging
   esp_deep_sleep_start();
        
}
     

The error I'm currently fighting is:

Arduino: 1.8.13 (Linux), Board: "DOIT ESP32 DEVKIT V1, 80MHz, 921600, None"

/home/nathan/Arduino/test_soil_moisture_V2/test_soil_moisture_V2.ino: In function 'void setup()':
test_soil_moisture_V2:50:19: error: no matching function for call to 'InfluxdbV2::setToken()'
   influx.setToken();
                   ^
In file included from /home/nathan/Arduino/test_soil_moisture_V2/test_soil_moisture_V2.ino:3:0:
/home/nathan/Arduino/libraries/ESP8266_Influx_DB_V2/InfluxDbV2.h:28:8: note: candidate: void InfluxdbV2::setToken(String)
   void setToken(String token);
        ^
/home/nathan/Arduino/libraries/ESP8266_Influx_DB_V2/InfluxDbV2.h:28:8: note:   candidate expects 1 argument, 0 provided

exit status 1
no matching function for call to 'InfluxdbV2::setToken()'

I have tried to set the token with NULL, (), "", and with phony strings. Nothing seems to work. I've dove into the InfluxDbV2.cpp, InfluxDbV2.h, and InfluxDataV2.h files to try to solve this, but I have had zero success.

I'm hoping someone can help steer me in the correct direction.

1
Read the error message candidate expects 1 argument, 0 provided, which means that influx.setToken() is expecting 1 argument to be pass in, something like influx.setToken(token).hcheung

1 Answers

1
votes

@hcheung: thank you for your reply. I set the line to be influx.setToken("SomeFakeToken") and it removed the error candidate expects 1 argument, 0 provided but it still wouldn't compile correctly.

Then I noticed the line 'null' was not declared in this scope if(_token == null || _token.length() < 10){

which is the same error I've fought all weekend. Then I remembered reading how C requires NULL and js uses null. I updated the InfluxDbV2.cpp and changed null to NULL and it finally compiled!

Thanks for all your help!