Adding XMPP to our devices

We now have sufficient information to begin using XMPP in our projects. To do this, we create two new projects, which we will call SensorXmpp and ActuatorXmpp, copying the corresponding code from the Sensor and Actuator projects as we have done earlier. As with the previous chapters, we use the same hardware.

For reference, the projects are available on GitHub at https://github.com/PeterWaher/MIoT.

We also add a series of NuGet packages to our projects:

NuGet

Description

Waher.Networking.XMPP.UWP

XMPP client library.

Waher.Networking.XMPP.Sensor.UWP

XMPP IoT sensor data plugin. Added to both projects.

Waher.Networking.XMPP.Chat.UWP

XMPP IoT chat plugin.

Waher.Networking.XMPP.Control.UWP

XMPP IoT control plugin. Only added to the ActuatorXmpp project.

Waher.Networking.XMPP.Provisioning.UWP

Added to both projects. We will discuss this module in a later chapter.

For .NET Standard, .NET Core, second-generation UWP, or traditional .NET Framework projects, you can use the package versions without UWP instead. First-generation UWP apps use different libraries and runtime binaries when it comes to accessing network adaptors. For this reason, they require a somewhat modified version of the original library.

When we initialize our runtime environment, we must make sure to include the assemblies defining relevant classes, at the beginning of the application. We will include the capability of using a rich chat environment using the formatted syntax (based on markdown) and graphs (based on the script engine), so we include these assemblies as well:

Types.Initialize( 
typeof(FilesProvider).GetTypeInfo().Assembly, 
typeof(RuntimeSettings).GetTypeInfo().Assembly, 
typeof(IContentEncoder).GetTypeInfo().Assembly, 
typeof(XmppClient).GetTypeInfo().Assembly, 
typeof(Waher.Content.Markdown.MarkdownDocument). 
GetTypeInfo().Assembly, 
typeof(Waher.Content.Xml.XML).GetTypeInfo().Assembly, 
typeof(Waher.Script.Expression).GetTypeInfo().Assembly, 
typeof(Waher.Script.Graphs.Graph).GetTypeInfo().Assembly, 
typeof(App).GetTypeInfo().Assembly); 
We must not forget to add the internetClientServer capability to our set of capabilities in the Package.appxmanifest files as well:
<Capability Name="internetClientServer" /> 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset