InfluxDB-Client-for-Arduino
InfluxDB-Client-for-Arduino copied to clipboard
InfluxDB write failed: connection failed
Steps to reproduce: I've tried to reproduce the basic write example: https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/blob/master/examples/BasicWrite/BasicWrite.ino I fulfilled the information, INFLUXDB_URL, INFLUXDB_TOKEN, INFLUXDB_TOKEN, INFLUXDB_ORG and INFLUXDB_BUCKET.
Expected behavior:
I would expect wifi connected and influxDB connect
Actual behavior:
Wifi is connected, but influxdb has error:
InfluxDB connection failed: connection failed
Writing: wifi_status,device=ESP8266,SSID=
Specifications:
- Library Version: latest
- InfluxDB Version: 2
- Board/ESP chip: ESP8266 Feather Huzzah board
- Device Arduino SDK version: 2.0.3
@ewwachter, make sure you have the correct Server URL, not http://localhost:8086.
If you are still unsure, enable debug and add a log, please.
Hi, thanks for the update, please see the log:
6.509 [D] Org: removed 6.512 [D] Bucket: removed 6.515 [D] Token: removed 6.524 [D] DB version: 2 6.527 [D] probeMaxFragmentLength to us-east-1-1.aws.cloud2.influxdata.com:443 6.744 [D] MFLN:yes 6.745 [D] setUrls 6.745 [D] writeUrl: https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write?org=removed&bucket=removed 6.748 [D] queryUrl: https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/query?org=removed 6.756 [D] Validating connection to https://us-east-1-1.aws.cloud2.influxdata.com/health 6.764 [D] GET request - https://us-east-1-1.aws.cloud2.influxdata.com/health 8.247 [E] Error - connection failed 8.248 [D] error -1: connection failed InfluxDB connection failed: connection failed 9.250 [D] writeRecord: bufferPointer: 1, batchPointer: 0, _bufferCeiling: 1 9.251 [D] Flushing buffer: is oversized true, is timeout false, is buffer full false 9.255 [D] Writing batch, batchpointer: 0, size 1 9.260 [D] Writing to https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write?org=removed&bucket=removed 9.271 [D] Sending: 9.279 [D] POST request - https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write?org=removed&bucket=removed, data: 81bytes, type text/plain 10.795 [D] HTTP status code - -1 10.796 [E] Error - connection failed 10.797 [D] error -1: connection failed
Please note that I've removed/replaced token, org, bucket values
As you are using HTTPS you should have started with the SecureWrite example. Your code most probably fails due to certificate validation. Add these lines before validating connection:
// Accurate time is necessary for certificate validation and writing in batches
// For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
// Syncing progress and the time will be printed to Serial.
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
// Alternatively, set insecure connection to skip server certificate validation
//client.setInsecure();
I see. What should I define as TZ_INFO? I cannot find this information. I'm currently based in the UK
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 "CET-1CEST,M3.5.0,M10.5.0/3"
I've tried with Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3" and it gives the same error, but now I can see the Synchronized time: Tue Apr 11 17:19:53 2023
Which is central europe and not the UK one. Can this be the issue? How can I find the TZ_INFO for UK?
I did manage to change the timezone:
#define TZ_INFO "GMT0BST,M3.5.0/1,M10.5.0/2"
Now I get the correct datetime, but still got the same error
Arduino Core for ESP8266 has a nice set of TZ constants: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h.
Try adding client.setInsecure(), please.
It works! Many thanks.
So, essentially for some reason it is not working securely? is that the issue?
It looks like the default included certificate doesn't work now. I will check later. You can add the new server certificate in your app if needed: https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino#secure-connection
Hi , @vlastahajek I m having the same issue using an ESP8266 running the basic write example , the error message is 01:56:34.755 -> 165.421 [D] POST request - http://192.168.0.31:8086/api/v2/write?org=9195xxxxxxxxf&bucket=ESP8266, data: 68bytes, type text/plain 01:56:34.755 -> [hostByName] Host: 192.168.0.31 is IP! 01:56:34.755 -> 170.439 [D] HTTP status code - -1 01:56:34.755 -> 170.440 [E] Error - connection failed 01:56:34.755 -> 170.440 [D] error -1: connection failed 01:56:34.755 -> 170.441 [D] Leaving data in buffer for retry, retryInterval: 0 01:56:34.755 -> 170.444 [D] Success: 0, _bufferPointer: 1, _batchPointer: 1, _writeBuffer[_bufferPointer]_0x3fff0fac 01:56:34.755 -> InfluxDB write failed: connection failed
Thank you very much for any support on this
@SPX10SF, there must be a connection problem between the ESP and the server. Check if you can reach the server from a different computer (e.g. from a mobile phone try load UI at http://192.168.0.31:808
Hi @vlastahajek , you re right , i m not able to access from a mobile phone . Mobile phone and computer are connected to the same wifi network . Looks like computer firewall is closing 8086 port . Thank you very much for your help !