Thank you very much for preparing the sgrebnov article from Akvelon (Ivanovo) , for helping to write this article as the AllJoyn developer and IoT / Windows expert. The rest of our IoT related articles can be found on the iotweek tag.
Hello!
Not so long ago, we
already touched on the topic of IoT or the “Internet of Things” at the last
WinHEC (Hardware Engineering Conference) 2015 conference.
One of the main issues of concern to many is the issue of connectivity and the discovery of devices speaking different languages, protocols, etc. The AllJoyn framework, in conjunction with the
Thread protocol, which Microsoft joined on July 1, is designed to solve this problem. About AllJoyn and go our speech.
')

Separately, we decided to consider one of the very important parts of this concept in the context of Windows 10 (but, of course, not limited to this OS) - the popular protocol for device interaction
AllJoyn , which has already become the de facto standard. Moreover,
Windows 10 and the accompanying
Windows 10 SDK provide special support for this protocol.
What is AllJoyn?
AllJoyn is an open source framework (and protocol) designed to allow applications, devices, and users to communicate over WiFi and Bluetooth (and other types of networks), regardless of the type of device.
The main merit of this protocol is a special level of abstraction, which allows devices and applications to offer themselves as providers of certain services and find other devices and applications without using any additional equipment and special servers.
Architecturally, it looks like this - the AllJoyn network consists of virtual routers (Routers) and applications (Apps). Applications communicate with their router, and routers, in turn, with other routers and other applications related to this router. Thus, applications can communicate with each other through a network of these virtual routers. At the same time, the application and the virtual router to which it is attached can be located on different physical devices.
You can read more about AllJoyn architecture
here (general information) and
here (Windows 10 IoT).

Windows 10 IoT AllJoyn
I hasten to please - in Windows 10, full support for this protocol is included, namely:
Firstly, you do not need to take care of the AllJoyn router described above, since Windows 10 includes a special service AllJoyn Router Service, which can be used both by your applications and other devices on the network.

Second, Windows 10 includes a special API for working with the AllJoyn protocol, which is located in the Windows.Devices.AllJoyn namespace (https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices .alljoyn.aspx) (C ++, C #, JavaScript are supported). Thus, you do not need to install additional SDK and tools, everything is ready and working.
And, of course, additional tools for developers:
- AllJoynCodeGen - part of the Windows 10 SDK (lies in the C: \ Program Files (x86) \ Windows Kits \ 10 \ bin \ x64 \), allows you to generate a fully ready Windows Runtime library for working with the AllJoyn service using the xml service description ( AllJoyn Introspection XML ). See and listen to more .
- getajxml is a special utility that allows you to detect all AllJoyn devices on the network, to obtain detailed information, including generating AllJoyn Introspection XML, which can be used to auto-generate code. More details can be found in the video above.
- AllJoyn Explorer is a similar utility made in the form of a Windows application and allowing not only to see the interface, but also to dynamically invoke methods. Download here .
An example of creating AllJoyn-application on Windows 10
Below we will use
Windows 10 Insider Preview and the free version of Visual Studio 2015 Community Edition (RC) (
download ).
One of the popular examples of AllJoyn is the project of the
Connected Lighting Project , which is nothing more than a light bulb that implements the AllJoyn interface for receiving information and controlling the device.
Below is a look at the process of creating Windows 10-client to control such a smart light bulb.
The full source code of the application can be found on
GitHub . So…
Step 1. Create a new Widows Runtime C ++ component and use
AllJoynCodeGen (see above) to auto-generate code.
The public AllJoyn Introspection XML for this project can be found
here .

Detailed instructions are
here .
Step 2 . Create a new Windows 10 C # / XAML application and add the newly created Windows Runtime component to the dependencies.
Step 3 . Now we can implement the logic of finding and controlling our light bulb.
To find and connect to a light bulb:

To change the brightness:

This is really all the code :) The main AllJoyn classes were provided by the Windows 10 API, the rest were generated using
AllJoynCodeGen .
Step 4. We test:
As a test light bulb, you can use the Lamp Simulator Application (Android,
download ). So, we run our application on the Windows Phone 10 phone and Lamp Simulator on Android, and see how it all works together.

Resources
AllJoyn and Windows10AllJoyn ArchitectureBuilding AllJoyn Apps on Windows 10AllJoyn Interfaces in Windows 10AllJoyn Connected Lighting Project