Skip to content

Control Omega LED from WEB

Prerequisites

Code

  • Open the control.py sample file.
  • Replace __YOUR_DEVICE_TOKEN__ with the device token from the Device page.
  • Run python led.py. A new Omega LED variable should appear on the Device page.
  • Open the Control Panels page and add a new control panel.
  • Add a new Switch widget and choose the newly added Omega LED variable.

You can now switch the onboard LED state using this widget.

Control Expansion Board RGB LED from WEB

Prerequisites

  • Configured and connected Omega2 board.
  • Expansion Board

Code

  • Open the led.py sample file.
  • Replace __YOUR_DEVICE_TOKEN__ with the device token from the from the Device page.
  • Run python control.py. Three new variables should appear on the Device page: 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 for each variable.

You can now change the RGB LED color using 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.