D.I.Y: Making Universal Windows 10 IoT Application for AllJoyn Enabled Devices

0
1042

AllJoyn enabled devices describe their capabilities via service interfaces on a network they are connected to. Developers can use these interfaces to make applications on any platform. For example, LIFX which makes WiFi enabled smart lights, uses AllJoyn in its Windows 10 IoT app to control its Smart Lights. On Windows 10 IoT platform these interfaces can be easily used using AllJoyn Studio which is a Visual Studio extension.

Getting Things Ready

Before beginning this project make sure you have completed our last tutorial : Make Your Own AllJoyn Enabled Switches on Windows 10 IoT Core. Now that you have completed that part, go the your Raspberry Pi’s web interface and make AllJoynDSBHeadedAdapterApp, the default app.

Set AllJoynDSBHeadedAdapter as the default app.
Set AllJoynDSBHeadedAdapter as the default app.

Now open Visual Studio and install AllJoyn Studio extension from Tools → Extension and Updates.

Install AllJoyn Studio extension to Visual Studio
Install AllJoyn Studio extension to Visual Studio

After the AllJoyn studio is installed create a new Project from the File menu. Select Visual C# → Windows → Universal from the Templates menu. From the list of Templates select AllJoyn App.

AllJoyn App Template
Create a new project using AllJoyn app template

After the project is created you will be asked to add interfaces to this project. You can also do this later by selecting AllJoyn → Add/Remove Interfaces from the menu bar. We will be looking for interfaces on our network so make sure your Raspberry Pi is connected to the same network to which your laptop/PC is connected, via WiFi or LAN. You can also connect your Pi directly to your laptop’s Ethernet port.

Now select all the interfaces that are published by your Device.

Include interfaces provided by your device.
Include interfaces provided by your device.

The Design Part of the App

Open MainPage.xaml in design view from the Solution Explorer window.

Design view for MainPage.xaml
Design view for MainPage.xaml

Use the zoom control to increase size of the design view. Now, open toolbox from the controls on left hand side. If you don’t have it there you can find it under View menu in the menu bar. Since we have to control 4 relays, we will need 4 toggle switch control. So we will drag and drop 4 Text Block and Toggle Switch controls from the toolbox to the design view.

Drag and drop controls from toolbox
Drag and drop controls from toolbox

Arrange the controls as shown in the image above. Then rename the controls as textBlock1, textBlock2, textBlock3, textBlock4, and similarly for Toggle Switch toggleSwitch1, toggleSwitch2, toggleSwitch3, toggleSwitch4. This can be done by selecting a control and then using the Properties pane under the Solution Explorer or by editing the xaml markup beneath the design view.

Change the Name property for the controls.
Change the Name property for the controls.

Now, we’ll generate event handler functions for each of those toggle switches by double clicking on each of them. This auto-generates a event handler function with the name <Toggle Switch Name>_Toggled().

Code

Coming to the coding part now, open MainPage.xaml in code view and edit the code as shown in the snippet below:

After updating the code for MainPage.xaml.cs, deploy the app on the local machine and your app is ready to control the AllJoyn Enabled Four Channel Relay Module. Since this is a Universal Windows Platform app, it can also be deployed on to Windows 10 phones(Right now only available for Windows Insider program) and Surface tablets.

Final app
Final application

After completing all this, I hacked an old extension board and connected my device to it. So it worked as a complete AllJoyn enabled socket.

Completing the hardware part.
Completing the hardware part.

Github Repo

Find the project on Github: https://github.com/rhtnryn/AllJoyn-Enabled-Switch

LEAVE A REPLY

Please enter your comment!
Please enter your name here