A very simple complex IoT Hub example

The Microsoft Azure service called IoT Hub is now also available in West-Europe for a couple of weeks. To be precise, it’s available as a service in East Asia, East US, North Europe, Southeast Asia, West Europe and West US.

It is good to know that there are basically three flavours available: Free, S1 standard and S2 standard. The free edition only support one, uniquely registered, device which can send eight thousand messages a day. The other versions support 400.ooo messages to six million messages a day. If you want to support more devices/messages, please contact Microsoft 🙂

Note: You can have only one Free IoT Hub in your Azure subscription. And turning a S1 IoT Hub into the free one is not possible.

Keep in mind that messages have a certain size. If the actual size of a single message is bigger than 0.5KB (free version) or 4KB (S1 or S2) it will be counted as multiple messages.

Getting started with IoT Hub is not that hard. You can start with the fine documentation at the Azure website. But that documentation is still limited. Integrating with StreamAnalytics ea. is not described. So here I present a more elaborate example (but keep in mind the MSFT documentation).

Doorgaan met het lezen van “A very simple complex IoT Hub example”

UWP app as Virtual Shields for Arduino

Are you in the position of not having a screen, GPS module, internet connection, GSM/SMS module, Gyro module, compass module, microphone module, etc. for your Arduino?

Normally you went out surfing to your favorite internet dealer for the components to buy them. And these are all pretty expensive modules. If you choose to buy them as a shield, you will have to pay even more.

But if you own a Lumia smart phone, then you could be lucky. Check this site if your Lumia is compatible with Windows 10 Mobile. Why? Because these devices support UWP apps and Microsoft has provided this Virtual Shields app.

Doorgaan met het lezen van “UWP app as Virtual Shields for Arduino”

Better long running custom Firmata functions

If you managed to get to this part, you have seen how simple wired communication protocol between two Arduino’s is transformed into communication over Bluetooth using the Firmata protocol. Great!

Now we take a look, again, at a demo given at the Ignite 2015 in Australia. In this demo, an ultrasonic distance reader is used to generate a custom stream of measurement.

Although it’s a demo and it serves a purpose, the solution shown has an architectural flaw. If we look deeper into the Arduino code, we will find a ‘while (true) {}’. It is put inside a switch inside the ‘custom function handler’ sysexCallback().

Yes, this generates a constant stream of measurement but it also locks up the Firmata on the Arduino. No other call will de handle anymore because the endless loop is just blocking further communication.

Doorgaan met het lezen van “Better long running custom Firmata functions”

Custom Firmata function called by Windows 10 IoT Core

In my previous blog, we investigated the usage of the standard Firmata protocol to communicate between UWP apps and an Arduino. I ended with directing to Channel 9 for more information about custom functions in Firmata.

But I think that’s not enough 🙂 First of all, that demo in the presentation failed. And next to that, it simply lacked any description on how to do it yourself.

I have put some time in figuring out this functionality. Again, the example below is based on the code of Part 4.

So we want to call some logic on the Arduino, using Firmata, and it has to be available for real-time usage. So we want to pass some parameters and we want to receive some response.

Doorgaan met het lezen van “Custom Firmata function called by Windows 10 IoT Core”

Use Bluetooth between Win 10 UWP and Arduino

This is part 3 of a series of blogs about device communication between Arduino, RaspberryPi etc:

  • Part 1: Using I2C to connect two Arduino Nano’s
  • Part 2: Using I2C between Rpi Master and Arduino Slave
  • Part 3: Use Bluetooth between Win 10 UWP and Arduino
  • Part 4: Add virtual Arduino ports to your UWP app
  • Part 5: Custom Firmata function called by Windows 10 IoT Core
  • Part 6: Better long running custom Firmata functions
  • Part 7: Custom servo usage in Firmata
  • Part 8: Using NRF24L01+ modules between Arduino’s
  • Part 9: Cheap Arduino mesh using RF24 radio modules

In previous blogs, I have written about combining one or more Arduino Nano’s with a RaspberryPi using the I2C protocol. Although this is very useful, the communication is limited to the length of the cables. This is not very practical for a local gateway.

fatfight3 Get it on Windows 10

So I looked at communication using Bluetooth. So I bought some Bluetooth modules. These little components are relatively cheap and reliable. They come with four and six pins (for now, it has just two extra pins not needed, the inner four are the same with the four pins version) but the four pin variant is used in this example.

Doorgaan met het lezen van “Use Bluetooth between Win 10 UWP and Arduino”

Time flies in Windows 10 IoT Core. How to get hold on it

Yes, time actually flies in a Raspberry Pi. It appears that it can not remember the current time when it is powered off in Windows 10 IoT Core.

One solution is to make use of a ‘sensor’ which tells the time.

Another solution is to ask ‘the internet’ for the current time. I use this service although there will be more, I can imagine 🙂

using System;
using System.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

...
using (var client = new HttpClient())
{
  client.DefaultRequestHeaders.UserAgent.Add(
    new HttpProductInfoHeaderValue(
          "Mozilla / 5.0(Windows NT 10.0; Win64; x64)"));
  var response = await client.SendRequestAsync(
              new HttpRequestMessage(
              HttpMethod.Get,
              new Uri("http://www.timeapi.org/utc/now.json")));
  if (response.StatusCode == HttpStatusCode.Ok)
  {
     // {{"dateString": "2015-09-21T21:46:34+02:00"}}
    dynamic json = JsonConvert.DeserializeObject(
                                  response.Content.ToString());
    DateTime dateTime =
          DateTime.Parse(json.dateString.ToString(),
          CultureInfo.InvariantCulture);
    tbTest.Text = "Universal time: " 
                         + dateTime.ToUniversalTime();
  }
  else
  {
    tbTest.Text = response.StatusCode.ToString();
  }
}

This service can return a date time in several ways, but I prefer the UTC. So when received, the datetime json message is transformed into a datetime which will give me the UTC.

How to connect your RPi to the local internet using only your PC

Programming a Raspberry Pi using Windows 10 IoT Core is a lot of fun but it comes with some little issues.

The Pi is not running a full OS, like Raspbian. What the PI is running, is a full screen Windows 10 IoT Core UWP (Universal Windows Platform) application or one or more (IoT Core) background applications.

And the usual way to put your app on that PI is by deploying it using WiFi and Visual Studio 2015. That is, when you are programming and debugging.

In Visual Studio, in the project properties, you have to find the Pi on the same network as your PC/Laptop is connected to.

Windows 10 ICS - 5

So if you can attach your Pi to the local internet using a network cable, you are good to go.

But If you only have Wi-Fi, you are less fortunate. Windows 10 IoT Core supports only one WiFi dongle: the official dongle from the Pi foundation. For example, the popular Wi-Pi is not support (I can only use it in Raspbian).

What I use normally at home is the DLink 505. It has WiFi and a ethernet port and it can repeat the WiFi network on that port. So that makes my Pi very mobile indoors: Where ever there is a power plug I have a network connection and a USB port.

But it is very hard to get in running, the installation is slow and tedious. Trying to get in running outside my home (on networks with unknown passwords or landing pages) takes a lot of effort and time.

So there I use ICS which does almost the same. Your windows can share your WiFi internet using the ethernet port in your PC/Laptop

Windows 10 ICS - 4

Here the internet (1) arrives from your provider (2) at your network router (3). Your own PC (4) is connected and using ICS the device connected to the ethernet port (5) (your Pi) is also connected.

And this is easy to do.

Just go to the control panel and search for adapter. You will find the network connections…

Windows 10 ICS - 3

In there, multiple adapters will exist. Just look for two of them: the one which represents your WiFi connection and the one which represents the internal ethernet port…

Windows 10 ICS

Then go to the properties of the WiFi adapter, go to the Share page and check the top checkbox. A dropdown list will come available, select the ethernet port adapter…

Windows 10 ICS - 2

And you are done.

Connect your Pi and see an IP address will be provided.

As always, happy coding!