Blynk Webhook and InfluxDB

I am trying to use the Blynk Webhook (local Blynk server on a Raspberry Pi 3) to pass data from a virtual pin to an Influx database (local sever on a different Raspberry Pi 3), but not having much luck. I use the Blynk app on and iPhone and iPad.

From the InfluxDB website, Influx (https://docs.influxdata.com/influxdb/v1.4/tools/api/#write) uses POST HTTP requests to write data into the database. And it works as expected from my Pi with a test value:

   pi@BlueberryPi:~ $ curl -i -XPOST "http://10.0.1.102:8086/write?db=arduino" --data-binary 'average value=41.29'

   HTTP/1.1 204 No Content
   Content-Type: application/json
   Request-Id: add75056-225b-11e8-8298-000000000000
   X-Influxdb-Version: 1.1.1
   Date: Wed, 07 Mar 2018 23:02:58 GMT

InfluxDB terminal logging display:

[httpd] 10.0.1.102 - - [07/Mar/2018:18:05:29 -0500] "POST /write?db=arduino HTTP/1.1" 204 0 "-" "curl/7.38.0" 07b9b0e1-225c-11e8-829a-000000000000 17531

Note that I have successfully directly written to an Influx database from a WiFi connected Arduino Yun using the string, or even more complex strings, as above, and I am successfully using Blynk Webhooks to push data from some home automation Arduino’s to a local ThingSpeak server (also on a Raspberry Pi 3).

However, when I use a Blynk Webhook for results on a virtual pin from an Arduino sketch where

URL: see above
Method: POST
Content Type: application/json
Body: empty

The InfluxDB terminal log displays:

[httpd] 10.0.1.103 - - [07/Mar/2018:18:14:36 -0500] "POST /write?db=arduino%20--data-binary%20%E2%80%98average%20value=3039.856%E2%80%98 HTTP/1.1" 404 87 "-" "-" 4d6d8aa2-225d-11e8-82a5-000000000000 478

And no value is entered into the database, although I can see the value for the pin changing with each write (until the write stops after 10 failures as per the Blynk default). I have tried different combinations of quoting for the URL, as well as using “&” for spaces, and a lot of Google’ing and searching the Blynk and InfluxDB sites, but no luck. Either an HTTP 400 or 404 error is displayed in the InfluxDB log. I also have tried the 3 different Webhook content types and that does not appear to solve the problem either.

Any thoughts as to why the Webhook fails to successfully write to the InfluxDB? As I noted above, it works brilliantly with my ThingSpeak server.

Thanks in advance for any help.

Regards,
John

Hello.

Seems like you have unnecessary space at the end of the url in your webhook widget.

I did get the Webhook to work after addressing the spaces and moving some of the URL call to the body.

But the new problem now is that for Webhook “Failed requests are requests that return status code that are not equal to 200 or 302.” As stated on the InfluxDB website, a successful HTTP write to InfluxDB returns a 204: “2xx: If your write request received HTTP 204 No Content, it was a success!” (https://docs.influxdata.com/influxdb/v1.5/guides/writing_data/). So, Webhook can only write 10 times to InfkuxDB before it stops because it received an HTTP 204.

-John-

1 Like

Thank you Dmitriy…I very much appreciate the help. As a note, the OpenWeatherMap also uses HTTP POST for contributors to that project and also returns an HTTP 204 when successful measurements are submitted to their server:

[POST] /measurements

This method is used to transfer measurements collected from your station. Full description of possible data structures is provided below. Measurements are transferred in an array which allows to specify several data sets at once and to perform a postponed sending. In case of successful measurements dispatch method returns an HTTP code 204.

-John-

Hi Dmitriy…updated my local Blynk server to v33.1 (Raspberry Pi 3) and it works brilliantly with InfluxDB (also running locally (on another Pi 3). The only issue is getting the HTTP body correct in the Webhook when multiple values are written as InfluxDB seems quite sensitive to spaces and new lines.

I did have a question with regards to server.properites and the Webhooks frequency user quota. Is the default value of 1 sec applied to each Webhook that is active or is it applied to all Webhooks that are active?

#this setting defines how often we can send webhooks. Specified in miliseconds webhooks.frequency.user.quota.limit=1000

Kind regards,
John

to all