How to control a LED using Onion Omega and IFTTT connected through Internet?

According to IOT(Internet of Things) initiative, I tried LED ON/OFF functionality using the IFTTT(IF THIS THEN THAT) web based service mobile application installed in the iPhone 7 and Android phone of Moto G5 Plus.

Onion Omega 2+ with expansion dock has been used for this demo. Please take a breadboard, 200 Ohms resistor and a LED light with connecting wires in between expansion dock and breadboard.

Pre-requisites;

1. Onion Omega 2+

2. Expansion dock

3. Breadboard

4. LED

5. One 200 ohms resistor

6. Two wires

Onion Omega should be configured as per the below official link;

https://docs.onion.io/omega2-docs/first-time-setup.html

Onion Cloud should be configured as per the below official link;

https://wiki.onion.io/Documentation/Cloud/Steup-Omega-for-the-Onion-Cloud

Steps to follow;

1. Connect the short leg of LED light to Ground in Expansion dock

2. Long leg should be connected to one end of resistor and another end of resistor should be connected to PIN 1 in the Expansion dock.

Please refer the below picture for more understanding;

Onion_1

Ensure the connection is working as expected by running the below command in the SSH terminal of Onion Omega;

root@omega123:~# fast-gpio set 1 1

fast-gpio<space>set<space><gpio pin number><space><value o or 1>

The above command used to set the LED light ON and you can check the below list of commands for ore understanding about the direction and values of LED;

fast-gpio set-input <gpio>

fast-gpio set-output <gpio>

fast-gpio get-direction <gpio>

fast-gpio read <gpio>

fast-gpio set <gpio> <value: 0 or 1>

fast-gpio pwm <gpio> <freq in Hz> <duty cycle percentage>

fast-gpio pulses <gpio> <path_pulses_file> <repeats>

Please note, you need to change the direction as set-output by running the below command before getting into Onion cloud; Once restart or switch-off and switch-on the Onion Omega, by default direction will be changed as input instead of output;

root@omega123:~#fast-gpio set-output 1

Our setup specific to onion Omega and LED connection got over, now we need to consider the Onion cloud to ensure the device can interact with the LED light using internet.

Steps to follow;

1. Go to https://cloud.onion.io/

2. Go to device explorer

3. Select onion

4. Select gpio

5. Enter command as SET

6. Enter params as {“gpio”:”1″,”value”:”1″}

7. Click Send button

You could see LED light is switched ON after click the Send button as stated above and response message as follows;

{

    “success”: true,

    “pin”: “1”,

    “value”: “1”

}

Onion_2

You can change the value as 0 to switch-off the LED. Once you are getting success response in the Onion cloud to control the LED using the GPIO pins, we can move to IFTTT part.

Go to https://ifttt.com and create a free user account to proceed for further move.

Steps to follow;

1. Create a New Applet

2. Select Button widget in the this condition

3. Select Webhooks in the that condition

4. Select Make a web request

5. Go to device explorer –> onion –> gpio as per the 7 different steps provided above

6. Click Generate code button to get the required details for IFTTT

7. Select cURL in the first dropdown

8. Select your pre-configured API Key in the next dropdown

9. Now copy the URL as follows;

https://api.onion.io/v1/devices/12345678-d345c-41154-83a2-7865445678/onion/gpio

10. Now copy the API key and append with the URL as follows;

https://api.onion.io/v1/devices/12345678-d345c-41154-83a2-7865445678/onion/gpio?key=ewfwfwefwegwgwwegwge3eretewewfswetwetgsegdsgetwtwtwtwtwtwe

11. Now copy the above complete values and paste in the Make a web request URL text box

12. Select POST method in the dropdown

13. Select application/json in the next dropdown

14. Copy paste the below values in the Body textbox;

{“command”:”set”,”params”:{“gpio”:”1″,”value”:”1″} }

space should be given in the end braces as I mentioned.

15. Save the applet in IFTTT

16. Go to mobile phone and download the IFTTT app in iPhone or Android phone

17. Create a widget to switch on the light in accordance with the above applet

18. Click the Light ON applet(Make a web request) widget button in the mobile phone

19. LED should be ON

20. Create a another applet to switch-off the LED with the value as 0  {“command”:”set”,”params”:{“gpio”:”1″,”value”:”0″} }

Please refer the below screenshots for better understanding;

Onion_3 Onion_4

Onion_5

onion_6.png

Please check the below demo video for your reference; Due to the network latency, request/response of LED ON or OFF will take sometime;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s