This guide shows you how to query the data you’ve uploaded to EdgeGO’s InfluxDB by Python.
Overview
EdgeGO provides two ways to query your uploaded data:
- Using Grafana dashboards for visualization
- Direct API queries using HTTP requests
API Query Method
You can query your data programmatically using EdgeGO’s REST API. This method is useful for:
- Automated data retrieval
- Integration with external systems
- Custom data processing workflows
Python Script Example
Below is a complete Python script that demonstrates how to query data from EdgeGO’s InfluxDB:
import requests
import json
import csv
url = "https://server-edgego.local/v1/api/data/data-bucket/"
# modify the device_name and device_token
device_name = "MXE-1300-1"
device_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwidGltZXN0YW1wIjoiMjAyNS0wNi0xNiAwODozOTowNy4zMTUxNjMifQ.JIsJM35GslrhRiqehC_pWaS3JvqzWMvvkgfJ-wP4UPc"
# modify the time range and filter to get your data
query = """
|> range(start: 2025-06-16T00:00:00+08:00, stop: 2025-06-16T23:00:00+08:00)
|> filter(fn: (r) => r._field == "count")
"""
params = {
"type":"TimeSeries",
"query":query
}
url = url + device_name
try:
response = requests.get(
url,
verify=False,
params=params,
headers={"device-token":device_token},
)
response_dict = json.loads(response.text)
print(response_dict)
if response_dict["status"] == "success":
pass
else:
print("Failed to get data.")
print(response_dict["message"])
except Exception as e:
print(f"Error: {e}")
Script Parameters
Before running the script, you need to modify the following parameters:
Required Modifications
- url: Replace
https://server-edgego.local
with your actual EdgeGO server URL - device_name: Replace
MXE-1300-1
with your actual onboarded device name - device_token: Replace the token with your valid authentication token (obtain from
Server Settings → Token Management → Manage Token → Create Token
) - range: Modify the
start
andstop
timestamps in the query - filter: Adjust the
filter
function to match your data fields
Query Parameters
- type: fixed to TimeSeries
- query: InfluxDB Flux query string with:
range()
: Specifies the time window for data retrievalfilter()
: Filters data based on field names or values
Advanced Queries with Flux
For more complex queries, you can use the full power of InfluxDB’s Flux query language. The following examples can replace the query
variable in the Python script above:
Aggregation Example
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "temperature")
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
Multiple Fields Filter
|> range(start: -24h)
|> filter(fn: (r) => r._field == "temperature" or r._field == "humidity")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
For more advanced Flux query examples and documentation, please refer to the official InfluxDB Flux documentation.
API Endpoint
The API endpoint follows this pattern:
https://server-edgego.local/v1/api/data/data-bucket/{device_name}
Authentication
Include the device token in the request headers:
headers={"device-token": "your_device_token_here"}
Response Format
A successful response will contain:
status
: “success” for successful queriesdata
: The queried time-series datamessage
: Error message if the query fails
Response Sample
Here’s an example of a successful API response:
{
"status": "success",
"data": [
{
"result": "_result",
"table": 0,
"_start": "2025-06-16T08:58:29.924256+00:00",
"_stop": "2025-06-17T07:58:29.924256+00:00",
"_time": "2025-06-17T07:23:44.150506+00:00",
"_measurement": "test",
"dev": "True",
"count": 2
}
]
}
The response includes:
- status: Indicates whether the query was successful
- data: Array of data points matching your query
- Each data point contains:
- _time: Timestamp of the data point
- _measurement: The measurement name (table) where data is stored
- _start/_stop: Query time range boundaries
- Custom tags: Your uploaded data tags (e.g.,“dev” in the example)
- Custom fields: Your uploaded data fields (e.g.,“count” in the example)