01.
public
class
DroneEntity : TableEntity
02.
{
03.
DroneEntity()
04.
05.
this
.PartitionKey =
"DJIMavicAir"
;
06.
.RowKey = Guid.NewGuid().ToString();
07.
08.
MeasurementTime = System.DateTime.Now;
09.
VelocityX = 0;
10.
VelocityY = 0;
11.
VelocityZ = 0;
12.
13.
}
14.
System.DateTime MeasurementTime {
get
set
; }
15.
double
VelocityX {
16.
VelocityY {
17.
VelocityZ {
18.
1.
//set the VelocityChanged event
2.
DJISDKManager.Instance.ComponentManager.GetFlightControllerHandler(0, 0).VelocityChanged += OnVelocityChanged;
3.
var typeVelocity = await DJISDKManager.Instance.ComponentManager.GetFlightControllerHandler(0, 0).GetVelocityAsync();
4.
OnVelocityChanged(
, typeVelocity.value);
private
async
void
object
sender, Velocity3D? value)
if
(value !=
null
)
aircraftVelocity3D = value.Value;
velocityX = aircraftVelocity3D.x;
velocityY = aircraftVelocity3D.y;
velocityZ = aircraftVelocity3D.z;
//Must in UI Thread
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
VelocityXTB.Text = velocityX.ToString() +
"m/s"
VelocityYTB.Text = velocityY.ToString() +
VelocityZTB.Text = velocityZ.ToString() +
});
const
string
connectionstring =
"HostName=*****.azure-devices.net;DeviceId=DJIMavicAir;SharedAccessKey=***="
IoTButton_Click(
sender, RoutedEventArgs e)
timerIotHubTransfer = ThreadPoolTimer.CreatePeriodicTimer(dataIoTHubTick, TimeSpan.FromMilliseconds(Convert.ToInt32(5000)));
dataIoTHubTick(ThreadPoolTimer timer)
try
// Create a new customer entity.
DroneEntity ent =
new
DroneEntity();
ent.MeasurementTime = System.DateTime.Now;
ent.VelocityX = velocityX;
ent.VelocityY = velocityY;
ent.VelocityZ = velocityZ;
String JsonData = Serialize(ent);
await SendDataToAzureIoTHub(JsonData);
catch
(Exception ex)
MessageDialog dialog =
MessageDialog(
"Error sending to IoTHub: "
+ ex.Message);
19.
await dialog.ShowAsync();
20.
21.
async Task SendDataToAzureIoTHub(
text)
var msg =
Message(Encoding.UTF8.GetBytes(text));
await deviceClient.SendEventAsync(msg);
(Exception e)
Debug.WriteLine(e.ToString());