Search code examples
influxdbesp8266esp32

Reading a influx measurement using an esp32 and Ardino


I need to read a temperature present in an influx v1.8 database, using esp8266 and esp32 in Arduino. I am using the ESP8266 influxdb v3.12.1 library.

This query works from a command prompt:

curl --insecure -XPOST https://10.1.1.40:8086/api/v2/query -sS \                                     
           -H 'Accept:application/csv' \
           -H 'Content-type:application/vnd.flux' \
           -d 'from(bucket:"test01")
             |> range(start:-5m)
             |> filter(fn:(r) => r._measurement == "sens848a6a6")' 

In my Arduino code I have:

void loop() {
  String query = "from(bucket:\"test01\") |> range(start:-5m) |> filter(fn:(r) => r._measurement == \"sens848a6a6\")";
   
  // Send query to the server and get result
  FluxQueryResult result = client.query(query);
 
  // Check if there was an error
  if(result.getError() != "") {
    Serial.print("Query result error: ");
    Serial.println(result.getError());
  }
  
  while (result.next()) {
    // Get typed value for flux result column 'temperature'       
    String temp = result.getValueByName("temperature").getString();
    Serial.print("temperature: ");
    Serial.print(temp);
    // Get converted value for flux result column '_value' where there is temperature value
    long value = result.getValueByName("_value").getLong();
    Serial.print(value);
    Serial.println();
    }
}

But is not working:

Query result error: send header failed
temperature: 0

Help appreciated!


Solution

  • That send header failed might give us some hint on the Arduino SDK you are using. InflxuDB instance should be. The issue I assume should be inside the Arduino HTTP client. You should use Postman to mock the behavior of Arduino HTTP client, which set up the HTTP headers and send the Flux query in the body to see whether it works or not.

    Besides, you are using HTTPS, there was an issue of Arduino HTTP client calling HTTPS. You might just try HTTP first and then switch to HTTPS when the client is stable or you could provide the certificates.