Influxdb v1.8 Query failed, code 400

Hello,

I have looked at all the forum posts on code 400 and have yet to find a fix.

I am not using a tag in my uploader, only measurements. I changed the upload history to different dates with no result. I have restarted the uploader multiple times, restarted the iotawatt, and my influx database.

There are many other services that are currently uploading to different databases without an issue.

Attached are the pertinent screenshots.

I do hope this is enough.

image

** Restart **

SD initialized.
6/07/22 18:16:02z Real Time Clock is running. Unix time 1654625762 
6/07/22 18:16:02z Reset reason: Software/System restart
6/07/22 18:16:02z Trace:  1:6[2], 1:6[2], 1:6[3], 1:5[19], 1:6[4], 1:6[6], 1:1[1], 1:2[2], 9:0[2], 9:0, 9:1, 8:4, 8:6, 8:8, 8:9, 9:3, 9:5, 9:9, 1:2, 1:3, 1:3, 1:6[1], 1:6[2], 1:6[2], 1:6[2], 1:6[3], 1:5[21], 1:6[4], 21:0, 21:1, 21:10, 21:10
6/07/22 18:16:02z ESP8266 ID: 15840746, RTC PCF8523 (68)
6/07/22 18:16:02z IoTaWatt 5.0, Firmware version 02_07_05
6/07/22 18:16:02z SPIFFS mounted.
6/07/22 13:16:02 Local time zone: -6:00, using DST/BST when in effect.
6/07/22 13:16:02 device name: IotaWatt
6/07/22 13:16:02 HTTP server started
6/07/22 13:16:02 influxDB_v1: Starting, interval:10, url:http://192.168.1.45:8086
6/07/22 13:16:02 influxDB_v2: Starting, interval:10, url:http://192.168.1.45:8087
6/07/22 13:16:02 timeSync: service started.
6/07/22 13:16:02 statService: started.
6/07/22 13:16:02 dataLog: service started.
6/07/22 13:16:02 dataLog: Last log entry 06/07/22 13:16:00
6/07/22 13:16:02 historyLog: service started.
6/07/22 13:16:02 historyLog: Last log entry 06/07/22 13:16:00
6/07/22 13:16:07 grid: Started
6/07/22 13:16:07 grid: Last log entry 06/07/22 13:16:00
6/07/22 13:16:55 WiFi connected. SSID=Not Internet, IP=192.168.1.6, channel=9, RSSI -90db
6/07/22 13:16:55 MDNS responder started for hostname IotaWatt
6/07/22 13:16:55 LLMNR responder started for hostname IotaWatt
6/07/22 13:16:55 Updater: service started. Auto-update class is MINOR
6/07/22 13:16:59 influxDB_v2: stopped, Last post 02/06/06 00:28:16
6/07/22 13:17:20 Updater: Invalid response from server. HTTPcode: -4
6/07/22 14:16:57 Updater: Auto-update is current for class MINOR.
6/09/22 19:51:07 influxDB_v1: stopped, Last post 02/06/06 00:28:16
6/09/22 19:52:19 WiFi disconnected.
6/09/22 19:52:27 WiFi connected. SSID=Not Internet, IP=192.168.1.6, channel=9, RSSI -95db
6/09/22 19:53:11 Restart command received.

** Restart **

SD initialized.
6/10/22 00:53:14z Real Time Clock is running. Unix time 1654822394 
6/10/22 00:53:14z Reset reason: Software/System restart
6/10/22 00:53:14z Trace:  1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:3, 1:1, 1:2[1], 9:0[1], 9:0, 9:1, 8:4, 8:6, 8:8, 8:9, 9:3, 9:5, 9:9, 1:2, 1:3, 10:2, 10:3
6/10/22 00:53:14z ESP8266 ID: 15840746, RTC PCF8523 (68)
6/10/22 00:53:14z IoTaWatt 5.0, Firmware version 02_07_05
6/10/22 00:53:14z SPIFFS mounted.
6/09/22 19:53:14 Local time zone: -6:00, using DST/BST when in effect.
6/09/22 19:53:14 device name: IotaWatt
6/09/22 19:53:14 HTTP server started
6/09/22 19:53:14 influxDB_v1: Starting, interval:10, url:http://192.168.1.45:8086
6/09/22 19:53:14 influxDB_v2: Starting, interval:10, url:http://192.168.1.45:8087
6/09/22 19:53:14 timeSync: service started.
6/09/22 19:53:14 statService: started.
6/09/22 19:53:14 dataLog: service started.
6/09/22 19:53:14 dataLog: Last log entry 06/09/22 19:53:10
6/09/22 19:53:14 historyLog: service started.
6/09/22 19:53:14 historyLog: Last log entry 06/09/22 19:53:00
6/09/22 19:53:19 WiFi connected. SSID=Not Internet, IP=192.168.1.6, channel=11, RSSI -67db
6/09/22 19:53:19 MDNS responder started for hostname IotaWatt
6/09/22 19:53:19 LLMNR responder started for hostname IotaWatt
6/09/22 19:53:19 Updater: service started. Auto-update class is MINOR
6/09/22 19:53:19 influxDB_v1: stopped, Last post 02/06/06 00:28:16
6/09/22 19:53:19 grid: Started
6/09/22 19:53:19 grid: Last log entry 06/09/22 19:53:10
6/09/22 19:53:20 Updater: Auto-update is current for class MINOR.
6/09/22 19:53:20 influxDB_v2: stopped, Last post 05/30/22 10:56:00
6/09/22 19:55:39 influxDB_v1: stopped, Last post 02/06/06 00:28:16
6/09/22 20:14:48 influxDB_v1: stopped, Last post 02/06/06 00:28:16
Jun  9 20:36:33 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:33 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" c2481dfa-e85d-11ec-83ff-9aea7f6c04b2 239
Jun  9 20:36:38 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:38 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" c5435e78-e85d-11ec-8406-9aea7f6c04b2 129
Jun  9 20:36:43 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:43 -0500] "POST /query HTTP/1.1 {'q': ' SELECT LAST(value) FROM 9_w '}, {'db': 'iotawatt'}, {'epoch': 's'}" 400 81 "-" "-" c83eb89b-e85d-11ec-840d-9aea7f6c04b2 203
Jun  9 20:36:48 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:48 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" cb3480e9-e85d-11ec-8412-9aea7f6c04b2 174
Jun  9 20:36:53 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:53 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" ce32e291-e85d-11ec-8418-9aea7f6c04b2 146
Jun  9 20:36:58 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:36:58 -0500] "POST /query HTTP/1.1 {'q': ' SELECT LAST(value) FROM 9_w '}, {'db': 'iotawatt'}, {'epoch': 's'}" 400 81 "-" "-" d12df968-e85d-11ec-841d-9aea7f6c04b2 133
Jun  9 20:37:03 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:03 -0500] "POST /query HTTP/1.1 {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}, {'db': 'iotawatt'}" 400 81 "-" "-" d428acb7-e85d-11ec-8423-9aea7f6c04b2 215
Jun  9 20:37:08 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:08 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" d7241ebb-e85d-11ec-842a-9aea7f6c04b2 122
Jun  9 20:37:13 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:13 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" da1fa3b1-e85d-11ec-8430-9aea7f6c04b2 133
Jun  9 20:37:18 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:18 -0500] "POST /query HTTP/1.1 {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}, {'db': 'iotawatt'}" 400 81 "-" "-" dd1ad7cf-e85d-11ec-8435-9aea7f6c04b2 154
Jun  9 20:37:23 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:23 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" e0120b1f-e85d-11ec-843c-9aea7f6c04b2 130
Jun  9 20:37:28 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:28 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" e30ee4e4-e85d-11ec-8441-9aea7f6c04b2 162
Jun  9 20:37:33 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:33 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" e60a277a-e85d-11ec-8448-9aea7f6c04b2 240
Jun  9 20:37:38 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:38 -0500] "POST /query HTTP/1.1 {'db': 'iotawatt'}, {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}" 400 81 "-" "-" e904ebc0-e85d-11ec-844f-9aea7f6c04b2 180
Jun  9 20:37:43 server1 influxd-systemd-start.sh[1756195]: [httpd] 192.168.1.6 - iotawatt [09/Jun/2022:20:37:43 -0500] "POST /query HTTP/1.1 {'epoch': 's'}, {'q': ' SELECT LAST(value) FROM 9_w '}, {'db': 'iotawatt'}" 400 81 "-" "-" ebfcc331-e85d-11ec-8454-9aea7f6c04b2 123

Did you create the “iotawatt” database on the influxdb server?

Without getting into recreating your issue, the log above shows the 400 response associated with the query of last value of measurement 9_w. When the influx uploader starts, queries are made to determine the time of the last value posted for each of the measurements so as to determine the point in time to resume uploading.

I’s possible that the query is simply failing due to a problem with the influx instance, or it’s possible that influx doesn’t like the name 9_w because IoTaWatt is not enclosing it in quotes.

So first thing I’d try is removing the measurement 9_w and see what happens.

I’d like to also point out that your WiFi signal strength (RSSI) is very weak. I’m surprised it’s working at all. I don’t see how that can result in a 400 response, but it could cause other problems.

UPDATE: I just recreated the problem by adding a measurement 9_w to a test system uploading to influxDB 1.8. It failed the same way and worked again once I deleted the measurement 9_w. I can add quotes to the query but it won’t help you now. Best bet is to change the name to something that is recognized as a string to the influx parser without quotes. In this case that would be starting with an alpha character rather than numeric.

1 Like

Yes. I forgot to mention the database has been working since May 23rd when I set it up. It stopped at 1:15 pm June 7th.

Thanks for the quick reply.

Strange influxdb doesn’t handle a query with a leading number.

I will give the change a shot.

See update above. Apparently the name works in the write line protocol but not in query. As long as the upload was running, no problem. Now trying to resume it needs the query to see where to begin.

2 Likes

It’s about the parser. As I understand it you can have just about anything in a string, but the parser will not recognize one that starts with a numeric unless it is enclosed in quotes. Most folks don’t start names with numerics because they are not accepted in many programming languages.

1 Like

That fixed it.

As soon as the name changed, iotawatt started dumping the history.

I am no programmer. The 9 was the breaker number and w for the watts. Thought I was being slick setting up a simple naming scheme.

1 Like