Merge pull request #5471 from influxdata/fix-iot-starter-tutorial
Fix IoT Starter tutorialspull/5451/head^2
commit
c3064aa4fc
|
@ -19,8 +19,8 @@ influxdb/v2/tags: [api, javascript, nodejs]
|
|||
|
||||
- [Contents](#contents)
|
||||
- [Set up InfluxDB](#set-up-influxdb)
|
||||
- [Authenticate with an InfluxDB API token](#authenticate-with-an-influxdb-api-token)
|
||||
- [Introducing IoT Starter](#introducing-iot-starter)
|
||||
- [Install Yarn](#install-yarn)
|
||||
- [Create the application](#create-the-application)
|
||||
- [Install InfluxDB client library](#install-influxdb-client-library)
|
||||
- [Configure the client library](#configure-the-client-library)
|
||||
|
@ -37,18 +37,20 @@ influxdb/v2/tags: [api, javascript, nodejs]
|
|||
|
||||
If you haven't already, [create an InfluxDB Cloud account](https://www.influxdata.com/products/influxdb-cloud/) or [install InfluxDB OSS](https://www.influxdata.com/products/influxdb/).
|
||||
|
||||
### Authenticate with an InfluxDB API token
|
||||
The IoT Starter example app assumes the following prerequisites:
|
||||
|
||||
For convenience in development,
|
||||
[create an _All Access_ token](/influxdb/v2/admin/tokens/create-token/)
|
||||
for your application. This grants your application full read and write
|
||||
permissions on all resources within your InfluxDB organization.
|
||||
- An InfluxDB [org ID](/influxdb/v2/admin/organizations/view-orgs/)
|
||||
- An [API token](/influxdb/v2/admin/tokens/create-token/) (for example, an **All Access token**) that has read and write permissions for the buckets
|
||||
- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center` for storing time series data from devices
|
||||
- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center_devices` for storing device metadata and API token IDs
|
||||
|
||||
{{% note %}}
|
||||
|
||||
#### Use restricted tokens for production apps
|
||||
|
||||
For a production application, create and use a
|
||||
{{% cloud-only %}}custom{{% /cloud-only %}}{{% oss-only %}}read-write{{% /oss-only %}}
|
||||
token with minimal permissions and only use it with your application.
|
||||
token with minimal permissions and only use it with a single client or application.
|
||||
|
||||
{{% /note %}}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ influxdb/v2/tags: [api, python]
|
|||
|
||||
- [Contents](#contents)
|
||||
- [Set up InfluxDB](#set-up-influxdb)
|
||||
- [Authenticate with an InfluxDB API token](#authenticate-with-an-influxdb-api-token)
|
||||
- [Introducing IoT Starter](#introducing-iot-starter)
|
||||
- [Create the application](#create-the-application)
|
||||
- [Install InfluxDB client library](#install-influxdb-client-library)
|
||||
|
@ -41,20 +40,12 @@ influxdb/v2/tags: [api, python]
|
|||
|
||||
If you haven't already, [create an InfluxDB Cloud account](https://www.influxdata.com/products/influxdb-cloud/) or [install InfluxDB OSS](https://www.influxdata.com/products/influxdb/).
|
||||
|
||||
### Authenticate with an InfluxDB API token
|
||||
The IoT Starter example app assumes the following prerequisites:
|
||||
|
||||
For convenience in development,
|
||||
[create an _All Access_ token](/influxdb/v2/admin/tokens/create-token/)
|
||||
for your application. This grants your application full read and write
|
||||
permissions on all resources within your InfluxDB organization.
|
||||
|
||||
{{% note %}}
|
||||
|
||||
For a production application, create and use a
|
||||
{{% cloud-only %}}custom{{% /cloud-only %}}{{% oss-only %}}read-write{{% /oss-only %}}
|
||||
token with minimal permissions and only use it with your application.
|
||||
|
||||
{{% /note %}}
|
||||
- An InfluxDB [org ID](/influxdb/v2/admin/organizations/view-orgs/)
|
||||
- An [API token](/influxdb/v2/admin/tokens/create-token/) (for example, an **All Access token**) that has read and write permissions for the buckets
|
||||
- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center` for storing time series data from devices
|
||||
- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center_devices` for storing device metadata and API token IDs
|
||||
|
||||
## Introducing IoT Starter
|
||||
|
||||
|
@ -356,8 +347,6 @@ Add the `/api/devices` API endpoint that retrieves, processes, and lists registe
|
|||
|
||||
In `./api/devices.py`, add the following:
|
||||
|
||||
{{% truncate %}}
|
||||
|
||||
```python
|
||||
def get_device(device_id=None) -> {}:
|
||||
influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'),
|
||||
|
@ -390,14 +379,12 @@ Add the `/api/devices` API endpoint that retrieves, processes, and lists registe
|
|||
return result
|
||||
```
|
||||
|
||||
{{% /truncate %}}
|
||||
{{% caption %}}[iot-api-python/api/devices.py get_device()](https://github.com/influxdata/iot-api-python/blob/9bf44a659424a27eb937d545dc0455754354aef5/api/devices.py#L30){{% /caption %}}
|
||||
|
||||
{{% caption %}}[iot-api-python/api/devices.py get_device()](https://github.com/influxdata/iot-api-python/blob/9bf44a659424a27eb937d545dc0455754354aef5/api/devices.py#L30){{% /caption %}}
|
||||
The `get_device(device_id)` function does the following:
|
||||
|
||||
The `get_device(device_id)` function does the following:
|
||||
|
||||
1. Instantiates a `QueryApi` client and sends the Flux query to InfluxDB.
|
||||
2. Iterates over the `FluxTable` in the response and returns a list of tuples.
|
||||
1. Instantiates a `QueryApi` client and sends the Flux query to InfluxDB.
|
||||
2. Iterates over the `FluxTable` in the response and returns a list of tuples.
|
||||
|
||||
## Create IoT virtual device
|
||||
|
||||
|
|
Loading…
Reference in New Issue