Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfluxDB write failed: connection failed #216

Open
ewwachter opened this issue Apr 6, 2023 · 13 comments
Open

InfluxDB write failed: connection failed #216

ewwachter opened this issue Apr 6, 2023 · 13 comments

Comments

@ewwachter
Copy link

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= rssi=-84i
InfluxDB write failed: connection failed
Wait 10s

Specifications:

  • Library Version: latest
  • InfluxDB Version: 2
  • Board/ESP chip: ESP8266 Feather Huzzah board
  • Device Arduino SDK version: 2.0.3
@vlastahajek
Copy link
Collaborator

@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.

@ewwachter
Copy link
Author

ewwachter commented Apr 11, 2023

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

@vlastahajek
Copy link
Collaborator

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();

@ewwachter
Copy link
Author

I see. What should I define as TZ_INFO? I cannot find this information. I'm currently based in the UK

@vlastahajek
Copy link
Collaborator

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"

@ewwachter
Copy link
Author

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?

@ewwachter
Copy link
Author

ewwachter commented Apr 11, 2023

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

@vlastahajek
Copy link
Collaborator

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.

@ewwachter
Copy link
Author

It works! Many thanks.

So, essentially for some reason it is not working securely? is that the issue?

@vlastahajek
Copy link
Collaborator

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

@SPX10SF
Copy link

SPX10SF commented Sep 11, 2023

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

@vlastahajek
Copy link
Collaborator

@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

@SPX10SF
Copy link

SPX10SF commented Sep 12, 2023

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants