Step 5: How does this work?
Steps of operation:
- Netduino-Plus first leases and IP address from your DHCP server
- Netduino-Plus goes to internet service http://www.geobytes.com/ to find out where in the world it is located. The output from this service includes city, country etc. but what we take from it is the longitude and latitude.
- Netduino-Plus goes to internet service http://www.askgeo.com/ to find out what is the current offset of your location from UTC. This way we know not only your time zone but also daylight savings.
- Netduino-Plus goes to NTP service on the internet to get accurate atomic time and sets the Netduino-Plus internal clock for this time together with the offset we found out earlier.
- Netduino-Plus goes to Weather Underground service http://www.wunderground.com/ to fetch current and forecast weather information.
- Netduino-Plus sends the weather data and clock to the 4D device over serial (UART) interface using simple protocol which I will skip the description of here. It is in the code.
- Time from NTP is synchronized every 300 minutes (6 hours) which I found to be sufficiently accurate.
- Weather information is downloaded every 10 minutes. More than enough for most people and cases. More frequent updates from Weather Underground will require you to be a paying user.
- Time from NetduinoPlus is sent to 4D device every 3 minutes (Netduino timers found a bit more accurate than the 4D ones)
- The 4D device formats data from textual stream it got from the Netduino-Plus to graphics on the screen.
My previous project when using the Arduino was already challenging from memory perspective to the Arduino board, and I was certain the additional information from Weather Underground would not fit, not to mention the automation tricks for finding location and DST. It appeared to me the Netduino will be a better fit for the job as it has some more resources like memory and faster CPU (48MHz vs. 16MHz on Arduino). Also managed code was very appealing for such internet inquiries… but later found out that once you load the XML generic parser assembly to the host, you are running out of memory. Worse than that, it was not enough to add the features I wanted for automation of DST and location. Disappointed I decided to stick to what's important, the automation and simplicity, and spend some tedious keystrokes myself on parsing XML myself. Oh well, nothing is ever as bright as originally seen by optimistsï. The state of matters now is that the Netduino-Plus is having its own memory challenges, and this program as is here fits well in and works, but there is very little room to add anything more. So, compared to previous project, this one does not measure indoor temperature and humidity. Also, the low priced DHT22 sensors that I have are not well supported on the Netduino. There are rumors it works with .NETMF 4.2 that is in beta, but once I uploaded the .NETMF 4.2 onto the Netduino, there was not enough room for the program even before adding the sensor code. So again, I picked automation and simplicity over richer functionality.
The XML parsing is done by reading one byte at a time from the internet socket. As this is managed code, it works horribly slow. It takes my Netduino-Plus good 19 seconds to parse the XML stream from Weather Underground. I think I know how to optimize it for much better performance, like using Stream class and all, but guess what? It run out of memory when doing that. The truth of the matter is that I could not care less if the Netduino-Plus CPU is spending 19 seconds in sleep or chewing bits from Weather Underground. I got nothing better for it to do AND even if I wanted, it is left without memory to do anything more. So, let it crawl through the stream at its own paste, and those 19 seconds should not matter much to anyone. You will notice that the on-board LED on the Netduino (cool blue one) will light up when it does its turtle parsing of the XML data.
I also repurposed the on-board button on the Netduino-Plus to act as "Sync time and weather information now" instead of reset. This change was useful when debugging and I am happy with power recycling as real reset anyway.
The guys in Weather Underground actually enforce the limits which is 500 calls daily or 10 a minute. So this is why I am not sharing my key with you here and also you should avoid doing that. I included their logo and stuff as their terms of conditions require.
The AskGeo service was in alpha or beta when I started using it. Now they moved to Amazon cloud and made slight modifications to the services. I updated the code accordingly, so you should not bother with any of that. Please note you should register yourself with them too and same drill about not sharing your key publicly.
About the "trick" for finding out location, it is not without limitation. It should work on any home network, but in the office it might be a bit of a challenge. If your network is going through a very remote proxy, like many organizations are still using for connecting remote offices to the internet, then the location the Netduino-Plus finds is where your proxy server is. It is fairly easy to change the Netduino-Plus code to use fixed location instead of auto-detecting it, and I will let those who are interested do it themselves. Hint: All you need is use fixed longitude and latitude in function ' InitLocation' coded in the file Program.cs