Connecting an ESP8266
Follow the instructions below to connect your device to the Cloud4RPi control panel.
Your ESP8266 module should have at least 1Mbyte of flash storage to install the full version of MicroPython.
- Flash the latest version of MicroPython using the official manual.
Connect to your Wi-Fi network:
>>> 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
Configure WebREPL for easier file uploading.
>>> import webrepl_setup
Connect to the ESP8266 via WebREPL.
Getting Libraries and Examples
Download the required source code files to your computer:
- simple.py: MQTT Library for MicroPython. Save this file as mqtt.py when downloading.
- cloud4rpi.py: Cloud4RPi client library for MicroPython.
- main.py: Sample code.
Hacking Together some Code
__SSID__with your Wi-Fi network name.
__PWD__with your Wi-Fi network password. If you have an open network, remove the
'__PWD__'element without removing the trailing comma so that the
WIFI_SSID_PASSWORDvariable becomes a tuple with one element.
__YOUR_DEVICE_TOKEN__with the token displayed at the top of the device page on cloud4rpi.io. If you have no token yet, open the Devices page, create a device using the New Device button in the top right corner, and use its token.
Save the file.
The LED & Button Example's Hardware
Connect the LED to GPIO12 and a button to GPIO16. If you need to use other pins, change the corresponding variables in main.py.
- Upload three files (mqtt.py, cloud4rpi.py and main.py) to your ESP8266 via the WebREPL.
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 a new Switch widget and bind it to the
- Add a new Text widget and bind it to the
Buttonvariable. Configure different colors for the "true" and "false" strings.
- Press the hardware button and notice the changes on the control panel.
- Use the LED switch on the control panel to light the hardware LED.