Mobile App Can Now Communicate with IoT Devices via Network
IoT like Rapsberry Pi or Arduino, and Mobile Devices unveiled a lot of innovations, opportunities & new kind of technologies, such as Smart Home, Drones, Remote Robotics and many more. But, how can we make our Mobile App talks to our IoT Devices through a simple network?
Before we start, you may need to learn how to create a mobile app with .NET Standard 2.0 first, so you may refer to our previous post – “Create Cross Platform Mobile App with .NET Standard 2.0“. Secondly, you may also need Visual Studio 2017 with cross platform development component installed, download a free community version if you have yet to own one.
If you are all set, we shall begin!
- Launch your Visual Studio 2017 (VS2017), if you have yet to create an app with .NET Standard, or your existing PCL Xamarin app, you may have to follow this post to create a .NET Standard Cross Platform Mobile App.
- Once you have created Xamarin app, you may now delete the default “Welcome to Xamarin.Forms” label control from MainPage.xaml.
- Then, let’s add in these controls to MainPage.xaml, three (3) entry boxes & one (1) send button.
- Now, let’s create a SendUDP function in MainPage.xaml.cs that’ll eventually read the entered IP, Port Number & Message. Also, performs a send when user clicks the button.
- However, you may notice there are some red underlined errors that can be resolved by adding reference to System.Net & System.Net.Sockets.
- Last, but not least, we need to bind the btnConnect to the function of SendUDP, so when user presses the button, it sends some messages to our IoT Device that is listening to the same port.
- Let’s compile, run and send some messages through network to an App that’s listening to same specified UDP port. Over here, I use some own written UDP Listener app to simulate like a IoT Device.
Is that cool and easy? Let’s us know if this really helps you to explore more opportunities!
This shows you a very conceptual solution, however, UDP doesn’t provide a guarantee delivery of your message.
If a guaranteed delivery is required, you may try to create an app which will replace UDP by using TCP or MQTT, which is a kind of light-weighted TCP protocol.