Skip to content

cloud4rpi/cloud4rpi-esp8266-micropython

Repository files navigation

Cloud4RPi Library and Examples for ESP8266 with MicroPython

Build Status

Running the Sample Code

  1. 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
  2. Download the MQTT library and upload it to your ESP8266 with the name mqtt.py using the WebREPL.

  3. Clone this repository or download cloud4rpi.py and the main.py files.

  4. Log into your Cloud4RPi account or create a new one.

  5. Copy your device's Device Token.

  6. Edit the main.py file. Enter your Wi-Fi network data and paste the Device Token into the required variables.

  7. Connect the LED to GPIO12 and a button to GPIO16. If you need to use other pins, change the corresponding variables in main.py.

  8. Transfer the cloud4rpi.py and edited main.py files to your ESP8266.

  9. Reset the ESP8266. You can use the console for this:

    >>> import machine
    >>> machine.reset()
  10. Check that the device goes online and starts sending data.

  11. Go to the Control Panels page and add a new control panel.

  12. Add two Switch widgets and bind them to the LED variable.

  13. 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.

See Also