LED Hello World Tutorial

Blinking LED prototype with wapp

This example to control a LED requires a Raspberry Pi, breadboard, some wires and a LED, and a computer with an Internet connection. The steps here will show you all of the essential features of working with the Seluxit IoT Platform in Wappsto. It should take you about a half an hour to complete.

Here are all the steps you need to cover

Before we start here are all of the parts we will use in this guide

  • 1x Raspberry Pi 3, Model B, 1GB RAM
  • 1x Resistor (220)
  • 1x LED
  • 2x Female-to-Male Dupont Wire
  • 1x Breadboard
LED Hello World parts

1. Create an account in Wappsto

Go to wappsto.com, register and log in.

It's free up to generous usage limits [pricing]

Create Wappsto Account

2. Install and open "Seluxit IoT Creator" wapp

Click the Store in the menu on the left side. In Store, find the "Seluxit IoT Creator" wapp and install it.
Click "Open last installed" button.

Installing IoT Creator

3. Create an IoT model

Here is the IoT Model we will have in this guide and the steps we will go through to create it.
We will describe each step below.

NOTE

Please note that if you create your own names, you will have to change the code examples in this tutorial accordingly, so watch out for that!

Creating IoT Model
3.1 Create a "Network"

You will now create a so-called Network in Wappsto. We are calling ours "Light" in this example.

Creating a Network
3.2 Create a "Device"

Click on the network you have just created, then click the "Add device" to create the device.
We're calling our device "Bulb". Please use caution about naming.
When you create a device, you'll be prompted to fill out a form. Answer the questions meaningfully, as it makes sense to you. But don't sweat the small stuff - this is just a hello world after all. In the image below we have used examples for each field.

Creating a Device
3.3 Create a "Value"

In this case, our "Bulb" device only has one value - "on" or "off" / "1" or "0".
To create a "Value", expand "Bulb" panel and click "Add value".
In this tutorial, we're calling our Value "LED". Please note the caution with naming mentioned in previous steps.
Here it is important that you fill out following form fields correctly to make a working example.

  • Set the "type" to "light".
  • Set "Permission" to "Read/write" so that we can control our Bulb.
  • Set "Data type" to "number".
  • The "Min value" should be set to "0" and "Max value" to "1".
  • The "Step size" should be set to "1".
  • Set the "initial value" to "0".
Create a Value
3.4 Download Python Code

When you've finished modeling your Network > Device > Value, click download and save the zip-file containing the certificates, example values, generics as well as a JSON file. Experienced programmers will recognize here that you could write a program in any given programming language on any device that supports these certificates to connect to the Seluxit IoT Platform.

Download Python code

4. Wire up your Pi and LED

Connect the wires and components as shown below. It is important that you place the LED correctly, as otherwise it will not light up. The "long leg" should be placed at the red wire, in this example connected to pin 11 (GPIO17).

Wire up Pi to LED

5. Upload files

We are using WinSCP to upload the code in this example. Connect to your Pi. Extract the downloaded folder and move it to the Pi as shown.

NOTE:

This description is written for Windows users, if you are using Linux or Mac you can use a terminal to do ssh and scp, instead of using Winscp and Putty.

Upload files

6. Edit python code

Inside the uploaded folder navigate to "exampleValues" folder and modify the python code "bulb_led.py". Here is the example code which you can copy and paste in the "bulb_led.py".

Edit python code

7. Connect to the Pi.

Now we will connect to the Raspberry Pi using PuTTY. After you log in and start the command line type "cd" and the name of your folder to enter it.
Tip: you can start writing the directory name and press "Tab" to autocomplete.
Once you have entered the directory type in the code:

sudo python3 main.py

Now the IOT model/Pi is connected to Wappsto.

Connect Pi

8. Test connection in Wappsto dashboard

Go to the pre-installed wapp, "My Data", and locate the Network that you've just added to Wappsto and the "Bulb" device with the "LED" value. Navigate to value and toggle the on/off switch. Your LED should respond.

Test connection in Wappsto

9. Create a New Wapp

Under the menu point "Installed Apps" find the "Wapp Creator" wapp which will open in a new tab. Click create new and give the wapp a name, e.g. "LED wapp".

Create a Wapp
9.1. Create a file structure for your Wapp

In "Wapp Creator", hover on newly created wapp and click "Edit code". You'll have a blank canvas now. What you need to add is 3 files with the following names and code. After you create files and copy paste the code, press "Save" and you will see the UI loading in the canvas on the right side.

Once you save this code a popup will be prompted asking you to accept the permission to control your LED. This is required because by default wapps are not allowed to retrieve any user data. Accept it and try switching your LED "on" and "off" using the buttons in your wapp. (Blinking part is handled in the next step).

Create file structure for Wapp
9.2. Create and code automated task (blinking)

Create the following files under the "Background" section the same way you did in the "Foreground" and press "Save".

All the background tasks are constantly running in the cloud. To stop it from running, you can uninstall the wapp or remove the code.

Create blinking task

10. Run your new wapp

Once you have Saved your files in the "Background" you can go back to the "Foreground" and press "Reload". Try turning your LED "on","off" or to "blink" or "stop blinking", your LED should respond.
How can flashing a LED still be so satisfying?

This is just the beginning!

Try to make you own modifications, and play around.

Run Wapp
IMPORTANT!

Please make sure you shut down the Raspberry Pi before unplugging the power cable!

11. Shutdown

To shut down the Pi, in PuTTY command prompt stop the program by using the keybord command "Ctr+c" twice.
Then enter the following command:

sudo shutdown -h now

The small green light on your Pi should stop blinking, meaning its safe to unplug.

Shutdown Pi