I have a database (1.8.4) that I am populating via a python script. I am trying to access this data so I can display it via a webserver created with node. I am using the influxdb client using the following code snippet:
const client = new Influx.InfluxDB
client.query(‘SELECT * from sensor ORDER by time DESC LIMIT 1’).then(results => {
The query is working as expected and is returning an object of Iresult.
At this point I would like to be able to assign the returned data into variables but no matter what I try I cannot see how to reference the elements.
If I console log the object I get the following output of the object:
[
{
time: 2021-03-16T16:47:41.000Z {
_nanoISO: ‘2021-03-16T16:47:41Z’,
getNanoTime: [Function: getNanoTimeFromISO],
toNanoISOString: [Function: toNanoISOStringFromISO]
},
AirTemp: 20.187,
CPUTemp: 54.53,
Depth: 268,
PHValue: 7.067613252197431,
WaterTemp: 19.187
},
groupsTagsKeys: ,
groupRows: [ { name: ‘sensor’, rows: [Array], tags: {} } ],
group: [Function: groupMethod],
groups: [Function: groupsMethod]
]
How would I access the element AirTemp as an example? (edited)
Hello @gashd1889,
Here’s a basic example:
$ python
>>> from influxdb import InfluxDBClient
>>> json_body = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
]
>>> client = InfluxDBClient('localhost', 8086, 'root', 'root', 'example')
>>> client.create_database('example')
>>> client.write_points(json_body)
>>> result = client.query('select value from cpu_load_short;')
>>> print("Result: {0}".format(result))
Have you tried formatting it like that?
Additionally I believe you’re going to need to have a similar structure as the json object in the example above with a field key and an array of field key and field values.