我想检索在mqtt中发送的主题数据,我还使用xdb telegraf和chronograf来显示这些值的图形。但是,我想使用python程序和SQL根据主题检索这些值。你知道吗
我从一些代码开始,但是我不能定义我想要的主题。 我使用此SQL查询:“SELECT%s from%s ORDER by time DESC LIMIT 1”获取最后一个值,但它不依赖于主题。。。。你知道吗
Chronograf上的SQL查询取决于主题: 从“michelin”、“autogen”、“mqtt\u consumer”中选择mean(“I”)作为“mean\u I”,其中time>;:dashboardTime:和“topic”=“PI1”GROUP BY time(:interval:)FILL(null)
因此,我想根据主题PI1,但如何在SQL请求中实现它,我尝试添加:和topic='PI1',但它不起作用。如果有人能帮我。 感谢您的反馈。你知道吗
def run(element):
"""Instantiate a connection to the InfluxDB."""
host='localhost'
port=8086
dbname = 'michelin'
measurement = "michelin.autogen.mqtt_consumer"
device = element
user=""
password=""
results = read_energy_data(dbname,measurement,device)
return(results)
def read_energy_data(db, measurement, device):
client = InfluxDBClient(host='localhost', port='8086')
client.switch_database(db)
results = client.query(("SELECT %s from %s ORDER by time DESC LIMIT 1 ") % (device, measurement))
points = results.get_points()
for item in points:
return item[device]
目前没有回答
相关问题 更多 >
编程相关推荐