Raspberry Pi. Create your first Connected Light

Create your first connected light using Raspberry Pi. Control and monitor a connected light from mobile, tablet and desktop using Lelylan & MQTT. It takes 15 minutes | $36 (eth) or $44 (WiFi) in hardware | basic level.Raspberry Pi Create your first Connected Light

Step 1: Hardware

For this tutorial you need a Raspberry Pi connected to the Internet, either via ethernet (Model B) or via WiFi using a compatible WiFi USB dongle. To configure the network access on your Raspberry Pi have a look at this tutorial. To complete this tutorial you need the following components.

Step 2: Software

To program your Raspberry Pi you need to install a compatible GNU/Linux distribution from the Raw Images list section (if new to this checkout this guide) and the following libraries.

python-mosquitto. This library enables the communication between Lelylan and the Rasp by creating a MQTT client in Python.$ sudo apt-get install python-mosquitto

Step 3: Hardware Setup

Hardware Setup

This schema represents the led, resistor and pushbutton setup. With this setup each time you press the button, the LED is turned on and off.

Step 4: Software Setup

Software Setup

Open Lelylan Dashboard and create a new device by following 3 simple steps (if you are new to Lelylan, you can sign up for free).

1) Set a meaningful name (e.g. bedroom light).

2) Choose the device type. For this tutorial choose Basic Light. What is a type? A type defines what a device is by defining its properties, functions and statuses. For this tutorial you do not need to now more about.

3) Choose “Connect with MQTT” as connectivity option. In this tutorial we'll use MQTT, a publish subscribe protocol for the Internet of Things.

4) Get the Device ID and Device Secret. Once the device is created, click the settings link (placed under the device name) and get the device ID and device secret. You'll need them in the next section.

Step 5: Code

Once the (virtual) device is defined on Lelylan you need to make it communicate with the Raspberry Pi. Copy the Python sketch below and change , and with your device credentials. Save the sketch in a file named lelylan_light.pyand run it as super user: $ sudo python lelylan_light.py.

See code in Github

Step 6: You Are Done

Access Lelylan Dashboard and control your connected light from mobile, tablet and desktop. If any problem occours, let @lelylan know.

Step 7: Learn More

If you want to better understand how the code works checkout the code explenation code explenation section.


Source: Raspberry Pi. Create your first Connected Light

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top