Cloud4RPi Library and Examples for ESP8266 with MicroPython
-
Connect your MicroPython-enabled ESP8266 to a Wi-Fi network and configure it for the WebREPL. You can do it by accesing 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 isn't valid, wait and re-execute
-
Download the MQTT library and put it to your ESP8266 with the name
mqtt.py
using the WebREPL. -
Clone this repository or download cloud4rpi.py and main.py files.
-
Copy your device's Device Token.
-
Edit the main.py file. Put your Wi-Fi network data and the Device Token to the required variables.
-
Connect the LED to GPIO12 and a button to GPIO16. If you need to use another pins, change the required variables in main.py.
-
Transfer the cloud4rpi.py file and edited main.py file to your ESP8266.
-
Reset the ESP8266 physically of using the console:
>>> import machine >>> machine.reset()
-
Notice that the device went online and started 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 "true" and "false" strings.
You can use this control panel to see when the button was pressed and control the LED.