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.

Advertenties

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!

Documenting your IoT projects using Fritzing

I have build several IoT projects for my Gadgeteer and Raspberry Pi projects.

Although , as a software developer, figuring out how everything works with these intriguing components is challenging, the real challenge is documenting.

And with documenting I mean the choice of components, the layout and wiring, the use of GPIO ports, the code, pictures, etc.

Yes, it’s nice to see your projects succeed but it’s even better if you can tear everything down and rebuild it again. And to see it’s still working 🙂

I was looking at Hackster for some information and there they were shown: nice layout schema’s with in the right bottom corner the word ‘Fritzing’.

So I went do the site:

“Fritzing is an open-source hardware initiative that makes electronics accessible as a creative material for anyone. We offer a software tool, a community website and services in the spirit of Processing and Arduino, fostering a creative ecosystem that allows users to document their prototypes, share them with others, teach electronics in a classroom, and layout and manufacture professional pcbs.”

Then I downloaded the Win32 tool and it is pretty easy to use:

mf1

What I use is the breadboard function. Just pick the component you have used from the parts list and place them on the breadboard of your choice. Each component has several options, properties. And you can flip and rotate them. And you can simply drag lines which will become wires.

Tip: change the color of the wires. Use red and black for 5V and ground. Your readers like that a lot.

mf2

Here I added a Raspberry Pi, a breadboard, a led and a resistor. Se that I can add a header and some comments too.

It’s easy to export this as a picture:

myfirstfritz_bb

But if you are really proud of this project you can share it on the Fritzing site:

mf3

Do not forget to add a picture or video to make the project more attractive (Use a better camera, please):

myfirstfritz

This proofs your project is really working. That way you take a lot of doubt away from your readers.

So please give it a try. Share your projects here in the comments.