Before we start uploading data to the cloud, we need a way to store the connection secrets (WiFi password, Adafruit IO key) to the device... without hardcoding it into our source code. This is done with settings files (.env) in DeviceScript.
.env files
Click on the configure icon (wand) and select Add Settings to add two files to the project:
-
.env.default
, contains publich settings such as your Adafruit username. This file can be added to your source control system. -
.env.local
, contains your secrets. This file should NOT be added to your source control system
# env.defaults # public settings, commit to source control WIFI_SSID=your-wifi-ssid IO_USERNAME=your_adafruit_io_user IO_FEED=your_adafruit_io_feed
# env.local # secrets, don't commit to source control IO_KEY=your_secret_key WIFI_PWD=your_wifi_password
import { readSetting } from "@devicescript/settings" const key = await readSetting("IO_KEY") const user = await readSetting("IO_USERNAME") const feed = await readSetting("IO_FEED")
Text editor powered by tinymce.