Share via


Connecting DJI Drones with Azure Table Storage

1. Introduction

In this tutorial, we will show how to connect DJI drones with Azure Table Storage. The full project information can be found here: https://www.hackster.io/JiongShi/azure-cloud-services-for-dji-drones-d8d3a3. You can download the sample project from my Github page: https://github.com/shijiong/AzureCloudService4DJI. We use DJI Mavic Air as an example to demonstrate this demo.

2. Create a Basic UWP Application

Please refer to this tutorial to create a UWP application: Connecting DJI Drones with Azure IoT Hub. We can connect the UWP application with DJI drone by Windows SDK and get the real-time on-board sensor data, i.e., 3-axes velocities. In the rest of this article, we will demonstrate how to upload sensor data to Azure Table Storage. 

3. Import Azure Storage Namespaces

Import namespaces required for Azure Storage in the MainPage.xaml.cs file as follows.

1.using Microsoft.WindowsAzure.Storage;
2.using Microsoft.WindowsAzure.Storage.Auth;
3.using Microsoft.WindowsAzure.Storage.Table;

4. Upload Sensor Data to the Azure Storage Table

Since we now get the real-time 3-axis velocities of the aircraft, we can upload the data to Azure IoT Hub. Firstly, we will add a Button, by which the user can start the uploading process. In the Click event of the button, we will implement a ThreadPoolTimer to upload the data every 5 seconds as follows.

01.private void  AzureStorageButton_Click(object sender, RoutedEventArgs e)
02.{
03.            timerDataTransfer = ThreadPoolTimer.CreatePeriodicTimer(dataTransmitterTick, TimeSpan.FromMilliseconds(Convert.ToInt32(5000)));
04.        }
05. 
06.And furthermore, the timer elapsed handler, dataTransmitterTick, is defined as
07.        private async void dataTransmitterTick(ThreadPoolTimer timer)
08.        {
09.            try
10.            {
11.                CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=*******;AccountKey=*****=");
12. 
13.                // Create the table client.
14.                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
15. 
16.                // Create the CloudTable object that represents the " AccelerometerTable " table.
17.                CloudTable table = tableClient.GetTableReference("DJITable");
18.                await table.CreateIfNotExistsAsync();
19. 
20.                // Create a new customer entity.
21.                DroneEntity ent = new  DroneEntity();
22.                ent.MeasurementTime = System.DateTime.Now;
23.                ent.VelocityX = velocityX;
24.                ent.VelocityY = velocityY;
25.                ent.VelocityZ = velocityZ;
26. 
27.                // Create the TableOperation that inserts the customer entity.
28.                TableOperation insertOperation = TableOperation.Insert(ent);
29.                // Execute the insert operation.
30.                await table.ExecuteAsync(insertOperation);
31.            }
32.            catch (Exception ex)
33.            {
34.                MessageDialog dialog = new  MessageDialog("Error sending to Azure: "  + ex.Message);
35.                await dialog.ShowAsync();
36.            }
37.}

Remember to replace the Cloud Storage Account on line 11 with your own that you create in Step 2.

Now, once the app runs, you will see the 3-axes velocities on the screen as shown in Fig. 1. 

Fig. 1 Real time 3-axes Velocities

After clicking the “Upload to Azure Storage” button, the data will be transmitted to Azure Storage Table every 5 seconds. The table can be reviewed by Microsoft Azure Storage Explorer as follows.

Fig. 2 Azure Storage Table

Summary

In this tutorial, we showed the steps to connect your drones with Azure Storage Table. You can obtain the on-board sensor data and upload to Azure Storage Table periodically. 

Resources

1. Azure Cloud Services for DJI Drones: https://www.hackster.io/JiongShi/azure-cloud-services-for-dji-drones-d8d3a3
2. Source Code: https://github.com/shijiong/AzureCloudService4DJI
3. DJI Windows SDK: https://developer.dji.com/windows-sdk/ 

See Also

1. Connecting DJI Drones with Azure IoT Hub: https://social.technet.microsoft.com/wiki/contents/articles/54262.connecting-dji-drones-with-azure-iot-hub.aspx 

2. Connecting DJI Drones with Azure Cognitive Services: https://social.technet.microsoft.com/wiki/contents/articles/54265.connecting-dji-drones-with-azure-cognitive-services.aspx