TA Stuff 2021
Pycom
ESP32
It's time to start sending your sensor data to the cloud. And the easiest place to get started doing that is probably Pybytes.
This is done in 2 steps, first you'll get the device connected to Pybytes over Wi-Fi and then you'll get to send data and organise the Dashboard.
At the Pycom website there is a helpful tutorial with pictures to follow, and you can find it here: https://docs.pycom.io/pybytes/gettingstarted/
If something is unclear, take a look below where some parts are explained further.
First of all you'll need an account at Pybytes.
Before setting up your device with Pybytes it is an good idea to configure your network (see picture below) and enter your Wi-Fi's SSID (the name of your Wi-Fi) and credentials (and save!).
Then, in your device menu, press Configuration then Networks, and select your added Wi-Fi network before doing the Firmware update.
For step 2.5 the layout have changed a bit. If you're connecting using the Firmware updater you will find the token asked for in step 3 here under offline Firmware updater:
Firmware updater can be found here. Remember to select "Force update pybytes registration" in the updater before continuing.
Remember to close any VSCode or Atom before running the firmware updater.
If for some reason you cannot connect to your Wi-Fi after running the updater and starting your IDE again, the easiest way to check your SSID and password is by pressing "download" in your IDE and accept all new files. Then a new file pybytes_config.json
will appear (if you've done the Pybytes firmware update). There you can check the SSID and password you entered in Pybytes. Update your SSID/password if needed, save and upload the project again.
Tip: right-click in that config file then press "format document" (in VSCode, in Atom you need to install a package such as atom-beautify) to format it to something easier to read.
Now it is time for sending some data to Pybytes and organising the Dashboard. Again, there is a good tutorial on this provided by Pycom and you may find it here: https://docs.pycom.io/pybytes/dashboard/
When you want to send a signal to pybytes you can use the function pybytes.send_signal(signal_number, value)
. The signal_number
defines which "channel" you will use for sending your message. The value
represents what you want to send, this is your message. It can be a number, but also a string of text.
For example you can run this in main.py
:
If you use Pybytes, this is done via the provisioning alone when you do your pybytes firmware update and enter you Activation token (after you've entered your Wi-Fi credentials on pybytes). No need to do this below if you're only using Pybytes.
On your Pycom device there is a built-in antenna for connecting to Wi-Fi. When connecting to online platforms, other than Pybytes, or if you want to connect manually to your Wi-Fi you may use the code below. Note, this code will only try connecting to the Wi-Fi specified by ssid
. Don't forget to change ssid
and password
to the corresponding for your Wi-Fi.
In boot.py
:
wlan.connect(ssid='ssid', auth=(WLAN.WPA2, 'password'), timeout='time_in_ms')
, after the time has run out the device will stop trying to connect to your network.WLAN
class can be found here.When sharing or showing code you've written, then you may not want to expose your private keys and, later, tokens. As we encourage you to help each other and share your knowledge, we can work around this problem by storing this information in another file.
Create a new file in your project and call it keys.py
, here you can store your keys and tokens.
Then your code in boot.py
becomes somehing like this instead.
Credit
Written by Linnea Allander, Erik Karlsson