(MS Dynamics) NAV Of Things

For many ERP systems, the important part of digital transformation will be integrating with IoT, connecting enterprise system and business solutions with devices and sensors in the field. I will not focus on benefits of this, I will just list a few obvious applications – IoT based real-time production, smart offices and warehouses, smart cities,… is all possible using IoT and existing AI capabilities. For real production systems, you would use one of many excellent end-to-end IoT solutions, that come with both sensors, hubs and APIs, like for example these guys, or to simplify your integration further, these guys . The latter ones have a number of cool videos showing different applications of IoT and one of them was inspiration for this blog.

For educational, creative and experimental purposes, or if you just like to tinker with such, a DIY kit for sensors will suffice. This post will show one of those examples. If you can’t be bothered to read through the whole process, just scroll down to the end, and watch the 30 sec. video of the end result.

Let me start with the outline of the data flow here:


You can read all about this here, but in short: my sensor will (continuously) send the data to my Raspberry Pi, where my .Net project is running, capturing data and sending them on to my Azure Event Hub. On NAV side, I have a service checking for service bus messages, that reads any such message and takes appropriate action in NAV. In the real world, most of you would be starting somewhere around Event Hub and look only at NAV side of it. But it is actually quite fun to go through the whole process.

Then let’s move on to the fun part –  the tinkering :). DIY kits with different sensors and for different platforms are these days available in many variants.  I am actually combining two kits here (Microsoft IoT for Raspberry Pi and Grove Seeed for Pi) here, though a single kit for the same purpose can be purchased. The Raspberry Pi is a low-cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. Windows Iot Core is next installed on this (the Pi comes pre-installed with NOOBs, and adding Windows IoT is a simple and quick procedure). You don’t have to use Windows Iot of course, but as I will be sending all this to my hub in Azure, before pulling it down to NAV – that is the most logical option.

Grove Pi cape is placed on top of Raspberry Pi, and works as the bridge between the plug-and-play grove sensors and the Pi. Like this:


Grove sensors are simple to use, you only need to plug them into the ports, and that is the reason for adding the Grove hat, as without it you would need to go a further level down towards the basics and assemble your sensor. Like this:



At this point, many might have flashbacks to school projects and cringe, but it is actually rather fun, something that seems expected too, as while installing the Win IoT on the Pi, Microsoft will greet you with the following message::

Make your board blink, no setup is required, just press Start. Feel free to gather all of your friends and have a dance party around your device. Disclaimer: Microsoft takes no responsibility for whatever damage may be caused by hosting such a huge rave of a party by using the small blinking LED on your board. 

?!! By now I have to admit that it was fun indeed. Right so, with Windows IoT core installed, Grove hat mounted on Pi, sensor plugged in – I need a way to read the sensor data and send them further. For this, a number of already done template projects, for all kinds of sensors, boards and OS already exists. I used the projects provided by seeed, on GitHub. These projects capture sensor data and show them on the screen connected to Pi. But here you can easily modify them to send data on to Event Hub. I have my IoT devices registered in the portal, but for real projects, also device provisioning service would be considered. Messages from my device are routed to Event Hub (that I have created in the portal, with default Consumer Group). In the Event Hub, I have 2 shared access policies, one for sending and one for receiving. The sending one is used to create SAS (shared access token) that is used to connect from the Pi. And then connecting and sending data from my .net project to Azure, can be as simple as this:

var httpClient = new HttpClient();
httpClient.BaseAddress =
new Uri(String.Format(“https://{0}.servicebus.windows.net/”, serviceNamespace));
httpClient.DefaultRequestHeaders.TryAddWithoutValidation(“Authorization”, sas);

var postResult = httpClient.PostAsJsonAsync(String.Format(“{0}/publishers/{1}/messages”, hubName, deviceName), mytext).Result;

where mytext is the data sent by sensor.

When running, the project is deployed and runs on the Pi, sending my data to Azure. Now, on the NAV side of it – I have a service that is monitoring the messages, connecting using the second policy I have on the Event Hub – the one for reading. Here I am using Microsoft.ServiceBus.Messaging (.NET library, but distributed with NAV) to create service Uri, set message factory settings and create message factory, with amqp as transport type. My hub has two partitions, so I need to create a receiver for each, and finally, for each message from that message collection, I check the data value and adjust inventory accordingly. A Power Pivot add-in for Excel is used to import data from NAV to Excel report.

The data value from my “inventory sensor” is constantly polled, the NAV inventory reflects near real time data, and the whole process looks like this:




1 thought on “(MS Dynamics) NAV Of Things

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close