- Netduino Forums
- → ZakieM's Content
ZakieM's Content
There have been 26 items by ZakieM (Search limited from 22-May 23)
#30432 Auto detection NTP code
Posted by ZakieM on 08 June 2012 - 07:19 PM in General Discussion
#28761 Working FFT with RLP code
Posted by ZakieM on 09 May 2012 - 10:15 PM in General Discussion
With Arduino I had to give up as the best I could do is 2-3 times a second which visually not good enough.
The code linked here does it in 50ms overall so 20 times a second which is really good, however it using RLP (native) code. Hope you will find it useful.
The FFT code was taken from Plain FFT by Didier Longueville who maintains blog at Arduinoos site http://didier.longue...e.fr/arduinoos/ and was generous to share it with us. Thank you Didier!
Video
<iframe width="420" height="315" src="http://www.youtube.com/embed/BAqij8u8jzA" frameborder="0" allowfullscreen></iframe>
#28277 N+ showing Weather Underground information on VGA
Posted by ZakieM on 28 April 2012 - 10:41 PM in Project Showcase
Attached Files
- WeatherUndergroundScreen.zip 777KB 11 downloads
#27866 PC rebooting on NetduinoPlus Disconnect
Posted by ZakieM on 22 April 2012 - 05:01 AM in Beta Firmware and Drivers
#27718 N+ showing Weather Underground information on VGA
Posted by ZakieM on 20 April 2012 - 01:37 PM in Project Showcase
The N+ also tells the uVGA the time and date.
The uVGA itself then is running a program I wrote (it is programmable using 4GL language) that split the screen to tiles, changes font sizes, colors and what have you. Icons and bitmaps are stored on SD card of the uVGA. That code and content of the SD is part of the ZIP file.
The N+ updates the uVGA only once in few minutes. In the mean time an internal timer on the uVGA is interrupting once a second so that you get a clock with seconds displayed.
Both N+ and uVGA have very inaccurate timing, but the N+ is slightly better. This is why the NTP is polled once in 6 hours and fixes the drifts of the N+ time, and then the N+ is also updating the uVGA.
The uVGA has two firmwares, the one I use that requires you to program in 4GL and another one that lets you send graphical commands from UART. Switching between the two is simple. Take a look at their site.
#27714 N+ showing Weather Underground information on VGA
Posted by ZakieM on 20 April 2012 - 01:03 PM in Project Showcase
#27712 N+ showing Weather Underground information on VGA
Posted by ZakieM on 20 April 2012 - 12:45 PM in Project Showcase
Features
- Fully automatically identifies location in the globe and time
- Graphically displays current and forecast weather information
- Automatically synchronizes time and daylight savings from the internet (using NTP protocol)
- Shows sunrise, sunset and moon phase information
- Does not require any PC to be involved
- Easy to connect and assembly, only Ethernet cable and power supply
- Supports DHCP for network connection
- Supports both VGA screens and small 3.2" screens
Code and instructions (very easy) in here
#27051 PC rebooting on NetduinoPlus Disconnect
Posted by ZakieM on 12 April 2012 - 08:31 AM in Beta Firmware and Drivers
I now downgraded the Netduino itself to 4.1.06 again (not enough code space for my program in 4,2).
PC Information:
Windows 7 64bit (fully updates from MS)
VS 2010 Professional v 10.0.40219.1 SP1 Rel
NetduinoPlus Driver information:
(right click on the NetduinoPlus device in device manager)
6.1.7600.16385 by WinDDK
.
#26810 Moving to SDK 4.2 question
Posted by ZakieM on 09 April 2012 - 09:49 PM in Netduino Plus 2 (and Netduino Plus 1)
#26749 Assemblies not successfully deployed to device
Posted by ZakieM on 08 April 2012 - 09:16 PM in General Discussion
#26745 Assemblies not successfully deployed to device
Posted by ZakieM on 08 April 2012 - 08:31 PM in General Discussion
I checked couple of programs, but found issues. Projects with any networking seems to work fine. However, projects involving networking do not get deployed.
The error I am getting is quite useless:
Incrementally deploying assemblies to device
Deploying assemblies for a total size of 51348 bytes
Assemblies not successfully deployed to device.
Deployment to the device was not successful.
And the error list suggest I should check my hardware.
Any pointer for identifying the problem will be appreciated.
#26744 Moving to SDK 4.2 question
Posted by ZakieM on 08 April 2012 - 08:15 PM in Netduino Plus 2 (and Netduino Plus 1)
#26729 Moving to SDK 4.2 question
Posted by ZakieM on 08 April 2012 - 11:38 AM in Netduino Plus 2 (and Netduino Plus 1)
In the article Installing the TinyBooterDecompressor step by step (Netduino and Netduino Plus) I got to the surprising step of flashing the TinyBooter... but could not find where to get it from. In the SecretLabs directory I only have Assemblies and drivers.
Any help will be appreciated.
#25927 Auto detection NTP code
Posted by ZakieM on 24 March 2012 - 11:43 AM in General Discussion
timezone. To avoid too large assemblies, I did not use any XML or JSON parsing
classes. If your application is using XML or JSON parsing, the use of those here
could reduce code size.
The code refreshes local time with NTP server in a configurable number of hours. I noticed that on my device with 10 hours the clock gets drifted in couple of seconds. Use 5-6 hours for refresh. This is the main reason I wrote this code... I did not implement a refresh when DST turns on or off. If anyone adds that, please share.
How it Works:
By quering geobytes.com and askGeo.com I am finding the actual time-zone of the device:
Through geobytes.com I am finding my location in the world
Through askGeo.com I am finding the timezone data of this location
Limitations:
This auto-detection will work if the device is connected to the internet through
standard NAT configuration, but with remote proxies the auto-detection will be
wrong as it will detect the timezone of the proxy itself. For most applications
however it is good enough.
Don't expect a GPS accuracy for your location. It will probably get you the
name of city/town where your ISP is, and not your actual location, still for
timezone purposes this good enough.
Please read http://www.askgeo.com Terms of Use and legal disclaimer
Special NOTE:
In this code an API Key that is registered to the author of this code.
>>>> Please modify it to your registered key <<<<
Search below for <<<< to location of where you need to put your key
You may use the code, modify or include in any project you have, posted in the hope it will be useful.
Please read http://www.askgeo.com Terms of Use and legal disclaimer
Please read http://www.geobytes.com Terms and Conditions
/* ===================================================================================== * NTP Protocol synchronization code * In this code an implementation of NTP client and auto-detection classes for actual * timezone. To avoid too large assemblies, I did not use any XML or JSON parsing * classes. If your application is using XML or JSON parsing, the use of those here * could reduce code size. * * How it Works: * By quering geobytes.com and askGeo.com I am finding the actual time-zone of the * device: * Through geobytes.com I am finding my location in the world * Through askGeo.com I am finding the timezone data of this location * Limitations: * This auto-detection will work if the device is connected to the internet through * standard NAT configuration, but with remote proxies the auto-detection will be * wrong as it will detect the timezone of the proxy itself. For most applications * however it is good enough. * * Don't expect a GPS accuracy for your location. It will probably get you the * name of city/town where your ISP is, and not your actual location, still for * timezone purposes this good enough. * * Please read http://www.askgeo.com Terms of Use and legal disclaimer * * Special NOTE: * In this code an API Key that is registered to the author of this code. * >>>> Please modify it to your registered key <<<< * Search below for <<<< to location of where you need to put your key * ===================================================================================== * By: Zakie Mashiah * You may use the code, modify or include in any project you have. * Please read http://www.askgeo.com Terms of Use and legal disclaimer * Please read http://www.geobytes.com Terms and Conditions * ===================================================================================== */ using System; using System.Threading; using System.IO; using System.Text; using System.Net; using System.Net.Sockets; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using Microsoft.SPOT.Net; using Microsoft.SPOT.Time; using SecretLabs.NETMF; using SecretLabs.NETMF.Hardware; namespace NTPThread { public class GeoLoactionByIP { public string country; public string region; public string city; public string latitude; public string longitude; public string timezone; public int timeZoneMinutesGMT; // How many minutes from GMT public string externalIPAddress; private string queryString { get { return "http://www.geobytes.com/IpLocator.htm?GetLocation&Template=XML.txt"; } } /// /// Converts the internal string member of timezone to internal member of minutes from GMT /// private void _parseTimeZoneString() { int sign; int hour; int minute; sign = timezone[0] == '+' ? 1 : -1; hour = (timezone[1] - '0') * 10 + (timezone[2] - '0'); minute = (timezone[4] - '0') * 10 + (timezone[5] - '0'); timeZoneMinutesGMT = sign * ((hour * 60) + minute); } /// /// Read an attribute in the XML string until the end of the attribute /// /// String with the reply XML and starting with the value /// The sub-string until end of parameter denotion of XML private string _readAttribute(string parser, bool isString = true) { int start, end; string rv = null; string de = (isString) ? "\"" : ","; // Data ends at string ds = (isString) ? "\":\"" : "\":"; // Data starts at start = parser.IndexOf(ds); if (start > 0) { start += ds.Length; end = parser.IndexOf(de, start); if (end > 0) { rv = parser.Substring(start, end - start); } } return rv; } /// /// Reads the stream of reply from the geobytes and parses it into the variables /// /// the stream of the reply private void _readStream(Stream s) { System.Threading.Thread.Sleep(1000); // Wait a while StreamReader sr = new StreamReader(s); string parser = sr.ReadToEnd(); int location = parser.IndexOf("country\":\""); if (location > 0) { parser = parser.Substring(location); this.country = _readAttribute(parser); location = parser.IndexOf("region\":\""); if (location > 0) { parser = parser.Substring(location); this.region = _readAttribute(parser); location = parser.IndexOf("city\":\""); if (location > 0) { parser = parser.Substring(location); this.city = _readAttribute(parser); location = parser.IndexOf("latitude\":"); if (location > 0) { parser = parser.Substring(location); this.latitude = _readAttribute(parser, false); location = parser.IndexOf("longitude\":"); if (location > 0) { parser = parser.Substring(location); this.longitude = _readAttribute(parser, false); location = parser.IndexOf("timezone\":\""); if (location > 0) { parser = parser.Substring(location); this.timezone = _readAttribute(parser); location = parser.IndexOf("ipaddress\":"); if (location > 0) { parser = parser.Substring(location); this.externalIPAddress = _readAttribute(parser); // Now parse the timezone string to minutes _parseTimeZoneString(); } } } } } } } } /// /// Queries the Geobytes service for location of the IP address. /// /// public void queryLocation(string ip = null) { string q = (ip == null) ? queryString : queryString + ip; HttpWebRequest request = HttpWebRequest.Create(q) as HttpWebRequest; WebResponse resp = null; try { resp = request.GetResponse(); } catch (Exception e) { Debug.Print("ERROR: Exception in HttpWebRequest.GetResponse() for geobytes.com" + e.ToString()); } if (resp != null) { Stream respStream = resp.GetResponseStream(); respStream.ReadTimeout = 5000; _readStream(respStream); resp.Close(); } request.Dispose(); } public override string ToString() { return "Country=\t" + country + "\n\tRegion=\t" + region + "\n\tCity=\t" + city + "\n\tLatitude=\t" + latitude + "\n\tLongitude=\t" + longitude + "\n\tTimezone=\t" + timezone + "\n\tMinutesFromGMT=\t" + timeZoneMinutesGMT + "\n\tExternalIP=\t" + externalIPAddress; } } public class AskGeoService { public long currentOffserMS; private const string accountID = ""; // <<<< Put up your account ID, PLEASE! private const string apiKey = ""; // <<<< Put here your API key, PLEASE! private string queryString(string latitude, string longitude) { return "http://www.askgeo.com/api/" + accountID + "/" + apiKey + "/timezone.json?points=" + latitude + "%2C" + longitude; } public void queryLocation(string latitude, string longitude) { string q = queryString(latitude, longitude); HttpWebRequest request = HttpWebRequest.Create(q) as HttpWebRequest; WebResponse resp = null; try { resp = request.GetResponse(); } catch (Exception e) { Debug.Print("ERROR: Exception in HttpWebRequest.GetResponse() for askgeo.com" + e.ToString()); } if (resp != null) { Stream respStream = resp.GetResponseStream(); respStream.ReadTimeout = 5000; System.Threading.Thread.Sleep(1000); // Wait a while StreamReader sr = new StreamReader(respStream); string parser = sr.ReadToEnd(); int location; location = parser.IndexOf("currentOffsetMs\":"); if (location > 0) { parser = parser.Substring(location); int start = parser.IndexOf(':') + 1; location = parser.IndexOf(','); string currentOffsetMsString = parser.Substring(start, location - start); currentOffserMS = Convert.ToInt32(currentOffsetMsString); } resp.Close(); } request.Dispose(); } } public class NetworkTimeProtocolThread { #region Variables private static int sleepTime = 60 * 10; // Every 10 hours private static string ntpName = "time-a.nist.gov"; private static int minutesFromGMT; #endregion #region PrivateFunctions private static void SleepMinutes() { int times; times = sleepTime == 0 ? 1 : sleepTime; for (int i = 0; i < times; i++) { Debug.Print(DateTime.Now.ToString() + " NTP Thread:: " + i.ToString() + " of " + times.ToString()); Thread.Sleep(60 * 1000); // Minute } } private static void SetSystemTime(DateTime dt) { // Simulate timezone and DST of 3 hours (life is good in Tel-Aviv :-) TimeSpan timezoneOffset = TimeSpan.FromTicks(minutesFromGMT * TimeSpan.TicksPerMinute); dt += timezoneOffset; Debug.Print("\tSetting time to:\t" + dt.ToString()); Utility.SetLocalTime(dt); Debug.Print("\tSystem Time is :\t" + DateTime.Now.ToString()); } #endregion #region PublicFunctions public static void SetRefreshRate(int hoursForRefresh) { sleepTime = hoursForRefresh * 60; } public static void SetNTPHost(string host) { ntpName = host; } public static int GetTimeZoneOffset() { return minutesFromGMT; } public static void SetTimeZoneOffset(int minutes_from_GMT) { minutesFromGMT = minutes_from_GMT; } public static DateTime GetNetworkTime() { DateTime dt = new DateTime(1900, 1, 1, 1, 1, 1); IPHostEntry ntpServer = Dns.GetHostEntry(ntpName); if (ntpServer == null) { Debug.Print("ERROR: Can't find DNS entry for " + ntpName); return dt; } if (ntpServer.AddressList == null) { Debug.Print("ERROR: No addresses found for NTP server " + ntpName); return dt; } IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(ntpName).AddressList[0], 123); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); s.Connect(ep); byte[] ntpData = new byte[48]; // RFC 2030 ntpData[0] = 0x1B; for (int i = 1; i < 48; i++) ntpData[i] = 0; s.Send(ntpData); s.Receive(ntpData); byte offsetTransmitTime = 40; ulong intpart = 0; ulong fractpart = 0; for (int i = 0; i <= 3; i++) intpart = 256 * intpart + ntpData[offsetTransmitTime + i]; for (int i = 4; i <= 7; i++) fractpart = 256 * fractpart + ntpData[offsetTransmitTime + i]; ulong milliseconds = (intpart * 1000 + (fractpart * 1000) / 0x100000000L); s.Close(); TimeSpan timeSpan = TimeSpan.FromTicks((long)milliseconds * TimeSpan.TicksPerMillisecond); DateTime dateTime = new DateTime(1900, 1, 1); dateTime += timeSpan; TimeSpan offsetAmount = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime); DateTime networkDateTime = (dateTime + offsetAmount); Debug.Print(" NetworkDateTime: " + networkDateTime.ToString()); return networkDateTime; } #region NTPThreadRunner public static void Run() { Debug.Print("Network Time Protocol Thread starting...\n\tServer\t" + ntpName + "\n\tevery\t" + sleepTime.ToString() + " hours"); while (true) { Debug.Print("NTP Thread:: Checking NTP server time. Time before: " + DateTime.Now.ToString()); DateTime dt = GetNetworkTime(); SetSystemTime(dt); SleepMinutes(); } } #endregion #endregion } // End of NTP Thread class }
Test Code:
using System; using System.IO; using System.Text; using System.Threading; using System.Net; using System.Net.Sockets; using System.Collections; using Microsoft.SPOT; using Microsoft.SPOT.IO; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF; using SecretLabs.NETMF.Hardware.NetduinoPlus; using NTPThread; /// This program demonstrates how to use the .NET Micro Framework HTTP classes /// to create a simple HTTP client that retrieves pages from several different /// websites, including secure sites. namespace NTPTestProgram { public static class NTPTestProgram { #region Variables static DateTime startTime; #endregion // Variables #region Main /// /// Retrieves weather current and forecast information from Google Weather and display /// it on the LCD with time ticking clock /// public static void Main() { DateTime dt; int delay; // Initialization InitNetwork(); InitLocation(); InitRealTimeClock(); // Loop (forever) for (int minute = 0; ; minute += 1000) { if (minute > (60 * 1000)) minute = 0; dt = DateTime.Now; ShowTime(); TimeSpan ts = DateTime.Now - dt; delay = 1000 - ts.Milliseconds; if (delay > 0) Thread.Sleep(delay); else Debug.Print("Total processing time was: " + ts.Milliseconds.ToString()); } } #endregion #region InitFunctions public static void InitNetwork() { } // Would need to populate if using a Ethernet Shield public static void InitRealTimeClock() { NetworkTimeProtocolThread.SetRefreshRate(5); new Thread(NetworkTimeProtocolThread.Run).Start(); Thread.Sleep(1000); // Wait a second for NTP to push system time startTime = DateTime.Now; Debug.Print("Starting at: \t[" + startTime.ToString() + "]"); } public static void InitLocation() { GeoLoactionByIP myLocation = new GeoLoactionByIP(); AskGeoService askGeo = new AskGeoService(); myLocation.queryLocation(); Debug.Print("Location:\n\t" + myLocation.ToString() ); askGeo.queryLocation(myLocation.latitude, myLocation.longitude); int minutes = (int)(askGeo.currentOffserMS / 1000 / 60); Debug.Print("\tCurrent timezone offset=" + minutes + " minutes"); NetworkTimeProtocolThread.SetTimeZoneOffset(minutes); } #endregion #region UtilityFunctions private static string DecimalTwoPos(int d) { if (d < 10) return "0" + d.ToString(); else return d.ToString(); } #endregion #region DisplayFunctions private static void ShowTime() { DateTime dt = DateTime.Now; string s = DecimalTwoPos(dt.Hour) + ":" + DecimalTwoPos(dt.Minute)+ ":" + DecimalTwoPos(dt.Second); Debug.Print(s); } #endregion } }
Attached Files
- NetduinoPlusAutoNTP.zip 39.35KB 23 downloads
#25134 HMC5883L Magnetometer Netduino Code
Posted by ZakieM on 06 March 2012 - 07:36 AM in Project Showcase
Attached Files
- ST7565 Display.zip 729KB 58 downloads
#24053 HMC5883L Magnetometer Netduino Code
Posted by ZakieM on 10 February 2012 - 09:55 AM in Project Showcase
So I borrowed the code from here plus a lot of code from http://LoveElectronics.co.uk to integrate 3 I2C devices on the same bus:
HMC5883L Magnetometer
ADXL345 Accelerometer
ITG3200 Gyro
And glued those together to display results on ST7565 LCD display (code from thttp://inyclr.com).
I hope that what I found simpler to use in order to access multiple devices on the bus will be useful for others too.
Attached Files
- ST7565 Display.zip 34.16KB 74 downloads
#21185 Compatible Shields and Accessories
Posted by ZakieM on 30 November 2011 - 08:50 PM in Netduino 2 (and Netduino 1)
That was my first Netduino work (well after the LED blink sample), and I simply ported the code from the Arduino C/C++ to C#
#16701 Send data wirelessly using RF modules
Posted by ZakieM on 14 August 2011 - 05:31 AM in General Discussion
#16206 Accuracy of time
Posted by ZakieM on 02 August 2011 - 09:36 PM in Netduino Plus 2 (and Netduino Plus 1)
#16154 USB Oscilloscopes?
Posted by ZakieM on 01 August 2011 - 07:09 PM in General Discussion
#16153 Accuracy of time
Posted by ZakieM on 01 August 2011 - 06:58 PM in Netduino Plus 2 (and Netduino Plus 1)
#16006 USB Power and 9volt battery life
Posted by ZakieM on 28 July 2011 - 04:12 PM in Netduino Plus 2 (and Netduino Plus 1)
With my project, I eventually gave up and used Arduino Fio with LiPo battery and the device sleeps for 2seconds, wakes up check status and if nothing to do, goes back to sleep. By that I extended the lifetime of a 2000mA battery by 10 folds at least. With the Fio being extremely battery friendly I completed the project and battery last there for 4 months already without recharging. Still, I felt bad for not doing it with the Netduino (defeat the purpose I called it).
#16004 Netduino Plus Firmware v4.2.0 BETA 1
Posted by ZakieM on 28 July 2011 - 03:58 PM in Beta Firmware and Drivers
#15955 Where do I get the address from?
Posted by ZakieM on 27 July 2011 - 06:52 AM in Netduino Plus 2 (and Netduino Plus 1)
In MFDeploy main window chose USB instead of Serial, then went to Target menu as you said above, DHCP was on, turned it off set static values that made sense and it did not work. After setting DHCP on again, it started working. I guess something was in zombie mode before.
Now on to do the project: Electricity cabinet monitoring.
#15940 Where do I get the address from?
Posted by ZakieM on 26 July 2011 - 09:57 PM in Netduino Plus 2 (and Netduino Plus 1)
My network is 192.168.2.XX and I know my router gives good IP addresses to other devices connected to same Ethernet cable...
Since the DGW is 192.168.5.1 too, I suspect this is some sort of default somewhere... but could not find it.
Can someone direct me to where the problem might be?
- Netduino Forums
- → ZakieM's Content
- Privacy Policy