|
1 | 1 | // Libraries |
2 | | -import React, {useState} from 'react' |
| 2 | +import React from 'react' |
3 | 3 |
|
4 | 4 | // Components |
5 | | -import {Button, ButtonGroup, ComponentColor} from '@influxdata/clockface' |
| 5 | +import CodeSnippet from 'src/shared/components/CodeSnippet' |
| 6 | +import DataListening from 'src/homepageExperience/components/DataListening' |
| 7 | +import {InfluxColors, Panel} from '@influxdata/clockface' |
6 | 8 |
|
7 | | -// Styles |
8 | | -import './ArduinoSteps.scss' |
| 9 | +// Utils |
| 10 | +import {DEFAULT_BUCKET} from 'src/writeData/components/WriteDataDetailsContext' |
| 11 | +import {event} from 'src/cloud/utils/reporting' |
9 | 12 |
|
10 | | -// Types |
11 | | -type CurrentDataSelection = 'URL' | 'CSV' |
12 | 13 | type OwnProps = { |
13 | 14 | bucket: string |
14 | 15 | } |
15 | 16 |
|
16 | | -export const WriteDataComponent = (props: OwnProps) => { |
| 17 | +export const WriteData = (props: OwnProps) => { |
17 | 18 | const {bucket} = props |
| 19 | + const bucketName = bucket === DEFAULT_BUCKET ? 'sample-bucket' : bucket |
18 | 20 |
|
19 | | - const [currentDataSelection, setCurrentDataSelection] = useState< |
20 | | - CurrentDataSelection |
21 | | - >('URL') |
| 21 | + const codeSnippetOne = `void setup() { |
| 22 | + // ... code in setup() from Initialize Client |
| 23 | + |
| 24 | + // Add tags to the data point |
| 25 | + sensor.addTag("device", DEVICE); |
| 26 | + sensor.addTag("SSID", WiFi.SSID()); |
| 27 | + }` |
| 28 | + |
| 29 | + const codeSnippetTwo = `void loop() { |
| 30 | + // Clear fields for reusing the point. Tags will remain the same as set above. |
| 31 | + sensor.clearFields(); |
| 32 | + |
| 33 | + // Store measured value into point |
| 34 | + // Report RSSI of currently connected network |
| 35 | + sensor.addField("rssi", WiFi.RSSI()); |
| 36 | + |
| 37 | + // Print what are we exactly writing |
| 38 | + Serial.print("Writing: "); |
| 39 | + Serial.println(sensor.toLineProtocol()); |
| 40 | + |
| 41 | + // Check WiFi connection and reconnect if needed |
| 42 | + if (wifiMulti.run() != WL_CONNECTED) { |
| 43 | + Serial.println("Wifi connection lost"); |
| 44 | + } |
| 45 | + |
| 46 | + // Write point |
| 47 | + if (!client.writePoint(sensor)) { |
| 48 | + Serial.print("InfluxDB write failed: "); |
| 49 | + Serial.println(client.getLastErrorMessage()); |
| 50 | + } |
| 51 | + |
| 52 | + Serial.println("Waiting 1 second"); |
| 53 | + delay(1000); |
| 54 | + }` |
| 55 | + |
| 56 | + // Events log handling |
| 57 | + const logCopyCodeSnippet = () => { |
| 58 | + event(`firstMile.arduinoWizard.buckets.code.copied`) // edit |
| 59 | + } |
22 | 60 |
|
23 | 61 | return ( |
24 | 62 | <> |
25 | 63 | <h1>Write Data</h1> |
26 | | - <h2 style={{marginBottom: '8px'}}>Choose your sample data source</h2> |
27 | 64 | <p className="small-margins"> |
28 | | - We recommend choosing an option that most closely matches how you will |
29 | | - write your actual data. |
| 65 | + To start writing data, append the lines of code to add tags to the Point |
| 66 | + at the end of the{' '} |
| 67 | + <code className="homepage-wizard--code-highlight">void setup()</code>{' '} |
| 68 | + function. |
| 69 | + </p> |
| 70 | + <CodeSnippet |
| 71 | + text={codeSnippetOne} |
| 72 | + onCopy={logCopyCodeSnippet} |
| 73 | + language="arduino" |
| 74 | + /> |
| 75 | + <p> |
| 76 | + Add the following{' '} |
| 77 | + <code className="homepage-wizard--code-highlight">loop()</code> code |
| 78 | + snippet to your sketch |
| 79 | + </p> |
| 80 | + <CodeSnippet |
| 81 | + text={codeSnippetTwo} |
| 82 | + onCopy={logCopyCodeSnippet} |
| 83 | + language="arduino" |
| 84 | + /> |
| 85 | + <p> |
| 86 | + In the above code snippet, we retrive the RSSI (Received Signal Strength |
| 87 | + Indicator) of your wifi connection and write it to InfluxDB using the |
| 88 | + client. |
| 89 | + </p> |
| 90 | + <p> |
| 91 | + Once the data is finished writing, you will see a confirmation below. |
| 92 | + </p> |
| 93 | + <Panel backgroundColor={InfluxColors.Grey15}> |
| 94 | + <Panel.Body> |
| 95 | + <DataListening bucket={bucketName} /> |
| 96 | + </Panel.Body> |
| 97 | + </Panel> |
| 98 | + <h2>Review data concepts</h2> |
| 99 | + <p> |
| 100 | + <b>Field (required)</b> <br /> |
| 101 | + Key-value pair for storing time-series data. For example, insect name |
| 102 | + and its count. You can have one field per record (row of data), and many |
| 103 | + fields per bucket. <br /> |
| 104 | + <i>key data type: string</i> <br /> |
| 105 | + <i>value data type: float, integer, string, or boolean</i> |
| 106 | + <br /> |
| 107 | + </p> |
| 108 | + <p> |
| 109 | + <b>Measurement (required)</b> <br /> |
| 110 | + A category for your fields. In our example, it is census. You can have |
| 111 | + one measurement per record (row of data), and many measurements per |
| 112 | + bucket. <br /> |
| 113 | + <i>data type: string</i> <br /> |
| 114 | + </p> |
| 115 | + <p style={{marginBottom: '48px'}}> |
| 116 | + <b>Tag (optional)</b> <br /> |
| 117 | + Key-value pair for field metadata. For example, census location. You can |
| 118 | + have many tags per record (row of data) and per bucket. |
| 119 | + <br /> |
| 120 | + <i>key data type: string</i> <br /> |
| 121 | + <i>value data type: float, integer, string, or boolean</i> |
30 | 122 | </p> |
31 | | - <ButtonGroup className="small-margins"> |
32 | | - <Button |
33 | | - text="URL to File" |
34 | | - color={ |
35 | | - currentDataSelection === 'URL' |
36 | | - ? ComponentColor.Primary |
37 | | - : ComponentColor.Default |
38 | | - } |
39 | | - onClick={() => { |
40 | | - setCurrentDataSelection('URL') |
41 | | - }} |
42 | | - /> |
43 | | - <Button |
44 | | - text="Local CSV" |
45 | | - color={ |
46 | | - currentDataSelection === 'CSV' |
47 | | - ? ComponentColor.Primary |
48 | | - : ComponentColor.Default |
49 | | - } |
50 | | - onClick={() => { |
51 | | - setCurrentDataSelection('CSV') |
52 | | - }} |
53 | | - /> |
54 | | - </ButtonGroup> |
55 | | - {currentDataSelection === 'CSV' && ( |
56 | | - <> |
57 | | - <h2 className="large-margins">Download sample data to {bucket}</h2> |
58 | | - </> |
59 | | - )} |
60 | | - {currentDataSelection === 'URL' && ( |
61 | | - <> |
62 | | - <h2 className="large-margins">Review sample data</h2> |
63 | | - </> |
64 | | - )} |
65 | 123 | </> |
66 | 124 | ) |
67 | 125 | } |
68 | | - |
69 | | -export const WriteData = props => { |
70 | | - return <WriteDataComponent bucket={props.bucket} /> |
71 | | -} |
|
0 commit comments