Close

Adding Time Functionality

A project log for Wi-Fi Thermal Receipt Printer V1

This was a technical thesis project designed to allow a user to get a print out of the current weather and the word of the day via Wi-Fi.

scott-clandininScott Clandinin 07/12/2016 at 01:440 Comments

My next goal for this project is to add time-tracking capability to the device. It seems most appropriate to get this information from an online source, so I will attempt that. There are a couple ways I can think of to accomplish this.

Header information (the easy way)

The simplest way to get the current time is by making a call, and taking the current time from the header information. When a basic call is made to a server, there will be some header information including the current time in GMT (Greenwich Mean Time).

I tested this theory out with a serial monitor too see what returns when I made an HTTP HEAD request to "google.com". As you can see, it show the full date information. Only difficulty is converting GMT to another time zone.I am lucky here as my city does not undergo any daylight savings time change, so my time will always be GMT - 6. This will allow me to easily convert this time to CST.

The downside to this is that it becomes trickier to keep the date, month, and year in order. For example, Monday here will show up as Tuesday in GMT. I will also need to keep track of leap years. Knowing the date is not a priority in my next stage, but it would be very nice to have that information.

API Service (the hard way)

This method seems to be trickier. In my research, I was unable to find a simple free service that allowed the user to get the readable date and time for their time zone. Some services allow for this, but it will return the current date and time in Unix Time Stamp.

What is Unix Time Stamp?

It is a popular format for sending time data around. The number represents the total number of seconds that have elapsed since Thurs, Jan 1, 1970. As of writing this, the current Unix time is 1468268069, a 32-bit number.

A website that looks good for this is https://timezonedb.com/. It is easy to set up and easy to pull the desired Unix time stamp. The difficult part is turning this time format into a readable date and time. There are a couple ways to do this. 1. Manually breaking down the number keeping years, months, days, and leap years in mind. 2. Use a library function.

I'm definitely not keep on manually transforming the format type, so I took a look at some of the ways people have done this in the past. The most common tool people used was the strftime function in the time.h library. An example of such program is http://www.epochconverter.com/programming/c.

Concluding Thoughts

After looking into the Unix conversion code, I don't fully understand the implementation and different ways people have done the conversion. I realize I will need to brush up on my programming knowledge to use this in the future. But in the meanwhile, I will just go with retrieving header information from google and converting that to my local time.

Discussions