Skip to content

Commit cdc4ea2

Browse files
alexjw3alex wangDavid R
authored
feat: add executeQuery page for arduino wizard (#5400)
* feat: add executeQuery page for arduino wizard * fix: add text and dynamic bucket names Co-authored-by: alex wang <alexwang@alexs-MacBook-Pro.local> Co-authored-by: David R <drusnak@influxdata.com>
1 parent 61a181c commit cdc4ea2

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

src/homepageExperience/components/steps/arduino/ExecuteQuery.tsx

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Libraries
22
import React, {useEffect} from 'react'
33

4+
// Components
5+
import CodeSnippet from 'src/shared/components/CodeSnippet'
6+
import {DEFAULT_BUCKET} from 'src/writeData/components/WriteDataDetailsContext'
7+
import {SafeBlankLink} from 'src/utils/SafeBlankLink'
8+
49
// Utils
510
import {event} from 'src/cloud/utils/reporting'
6-
711
import {keyboardCopyTriggered, userSelection} from 'src/utils/crossPlatform'
812

913
const logCopyCodeSnippet = () => {
@@ -16,6 +20,64 @@ type OwnProps = {
1620

1721
export const ExecuteQuery = (props: OwnProps) => {
1822
const {bucket} = props
23+
const bucketName = bucket === DEFAULT_BUCKET ? 'sample-bucket' : bucket
24+
25+
const codeSnippet = `void loop() {
26+
// ... code from Write Data step
27+
28+
// Query will find the RSSI values for last minute for each connected WiFi network with this device
29+
String query = "from(bucket: \"${bucketName}\")\n\
30+
|> range(start: -1m)\n\
31+
|> filter(fn: (r) => r._measurement == \"wifi_status\" and r._field == \"rssi\")";
32+
33+
// Print composed query
34+
Serial.println("Querying for RSSI values written to the \"${bucketName}\" bucket in the last 1 min... ");
35+
Serial.println(query);
36+
37+
// Send query to the server and get result
38+
FluxQueryResult result = client.query(query);
39+
40+
Serial.println("Results : ");
41+
// Iterate over rows.
42+
while (result.next()) {
43+
// Get converted value for flux result column 'SSID'
44+
String ssid = result.getValueByName("SSID").getString();
45+
Serial.print("SSID '");
46+
Serial.print(ssid);
47+
48+
Serial.print("' with RSSI ");
49+
// Get value of column named '_value'
50+
long value = result.getValueByName("_value").getLong();
51+
Serial.print(value);
52+
53+
// Get value for the _time column
54+
FluxDateTime time = result.getValueByName("_time").getDateTime();
55+
56+
String timeStr = time.format("%F %T");
57+
58+
Serial.print(" at ");
59+
Serial.print(timeStr);
60+
61+
Serial.println();
62+
}
63+
64+
// Report any error
65+
if (result.getError() != "") {
66+
Serial.print("Query result error: ");
67+
Serial.println(result.getError());
68+
}
69+
70+
// Close the result
71+
result.close();
72+
73+
Serial.println("==========");
74+
75+
delay(5000);
76+
}`
77+
78+
const fluxExample = `from(bucket: “weather-data”)
79+
|> range(start: -10m)
80+
|> filter(fn: (r) => r._measurement == “temperature”)`
1981

2082
useEffect(() => {
2183
const fireKeyboardCopyEvent = event => {
@@ -30,5 +92,40 @@ export const ExecuteQuery = (props: OwnProps) => {
3092
return () => document.removeEventListener('keydown', fireKeyboardCopyEvent)
3193
}, [])
3294

33-
return <h1>Execute a Flux Query on {bucket}</h1>
95+
return (
96+
<>
97+
<h1>Execute a Flux Query</h1>
98+
<p>
99+
Now let's query the data we wrote into the database. We use the Flux
100+
scripting language to query data.{' '}
101+
<SafeBlankLink
102+
href="https://docs.influxdata.com/influxdb/v2.2/reference/syntax/flux/"
103+
onClick={() =>
104+
event('firstMile.arduinoWizard.documentation.link.clicked')
105+
}
106+
>
107+
Flux
108+
</SafeBlankLink>{' '}
109+
is designed for querying, analyzing, and acting on data.
110+
<br />
111+
<br />
112+
Here's an example of a basic Flux script:
113+
</p>
114+
<CodeSnippet
115+
text={fluxExample}
116+
showCopyControl={false}
117+
language="properties"
118+
></CodeSnippet>
119+
<p className="small-margins">
120+
In this query, we are looking for data points within the last 1 minute
121+
with a measurement of{' '}
122+
<code className="homepage-wizard--code-highlight">"wifi_status"</code>.
123+
</p>
124+
<CodeSnippet
125+
text={codeSnippet}
126+
onCopy={logCopyCodeSnippet}
127+
language="arduino"
128+
/>
129+
</>
130+
)
34131
}

0 commit comments

Comments
 (0)