SlideShare a Scribd company logo
1 of 10
Download to read offline
How Mobile App
Can Communicate
with IoT Devices
via Network
Marvin Heng
Twitter : @hmheng
Blog : http://hmheng.azurewebsites.net
Github: https://github.com/hmheng
Pre-requisite
• Installed Visual Studio 2017 for Windows with Xamarin
Cross-Platform component & all necessary platform-
specific SDK. (Download a FREE Community Version here)
• Create a cross platform mobile app with .NETStandard 2.0
(Learn to how to create one here)
Communicate between App & IoT Devices
1. Launch your Visual Studio 2017 (VS2017), follow this
tutorial to create a .NET Standard Cross Platform Mobile App.
2. Let’s delete the “Welcome to Xamarin.Forms!” label.
3. Add in these lines to MainPage.xaml.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:HmhengXamNet"
x:Class="HmhengXamNet.MainPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Entry x:Name="txtIPAddress" Text="192.168.0.103" />
<Entry x:Name="txtPort" Text="7000" />
<Entry x:Name="txtMessage" Text="Message" />
<Button x:Name="btnConnect" Text=“Send" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Communicate between App & IoT Devices
3
2
4. Now, let’s create a SendUDP function that’ll eventually read
the entered IP, Port Number & Message and perform a send.
public void ConnectUDP(object sender, EventArgs e)
{
UdpClient ucpClient = new UdpClient();
IPAddress ipAddress = IPAddress.Parse(txtIPAddress.Text);
IPEndPoint endPoint = new IPEndPoint(ipAddress,
Int32.Parse(txtPort.Text));
Byte[] data = Encoding.ASCII.GetBytes(txtMessage.Text);
ucpClient.Send(data, data.Length, endPoint);
}
Communicate between App & IoT Devices
4
5. You may notice red underlined errors that can be resolved
by adding reference to System.Net & System.Net.Sockets.
…
using System.Net;
using System.Net.Sockets;
…
Communicate between App & IoT Devices
5
6. Last, but not least, we need to bind the btnConnect to the
function of SendUDP.
public MainPage()
{
InitializeComponent();
btnConnect.Clicked += SendUDP;
}
Communicate between App & IoT Devices
6
7. Let’s compile, run and send some messages through
network to an App that’s listening to same specified UDP port.
Communicate between App & IoT Devices
Congratulation!
You’ve Created Your Very First Xamarin Cross-Platform App with VS2017!
How Mobile App
Can Communicate
with IoT Devices
via Network
Marvin Heng
Twitter : @hmheng
Blog : http://hmheng.azurewebsites.net
Github: https://github.com/hmheng

More Related Content

More from Marvin Heng

More from Marvin Heng (18)

Intelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFrameworkIntelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFramework
 
Using AI to solve business challenges
Using AI to solve business challengesUsing AI to solve business challenges
Using AI to solve business challenges
 
Intelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom VisionIntelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom Vision
 
Azure Cognitive Services for Developers
Azure Cognitive Services for DevelopersAzure Cognitive Services for Developers
Azure Cognitive Services for Developers
 
Bot & AI - A Bot for Productivity
Bot & AI - A Bot for ProductivityBot & AI - A Bot for Productivity
Bot & AI - A Bot for Productivity
 
Artificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I SeeArtificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I See
 
Handwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive ServicesHandwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive Services
 
Create a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your CustomersCreate a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your Customers
 
Facial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET CoreFacial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET Core
 
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKitAI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
 
AI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on AzureAI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on Azure
 
AI: Integrate Search Function into Your App Using Bing Search API.
AI: Integrate Search Function into Your App Using Bing Search API.AI: Integrate Search Function into Your App Using Bing Search API.
AI: Integrate Search Function into Your App Using Bing Search API.
 
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & AzureArtificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
 
AI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedAI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You Typed
 
App Development: Create Cross Platform Mobile App with .NETStandard 2.0
App Development: Create Cross Platform Mobile App with .NETStandard 2.0App Development: Create Cross Platform Mobile App with .NETStandard 2.0
App Development: Create Cross Platform Mobile App with .NETStandard 2.0
 
App Development: Create Cross Platform Mobile App with Just 6 Steps
App Development: Create Cross Platform Mobile App with Just 6 StepsApp Development: Create Cross Platform Mobile App with Just 6 Steps
App Development: Create Cross Platform Mobile App with Just 6 Steps
 
AI: Together We Make World Smarter With LUIS
AI: Together We Make World Smarter With LUISAI: Together We Make World Smarter With LUIS
AI: Together We Make World Smarter With LUIS
 
Cloud: Publish First Web Application to Azure Using Visual Studio
Cloud: Publish First Web Application to Azure Using Visual StudioCloud: Publish First Web Application to Azure Using Visual Studio
Cloud: Publish First Web Application to Azure Using Visual Studio
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

App Development: How Mobile App Can Communicate With IoT Device via Network

  • 1. How Mobile App Can Communicate with IoT Devices via Network Marvin Heng Twitter : @hmheng Blog : http://hmheng.azurewebsites.net Github: https://github.com/hmheng
  • 2. Pre-requisite • Installed Visual Studio 2017 for Windows with Xamarin Cross-Platform component & all necessary platform- specific SDK. (Download a FREE Community Version here) • Create a cross platform mobile app with .NETStandard 2.0 (Learn to how to create one here)
  • 3. Communicate between App & IoT Devices 1. Launch your Visual Studio 2017 (VS2017), follow this tutorial to create a .NET Standard Cross Platform Mobile App.
  • 4. 2. Let’s delete the “Welcome to Xamarin.Forms!” label. 3. Add in these lines to MainPage.xaml. <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:HmhengXamNet" x:Class="HmhengXamNet.MainPage"> <ContentPage.Content> <StackLayout> <Label Text="Welcome to Xamarin.Forms!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" /> <Entry x:Name="txtIPAddress" Text="192.168.0.103" /> <Entry x:Name="txtPort" Text="7000" /> <Entry x:Name="txtMessage" Text="Message" /> <Button x:Name="btnConnect" Text=“Send" /> </StackLayout> </ContentPage.Content> </ContentPage> Communicate between App & IoT Devices 3 2
  • 5. 4. Now, let’s create a SendUDP function that’ll eventually read the entered IP, Port Number & Message and perform a send. public void ConnectUDP(object sender, EventArgs e) { UdpClient ucpClient = new UdpClient(); IPAddress ipAddress = IPAddress.Parse(txtIPAddress.Text); IPEndPoint endPoint = new IPEndPoint(ipAddress, Int32.Parse(txtPort.Text)); Byte[] data = Encoding.ASCII.GetBytes(txtMessage.Text); ucpClient.Send(data, data.Length, endPoint); } Communicate between App & IoT Devices 4
  • 6. 5. You may notice red underlined errors that can be resolved by adding reference to System.Net & System.Net.Sockets. … using System.Net; using System.Net.Sockets; … Communicate between App & IoT Devices 5
  • 7. 6. Last, but not least, we need to bind the btnConnect to the function of SendUDP. public MainPage() { InitializeComponent(); btnConnect.Clicked += SendUDP; } Communicate between App & IoT Devices 6
  • 8. 7. Let’s compile, run and send some messages through network to an App that’s listening to same specified UDP port. Communicate between App & IoT Devices
  • 9. Congratulation! You’ve Created Your Very First Xamarin Cross-Platform App with VS2017!
  • 10. How Mobile App Can Communicate with IoT Devices via Network Marvin Heng Twitter : @hmheng Blog : http://hmheng.azurewebsites.net Github: https://github.com/hmheng