LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone familiar with InfluxDB and REST?

Solved!
Go to solution

I've been given access to an InfluxDB database located on Amazon AWS, and asked if we could write data to it using HTTP.

I figured I would use JKI REST, and following the documentation (located here) this should not be a problem.

 

In the attached screenshot you can see I started with a "ping" request, which return the expected results.

The docs display examples using Curl, and the ping is

 

curl -sl -I localhost:8086/ping

 

Next I wanted to create a database. The docs says

curl -XPOST 'http://localhost:8086/query' --data-urlencode 'q=CREATE DATABASE "mydb"'

 As the screenshot shows, I try to give the request body a json string (since I understand that this is the correct content type).

I've tried many things here, but don't seem to get it right.

 

I'm not sure how to make certain that the string I give is "urlencoded" properly.

 

Does anyone here use InfluxDB with LabVIEW, or are familiar with HTTP?

 

I've seen, and tried, the following project on GitHub:

https://github.com/johanvandenbroek/InfluxDB-Client-LabVIEW

but the way it is made is not according to the docs, and does not work for me.

Maybe it was correct for an earlier version of InfluxDB.

 

Thank you for reading.

Message 1 of 5
(7,120 Views)
Solution
Accepted by topic author Oksavik

I've used the HTTP Client VIs for reading/writing InfluxDB. I don't think you need to supply a JSON formatted string to the query, but the result will be JSON formatted. I'd avoid LabVIEW's built in JSON VIs, as some of the query results from InfluxDB won't be handled correctly (nested arrays of strings and numerics for example). Instead the JSONtext library works very well.

 

Here's a quick and dirty example, minus the JSON parsing.

influxdb.png




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 2 of 5
(7,080 Views)

Thank you for your answer.

 

I had to try again now, seeing how your example was simpler then my earlier attempts.

 

It turns out that "q = CREATE DATABASE LabviewDB" is giving Error 400, but "q=CREATE DATABASE LabviewDB" is fine.

 

Always good too figure out what one does wrong, but sometimes very annoying when it's such a simple thing.

0 Kudos
Message 3 of 5
(7,075 Views)

Glad you solved it! Did you end up sending JSON messages, or just plain strings?

 

InfluxDB can be very particular about the query formatting, especially when it comes to strings and when to double quote, when to escape spaces, and when to just let it work out what is and isn't a string. All the relevant info is in the InfluxDB docs, but they are a little scatter brained, so I always have 3 or 4 tabs open at once to jump between bits and pieces of info.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 4 of 5
(7,056 Views)

Just plain string as input. Feels like I tried all variations, but apparently the spaces were the key.

 

It seems to be working very well, so now we'll just have to learn how to use this type of database properly.

Thank you again! 🙂

 

 

0 Kudos
Message 5 of 5
(7,048 Views)