Now that you've learned a few basics about network functions, here are a few application examples.
In this example, a website is displayed in the browser using station mode. There are two toggle options on this web page to turn LEDs on or off.
The example is kept very simple (without further checks). Once you have understood it, you can expand it at any time.
- mandatory 2x LEDs (any color)
- mandatory 2x resistors (min. 220 ohms)
- mandatory internet connection
- few cables
- optional a breadboard
# create script
$ touch ~/Projects/ESP/examples/network/led_controller_webserver.py
# create html
$ touch ~/Projects/ESP/examples/network/index.html
Source Code for
led_controller_webserver.py
Source Code for html
index.html
Source Code for
boot.py
Adjust the constants (boot.py
and led_controller_webserver.py
) according to your needs and check the circuit. Connect the microcontroller and transfer the files.
# copy script as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/network/led_controller_webserver.py /pyboard/main.py
# copy html
(venv) $ rshell -p [SERIAL-PORT] cp examples/network/index.html /pyboard/
# copy boot.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/network/boot.py /pyboard/
# start repl on microcontroller
(venv) $ rshell -p [SERIAL-PORT] repl
To start press reset
key or start with keys Control
+ d
. To interrupt press keys Control
+ c
. To finish the rshell
- repl
session, press keys Control
+ x
.
If you don't know the IP, use for example
$ arp -a
(inside local terminal) and then enter 'http://[IP OF MICROCONTROLLER]' in the browser.
With an Adafruit account, you can also use Adafruit IO (for free)! This gives you the opportunity, for example, to create IoT dashboards and actions that display your measured values or to control devices. Here is an example to control the color of your NeoPixel (from computer or mobile).
- mandatory Adafruit IO Account (free Adafruit IO Basic plan)
- mandatory 1x NeoPixel (Strip or Ring or Matrix)
- few cables
- optional a breadboard
If you don't have an Adafruit account yet, sign up and log in to adafruit.io.
The free
Adafruit IO Basic Plan
is enough for this tutorial. There is no need to add anyDevice
,Action
orPower-Up
to createFeeds
andDashboards
!
Steps
- create a new feed (incl. name) and note down feed key
- create a new dashboard (incl. name)
- via
Dashboard Settings
>Edit Layout
>Create New Block
addColor Picker
- choose the feed for
Color Picker
and pressNext step
- select a
Test value
and pressCreate block
- save all your settings
Dashboard Settings
>Edit Layout
>Save Layout
- note down
IO_USERNAME
andIO_KEY
NeoPixel | ESP32 |
---|---|
GND | GND |
DIN | 23 |
5V | 5V5 |
# create script
$ touch ~/Projects/ESP/examples/network/adafruit_io_neopixel.py
Source Code for
adafruit_io_neopixel.py
Source Code for
boot.py
Adjust the constants (boot.py
and adafruit_io_neopixel.py
) according to your needs and check the circuit. Connect the microcontroller and transfer the files.
# copy script as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/network/adafruit_io_neopixel.py /pyboard/main.py
# copy boot.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/network/boot.py /pyboard/
# start repl on microcontroller
(venv) $ rshell -p [SERIAL-PORT] repl
To start press reset
key or start with keys Control
+ d
. To interrupt press keys Control
+ c
. To finish the rshell
- repl
session, press keys Control
+ x
.