I am using node-red-contrib-influxdb
I want to pass dynamic deviceId selected from dashboard(coming in msg.deviceId) to below query field deviceId. How to achive this?
msg.query=`from(bucket: "localnrf")
|> range(start: -2d)
|> filter(fn: (r) => r["_measurement"] == "testdata")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["deviceId"] == "nrf-352656106122685")
|> filter(fn: (r) => r["type"] == "TEMP")` ;
return msg;
Colin
4 March 2022 13:57
2
You can embed the id in the message using javascript template literals. So something like
msg.query=`from(bucket: "localnrf")
|> range(start: -2d)
|> filter(fn: (r) => r["_measurement"] == "testdata")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["deviceId"] == ${msg.deviceId})
|> filter(fn: (r) => r["type"] == "TEMP")` ;
1 Like
Thanks I will try this solution.
This is the correct solution:
msg.query=`from(bucket: "localnrf")
|> range(start: -5m)
|> filter(fn: (r) => r["_measurement"] == "testdata")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["deviceId"] == "${msg.deviceID}")
|> filter(fn: (r) => r["type"] == "TEMP")` ;
Colin
5 March 2022 07:18
5
Is that different to the suggestion I posted? I am on my phone and can't see the difference.
docule quote was missing which causing error${msg.deviceId}) >> "${msg.deviceId})"
system
Closed
19 March 2022 07:41
8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.