Cloud4RPi Library and Examples for ESP8266 with MicroPython
-
Connect your MicroPython-enabled ESP8266 to a Wi-Fi network and configure it for WebREPL. You can do it by accessing the console via the serial port and executing the following commands:
>>> from network import WLAN >>> STA = WLAN(0); STA.active(1) >>> STA.connect('__SSID__', '__PASSWORD__') >>> STA.ifconfig() # Outputs the network configuration. If it is not valid, wait and re-execute
-
Download the MQTT library and upload it to your ESP8266 with the name
mqtt.py
using the WebREPL. -
Clone this repository or download cloud4rpi.py and the main.py files.
-
Copy your device's Device Token.
-
Edit the main.py file. Enter your Wi-Fi network data and paste the Device Token into the required variables.
-
Connect the LED to GPIO12 and a button to GPIO16. If you need to use other pins, change the corresponding variables in main.py.
-
Transfer the cloud4rpi.py and edited main.py files to your ESP8266.
-
Reset the ESP8266. You can use the console for this:
>>> import machine >>> machine.reset()
-
Check that the device goes online and starts sending data.
-
Go to the Control Panels page and add a new control panel.
-
Add two Switch widgets and bind them to the
LED
variable. -
Add a new Text widget and bind it to the
Button
variable. Configure different colors for the "true" and "false" strings.
You can use this control panel to control the LED and see when the button is pressed.