Skip to content

Control Omega LEDs from WEB

Prerequisites

Code

  • Open the control.py sample file.
  • Replace __YOUR_DEVICE_TOKEN__ with the device token from the from the Device page.
  • Run python control.py. Four new variables should appear on the Device page: Omega LED, RGB LED - Red, RGB LED - Green and RGB LED - Blue.
  • Open the Control Panels page and add a new control panel.
  • Add a Switch widget and bind them to the Omega LED variable.
  • Add Slider widgets and bind them to RGB LED variables with range from 0 to 255.

You can now change the onboard LED state (and RGB LED color if you use the Expansion Dock) with these widgets.

Secure your MQTT connection

Cloud4RPi supports the TLS-enabled MQTTs protocol. If your task requires an encrypted data transfer, follow the steps below:

  1. Install a package that provides the CA certificates for SSL and TLS protocols:

sh opkg update && opkg install ca-certificates

  1. Enable TLS by changing the cloud4rpi.connect() method call as follows:

    python device = cloud4rpi.connect(DEVICE_TOKEN, tls_config={'ca_certs': '/etc/ssl/certs/ca-certificates.crt'})

    The tls_config dictionary holds parameters for the Paho MQTT's tls_set() function.