Here are all topics, which we covered at .NET User Group in Frankfurt at Feb.11th 2016. We talked about (more or less) whole technology stack related to Internet of Things and also Industrie 4.0. We usually think on many cool “things” when it comes to IoT. But in reality IoT is not only cool. To make IoT end to end, we need to be familiar with many hard technologies.
This posts shows a short recap of most important technologies related to IoT. Please note, IoT is not about things only, it is about Internet of Things. In our 3+ hours workshop we played with cool things, but also demonstrated how to use internet to connect things (devices) and services and collect data (really big-data) by doing stream analysis.
These are pillars of IoT:
Arduino with Node.js
We used Arduino board to demonstrate using on Node.js on tiny board with microcontroller (SOM = software on module).
To create a node program I used different editors and finally ended up with Visual Studio 2015 as best solution. It creates you simply everything you need. VS Code, Arduino IDE and Intel XDK IoT Editions are quite and kind of cool, but wen it comes to productive work, VS is just the best way to go. Unfortunately all of IDEs have some issues (including VS). Most painful one is lack of debugging.
Raspberry PI with Windows 10 IoT Core and C#
A more powerful sample is demonstrated in PI2 board. It was written in C# and shows how to connect to Azure EventHub, ServiceBus Queues and IoT Hub.
Following code shows how to receive commands from Service Bus. private async Task readCommand() { try { var cmdMsg = await m_QueueClient.Receive(ReceiveMode.ReceiveAndDelete); if (cmdMsg == null) return; if (cmdMsg.Properties.ContainsKey("Command")) { string cmd = cmdMsg.Properties["Command"] as string; m_GpioStatus.Text = String.Format("Received command '{0}'", cmd); if (m_Pin27 != null && m_Pin22 != null) { if (cmd.ToLower() == "on") { m_Pin27.Write(GpioPinValue.High); m_Pin22.Write(GpioPinValue.High); } else { m_Pin27.Write(GpioPinValue.Low); m_Pin22.Write(GpioPinValue.Low); } } } else m_GpioStatus.Text = "Unknown command received!"; } catch (Exception ex) { } }
| |
We also used Service Bus Java Script SDK to send commands from cloud (EventHub) to PI2. We also demoed how to do this by using Azure IoTHub SDK. Following is JavaScript code, which $("#btnSend").click(function () { var msgBody = { "message": txtMsg.value, "id": 1234 }; var props = [{ 'Name': 'Command', 'Value': txtMsg.value }, ] var msg = new BrokeredMessage(msgBody, props); queueClient.sendMessage(msg, function (messagingResult) { $("#result").html(messagingResult.result); }, "application/json"); });
| |
All Microsoft Band Sensors
We also showed how (ALL) Microsoft Band sensors can be used. Following code snippet shows how to obtain sensor data from band: public async Task Run() { m_Recognizer = new GestureRecognizer(); m_Recognizer.OnGesture += recognizer_OnGesture; m_Recognizer.RegisterRecognizers(new List<IRecognizer>() { new HandDownRecognizer(), new HandUpRecognizer () }); m_BandClient = await m_Connector.GetClient(); m_BandClient.SensorManager.Accelerometer.ReadingChanged += Accelerometer_ReadingChanged; m_BandClient.SensorManager.Accelerometer.ReportingInterval = TimeSpan.FromMilliseconds(128); await m_BandClient.SensorManager. Accelerometer.StartReadingsAsync( new CancellationToken());
}
This code shows wow to send data to Azure Event Hub: public async Task WriteToStream(dynamic sensorEvent) { try { var stringified = JsonConvert.SerializeObject(sensorEvent); var bytes = Encoding.UTF8.GetBytes(stringified); using (MemoryStream stream = new MemoryStream(bytes)) { stream.Flush(); var message = new ServiceBus.OpenSdk.Message(stream); await m_EventHubClient.Send(message); } } catch (Exception ex) { // rootPage.NotifyUserFileNotExist(); } }
| |
Drone
| We also showed a University project, with the goal to implement autonomous flying and flight control by using hand motions and Microsoft Band. Drone control was implemented by native .NET UDP socket stack. |
Azure Stream Analytics
We implemented a code which detects hand movements based on data collected by accelerator sensor and moved that events as Hot-Path events to service bus queue. WITH XMoves AS ( SELECT Count(*) as SAMPLES, DateAdd(second,-2,System.TimeStamp) as WinStartTime, system.TimeStamp as WinEndTime, deviceId, (MAX(x) - MIN(x)) as deltaX, (MAX(y) - MIN(y)) as deltaY, (MAX(z) - MIN(z)) as deltaZ FROM eventstream WHERE sensor = 'Accelerometer' GROUP BY deviceId, TumblingWindow(second, 2) ) Select * INTO acceleratoralertqueue from XMoves WHERE deltaX > 0.25 Select * INTO charts1 from eventstream WHERE sensor = 'Accelerometer' Select * INTO chartHR from eventstream WHERE sensor = 'HeartRate'
| |
Power BI
| Moreover, we also routed all Heart Beats to Power-BI including full motion events. Picture above shows heart-rate and picture below shows real-time motions aggregated by interval of 2 sec. (See ASA script above). Pulse over 150 was probably at time of working with VS Code, Arduino IDE etc. Lower rate might be Visual Studio . |
Azure Data Lake
| And finally we have given an intro in Azure Data Analytics and Azure Data Lake Storage technologies.
|
Thanks to all attendees and hope on your feedback.
Posted
Feb 11 2016, 04:30 PM
by
Damir Dobric