I have been successful sending data the Influx DB using the ESP32 Influx library. I need though to develop a lighter and more flexible means of sending data to Influx using just http post, without curl, but I have not found any examples that I can get working on ESP32. I connect to the URL but no data appears in the bucket. I think I may be failing at either the authentication via the authorization token and/or in the format of the data I am trying to send. Perhaps I also need to add the Org to the input??? Your inputs are appreciated. The core of the code is below. (diagnostic output also posted below).
#define IF_BUCKET "TESTBucket"
#define IF_DEVICE "TESTDevice"
#define IF_LOCATION "Lab"
#define IF_SENSOR "Channel_1"
#define IF_URL "influx.local:8086"
#define IF_TOKEN "OneLongToken==="
WiFiClient client;
HTTPClient http;
String HOST_LINE = (String)IF_URL + "/?bucket=" + IF_BUCKET;
ESP_LOGD(TAG, "HOST_LINE = %s", HOST_LINE.c_str());
http.begin(client, HOST_LINE);
http.addHeader("Authorization", (String)"Bearer " + IF_TOKEN);
// referred to https://docs.influxdata.com/influxdb/v1.8/guides/write_data/
String DATA_LINE = (String) "Energy,Device=" + IF_DEVICE + "," + "Location=" + IF_LOCATION + "," + "Sensor=" + IF_SENSOR + " " + "value=" "42"; // excluding timestamp
ESP_LOGD(TAG, "DATA_LINE = %s", DATA_LINE.c_str());
int httpResponseCode = http.POST(DATA_LINE);
ESP_LOGI(TAG, "HTTP Response code: %d", httpResponseCode);
// Free resources
http.end();
output:
[ 1826][D][main.cpp:84] setup(): [setup] HOST_LINE = http://192.168.1.211:8086/?bucket=TESTBucket
[ 1835][V][HTTPClient.cpp:252] beginInternal(): url: http://192.168.1.211:8086/?bucket=TESTBucket
[ 1844][D][HTTPClient.cpp:303] beginInternal(): protocol: http, host: 192.168.1.211 port: 8086 url: /?bucket=TESTBucket
[ 1855][D][main.cpp:94] setup(): [setup] DATA_LINE = Energy,Device=TESTDevice,Location=Lab,Sensor=Channel_1 value=42
[ 1865][D][HTTPClient.cpp:598] sendRequest(): request type: 'POST' redirCount: 0
[ 1901][D][HTTPClient.cpp:1156] connect(): connected to 192.168.1.211:8086
[ 1964][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'HTTP/1.1 200 OK'
[ 1964][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Accept-Ranges: bytes'
[ 1967][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Cache-Control: public, max-age=3600'
[ 1976][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Content-Length: 515'
[ 1983][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Content-Type: text/html; charset=utf-8'
[ 1992][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Etag: "5152816413"'
[ 1999][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Last-Modified: Wed, 28 Dec 2022 21:04:13 GMT'
[ 2009][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'X-Influxdb-Build: OSS'
[ 2016][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'X-Influxdb-Version: v2.6.1'
[ 2024][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: 'Date: Wed, 12 Apr 2023 22:29:29 GMT'
[ 2033][V][HTTPClient.cpp:1250] handleHeaderResponse(): RX: ''
[ 2038][D][HTTPClient.cpp:1307] handleHeaderResponse(): code: 200
[ 2044][D][HTTPClient.cpp:1310] handleHeaderResponse(): size: 515
[ 2050][D][HTTPClient.cpp:628] sendRequest(): sendRequest code=200
[ 2056][I][main.cpp:97] setup(): [setup] HTTP Response code: 200
[ 2062][D][HTTPClient.cpp:388] disconnect(): still data in buffer (515), clean up.
[ 2070][E][WiFiClient.cpp:517] flush(): fail on fd 48, errno: 11, "No more processes"
[ 2078][D][HTTPClient.cpp:393] disconnect(): tcp keep open for reuse