forked from LordVeovis/xbee-csharp-library
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add XBee IoT Tank Monitoring sample application
Signed-off-by: Ruben Moral <[email protected]>
- Loading branch information
1 parent
dccb921
commit 6d1166e
Showing
79 changed files
with
26,554 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
XBee IoT Tank Monitoring Demo Application | ||
========================================= | ||
|
||
This example is part of the Digi XBee IoT Tank Monitoring demo. It | ||
demonstrates how to use XBee 3 Cellular modules to exchange data, communicate | ||
with Digi Remote Manager and use the BLE interface to talk to mobile apps | ||
applied to the tank monitoring vertical. | ||
|
||
This application is used to make the initial provisioning of the different | ||
smart tanks of the installation (XBee 3 Cellular modules). | ||
|
||
Read the demo documentation for more information: | ||
https://www.digi.com/resources/documentation/digidocs/90002422/. | ||
|
||
Demo requirements | ||
----------------- | ||
|
||
To run this example you need: | ||
|
||
* At least one XBee 3 Cellular module with MicroPython support running the | ||
corresponding MicroPython application of the demo and its corresponding | ||
carrier board (XBIB-C board). | ||
* A smartphone (Android or iOS) with access to the Internet. | ||
* A Digi Remote Manager account. Go to https://myaccount.digi.com/ to create it | ||
if you do not have one. | ||
|
||
Demo setup | ||
---------- | ||
|
||
Make sure the hardware is set up correctly: | ||
|
||
1. The mobile device is powered on. | ||
2. The XBee 3 Cellular modules are properly set up and running their | ||
corresponding MicroPython application. | ||
|
||
Demo run | ||
-------- | ||
|
||
The example is already configured, so all you need to do is to build and launch | ||
the project. | ||
|
||
The first page of the application lists the available smart tank devices near | ||
to you. Before starting the provisioning, make sure you configure your Digi | ||
Remote Manager credentials from the menu. | ||
|
||
To provision a device, tap on it on the list and enter its default Bluetooth | ||
password. If the connection is successful, the Provisioning page appears. Enter | ||
the required information about the device you want to provisioning and tap | ||
**Provision device**. | ||
|
||
|
||
Compatible with | ||
--------------- | ||
|
||
* Android devices | ||
* iOS devices | ||
|
||
License | ||
------- | ||
|
||
Copyright 2021, Digi International Inc. | ||
|
||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
19 changes: 19 additions & 0 deletions
19
examples/xamarin/TankDemo/TankDemo.Android/Assets/AboutAssets.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Any raw assets you want to be deployed with your application can be placed in | ||
this directory (and child directories) and given a Build Action of "AndroidAsset". | ||
|
||
These files will be deployed with your package and will be accessible using Android's | ||
AssetManager, like this: | ||
|
||
public class ReadAsset : Activity | ||
{ | ||
protected override void OnCreate (Bundle bundle) | ||
{ | ||
base.OnCreate (bundle); | ||
|
||
InputStream input = Assets.Open ("my_asset.txt"); | ||
} | ||
} | ||
|
||
Additionally, some Android functions will automatically load asset files: | ||
|
||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); |
164 changes: 164 additions & 0 deletions
164
examples/xamarin/TankDemo/TankDemo.Android/MainActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright 2021, Digi International Inc. | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
using Acr.UserDialogs; | ||
using Android; | ||
using Android.App; | ||
using Android.Content.PM; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Views; | ||
using Android.Widget; | ||
using Rg.Plugins.Popup; | ||
using System.Collections; | ||
using System.Linq; | ||
using Xamarin.Forms; | ||
|
||
namespace TankDemo.Droid | ||
{ | ||
[Activity(Label = "Digi XBee Tank", Icon = "@drawable/digi_icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )] | ||
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | ||
{ | ||
// Constants. | ||
private readonly int REQUEST_BLUETOOTH_ID = 0; | ||
private readonly string[] PERMISSIONS_BLUETOOTH = | ||
{ | ||
Manifest.Permission.AccessCoarseLocation, | ||
Manifest.Permission.AccessFineLocation, | ||
Manifest.Permission.Bluetooth, | ||
Manifest.Permission.BluetoothAdmin | ||
}; | ||
|
||
private readonly string ERROR_BLE_PERMISSIONS = "Bluetooth permissions are required in order to scan and connect to Bluetooth devices."; | ||
|
||
protected override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
TabLayoutResource = Resource.Layout.Tabbar; | ||
ToolbarResource = Resource.Layout.Toolbar; | ||
|
||
base.OnCreate(savedInstanceState); | ||
|
||
Xamarin.Essentials.Platform.Init(this, savedInstanceState); | ||
UserDialogs.Init(this); | ||
Popup.Init(this, savedInstanceState); | ||
|
||
CheckPermissions(); | ||
|
||
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); | ||
Xamarin.FormsMaps.Init(this, savedInstanceState); | ||
LoadApplication(new App()); | ||
} | ||
|
||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) | ||
{ | ||
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
if (requestCode != REQUEST_BLUETOOTH_ID) | ||
return; | ||
|
||
// Check if user declined any Bluetooth permission. | ||
bool anyPermissionDenied = false; | ||
foreach (var result in grantResults) | ||
{ | ||
if (result == Permission.Denied) | ||
{ | ||
anyPermissionDenied = true; | ||
break; | ||
} | ||
} | ||
// Display a message indicating that bluetooth permissions must be enabled. | ||
if (anyPermissionDenied) | ||
Toast.MakeText(this, ERROR_BLE_PERMISSIONS, ToastLength.Long).Show(); | ||
|
||
base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
|
||
public override bool OnOptionsItemSelected(IMenuItem item) | ||
{ | ||
// check if the current item id | ||
// is equals to the back button id | ||
if (item.ItemId == 16908332) | ||
{ | ||
// retrieve the current xamarin forms page instance | ||
Page currentPage = Xamarin.Forms.Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault(); | ||
if (currentPage is CustomContentPage) | ||
{ | ||
// check if the page has subscribed to | ||
// the custom back button event | ||
if (((CustomContentPage)currentPage)?.CustomBackButtonAction != null) | ||
{ | ||
((CustomContentPage)currentPage)?.CustomBackButtonAction.Invoke(); | ||
// and disable the default back button action | ||
return false; | ||
} | ||
} | ||
|
||
// if its not subscribed then go ahead | ||
// with the default back button action | ||
return base.OnOptionsItemSelected(item); | ||
} | ||
else | ||
{ | ||
// since its not the back button | ||
//click, pass the event to the base | ||
return base.OnOptionsItemSelected(item); | ||
} | ||
} | ||
|
||
public override void OnBackPressed() | ||
{ | ||
// retrieve the current xamarin forms page instance | ||
Page currentPage = Xamarin.Forms.Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault(); | ||
if (currentPage is CustomContentPage) | ||
{ | ||
// check if the page has subscribed to | ||
// the custom back button event | ||
if (((CustomContentPage)currentPage)?.CustomBackButtonAction != null) | ||
{ | ||
((CustomContentPage)currentPage)?.CustomBackButtonAction.Invoke(); | ||
} | ||
else | ||
{ | ||
base.OnBackPressed(); | ||
} | ||
} | ||
else | ||
{ | ||
base.OnBackPressed(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Checks if the minimum permissions required to execute the | ||
/// application are granted. If not, requests them. | ||
/// </summary> | ||
private void CheckPermissions() | ||
{ | ||
if ((int)Build.VERSION.SdkInt < 23) | ||
return; | ||
|
||
var permissionsToRequest = new ArrayList(); | ||
foreach (string permission in PERMISSIONS_BLUETOOTH) | ||
{ | ||
if (CheckSelfPermission(permission) != Permission.Granted) | ||
permissionsToRequest.Add(permission); | ||
} | ||
// If the minimum permissions are not granted, request them to the user. | ||
if (permissionsToRequest.Count > 0) | ||
RequestPermissions(permissionsToRequest.ToArray(typeof(string)) as string[], REQUEST_BLUETOOTH_ID); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/xamarin/TankDemo/TankDemo.Android/Properties/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.0.0" package="com.digi.xbee.sample.xamarin.tank" android:installLocation="auto"> | ||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" /> | ||
<application android:label="Digi XBee Tank" android:theme="@style/MainTheme" android:icon="@drawable/digi_icon"> | ||
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyDbQlHHVE1-wZxmfeDw_eA_v3jtTSIjGME" /> | ||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> | ||
<uses-library android:name="org.apache.http.legacy" android:required="false" /> | ||
</application> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-feature android:name="android.hardware.location" android:required="false" /> | ||
<uses-feature android:name="android.hardware.location.gps" android:required="false" /> | ||
<uses-feature android:name="android.hardware.location.network" android:required="false" /> | ||
</manifest> |
Oops, something went wrong.