Hello all!
I need help with getting last value from field.
This is my dataset for influxdb:
def get_data_points(session,runNo):
timestamp=datetime.datetime.utcnow().isoformat()
datapoints = [
{
“measurement”: session,
“tags”: {“runNum”: runNo,
},
“time”: timestamp,
“fields”: {
“Voltage”:voltage_value,“Amperage”:amperage_value,“Power”:power_value
}
}
]
return datapoints
For query I tried to use the following:
voltage = “Voltage”
measurement = “11”
client = InfluxDBClient(host, port, user, password, dbname)
def read_voltage_data(voltage, measurement):
results = client.query((“SELECT %s from %s ORDER by time DESC LIMIT 1”) % (voltage, measurement))
points = results.get_points()
for item in points:
return item [voltage]
Value = read_voltage_data(voltage, measurement)
print(Value)
This code returns:
InfluxDBClientError: 400: {“error”:“error parsing query: found 11, expected identifier at line 1, char 21”}
which tells me that query syntax is wrong. But, I cannot see what I am doing wrong. FYI, Grafana’s query is (SELECT “Voltage” FROM “11” WHERE $timeFilter) and it works.