DateTime.Now.AddHours(2)
Seems to work just fine for the moment

Thanks,
Donovan
![]() |
  | |||||||||||||
![]() |
|
![]() |
||||||||||||
The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
don664's ContentThere have been 77 items by don664 (Search limited from 06-July 24) #40291 RN-XV WiFly Module driver
ok, as a work around, I am simply adding two hours when I call for the date and time:
DateTime.Now.AddHours(2) Seems to work just fine for the moment ![]() Thanks, Donovan #40013 RN-XV WiFly Module driver
When was this added and is there an example of it's simple usage to set the dateTime on the Netduino? Thanks, Donovan #40220 RN-XV WiFly Module driver
Ah ha
![]() #40239 RN-XV WiFly Module driver
Is there a way to set the timezone just before the synchronize; as I need the times to be GMT +2?
Thanks
![]() #40212 RN-XV WiFly Module driver
Hi Stefan, Thanks... but now I don't know how to set the time as "Synchronize" is not part of SimpleSocket:
I've tried looking through the IntelliSense options for TimeClient but can't figure out which to use. // Initializes the time client SimpleSocket TimeClient = new WiFlySocket("time-a.nist.gov", 123, WifiModule); // Displays the time in three ways: Debug.Print("Amount of seconds since 1 jan. 1900: " + TimeClient.NtpLookup()); //Debug.Print("UTC time: " + TimeClient.UTCDate.ToString()); //Debug.Print("Local time: " + TimeClient.LocalDate.ToString()); // Synchronizes the internal clock TimeClient.Synchronize(); #40165 RN-XV WiFly Module driver
Hi Stefan,
Thanks for the link... which reference do I need to add for "IntegratedSocket"? I keep getting the following error:
I'm running a Netduino Plus 2. #40095 RN-XV WiFly Module driver
I have the toolbox.... will look again for an ntpvexample
Thanks :-)
#43108 Memory leak
Hi NooM,
I have tried this in various places but still seem to end up losing 3528 bytes in the first loop... and then consistently 852 bytes for subsequent loops.
I even tried removing the counter variable (which is increased by 1 each loop after a successful HTTP request) but this does not affect the memory leak... so it's something else that is eating up the memory?? #43098 Memory leak
d'oh!!
What a good idea, I'll give that a try and let you know where it swallows up the RAM.
Thanks Chris!! #43667 Memory leak
as far as i know you have to use simpleSocket in conjunction with a wifi connection? #43104 Memory leak
Hi Cuno,
I noticed this after printing out free RAM in various places and then removing a lot of these "Debug.Print" statements... I even stopped printing out the querystring and now am only losing about 852 bytes per cycle... still seems strange to be losing so much.
I've also thought about adding some delay's into the project hoping that this will result in threads "dying" naturally so the next time around it creates them fresh? #44165 Memory leak
Hi emg,
Thanks for the lead. I have spoken with OpenPicus and ordered a board which is on it's way for me to test. Hopefully their wifi module can handle FTP (which they claim) and will help my project along.
Cheers, Donovan #43095 Memory leak
Hi there,
I am building a live data logger (basically a counter) which sends counts (collected by a photo sensor) to a webpage in a querystring so the data can be added to a SQL DB.
To make sure that I have a redundancy, in the event of power failure for example, I have two files on an SD card which the counter writes to on the photo sensor interrupt. Periodically the SD card is read and the data put into an array which is then looped through to send the HTTP requests. This prevents any issues of trying to read from the SD card at the same time as a photo interrupt is trying to write to the card.
I'm using a Netduino Plus 2.
At the moment I am testing a part of the final code and have encountered a "memory leak" issue.
Basically I am simply looping through the "SD Card read" and "array send threads" to test them. the problem I am having is that I eventually run out of memory and I can't understand why.
I would have thought that the only thing taking up memory would be the counter variable (which is the only thing that changes with each request... it's increased by one) but for whatever reason on each loop I lose about 3500 bytes.
I have made sure that I flush/close/dispose both the stream reader and stream writer (used for writing errors to a log file) when I am finished using them. I also clear the array when i am done with it.
Surely increasing the counter variable by an increment of 1 is not 3500 bytes worth of memory?
Do I need to abort/close threads as I leave them? Is it something to do with the "Socket" or "WebSession"... do I need to somehow terminate/clear these before creating new ones?
using System;using System.Collections;using System.IO;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Toolbox.NETMF.Hardware;using Toolbox.NETMF.NET;using VariableLabs.PowerManagment;namespace testToolbox21240{ public class Program { static WiFlyGSX WifiModule; static ArrayList counterDataArray = new ArrayList(); // SD Card file variables static string strWriteFile = "datatwo"; static string strReadFile = "dataone"; // WiFi SSID and password static string strSSID = "mySSID"; static string strPassword = "myPassword"; // Remote host URL static string strRemoteHost = "myUrl.com"; // Counter variables static uint intCounter = 0; static uint intTimeoutCounter = 0; public static void Main() { Debug.Print("Turn off the Ethernet controller"); PowerManagment.SetPeripheralState(Peripheral.Ethernet, false); Debug.EnableGCMessages(true); connectToWifi(); populateArray(); Thread.Sleep(Timeout.Infinite); } public static void populateArray() { Debug.Print("Populate array from: " + strReadFile); using (var filestream = new FileStream(@"SD" + strReadFile + ".txt", FileMode.Open)) { string strSendLine; StreamReader sr = new StreamReader(filestream); while ((strSendLine = sr.ReadLine()) != null) { counterDataArray.Add(strSendLine); } sr.Close(); sr.Dispose(); } Debug.Print("send data from array"); foreach (string value in counterDataArray) { httpSendData(value); } cleanUp(); } public static void httpSendData(string queryStringData) { SimpleSocket Socket = new WiFlySocket(strRemoteHost, 80, WifiModule); HTTP_Client WebSession = new HTTP_Client(Socket); try { HTTP_Client.HTTP_Response Response = WebSession.Get("/default.aspx?" + queryStringData); Debug.Print("value: " + queryStringData); } catch (System.ApplicationException e) { Debug.Print("Error Code: " + e); intTimeoutCounter++; Debug.Print("intTimeoutCounter: " + intTimeoutCounter); using (var filestream = new FileStream(@"SDlog.txt", FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("DateTime: " + DateTime.Now.AddHours(2) + "rnError Code: " + e + "rnintTimeoutCounter: " + intTimeoutCounter + "rn"); sw.Flush(); sw.Close(); sw.Dispose(); } Thread.Sleep(1500); httpSendData(queryStringData); } catch (System.NullReferenceException f) { Debug.Print("Error Code: " + f); using (var filestream = new FileStream(@"SDlog.txt", FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("DateTime: " + DateTime.Now.AddHours(2) + "rnError Code: " + f + "rnintTimeoutCounter: " + intTimeoutCounter + "rn"); sw.Flush(); sw.Close(); sw.Dispose(); } } finally { intCounter++; } } public static void cleanUp() { if (strWriteFile == "dataone") { strWriteFile = "datatwo"; strReadFile = "dataone"; } else { strWriteFile = "dataone"; strReadFile = "datatwo"; } counterDataArray.Clear(); Debug.GC(true); Debug.Print("Free Memory: " + Debug.GC(true).ToString()); Debug.Print("Record count: " + intCounter); Debug.Print("running thread count: " + ThreadState.Background.ToString()); populateArray(); } public static void connectToWifi() { Debug.Print("start wifi"); WifiModule = new WiFlyGSX(); WifiModule.EnableDHCP(); WifiModule.JoinNetwork(strSSID, 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, strPassword); Thread.Sleep(3500); // Showing some interesting output Debug.Print("Local IP: " + WifiModule.LocalIP); Debug.Print("MAC address: " + WifiModule.MacAddress); SNTP_Client TimeClient = new SNTP_Client(new WiFlySocket("ntp2.is.co.za", 123, WifiModule)); Thread.Sleep(500); TimeClient.Synchronize(); Thread.Sleep(500); Debug.Print("DateTime.Now: " + DateTime.Now.AddHours(2)); Thread.Sleep(3500); } }}
A snippet of the debug output:
Thanks for any advice!
Donovan #44164 Memory leak
Hi skobyJay,
I wasn't sure how to modify the array as you suggested, or implement the iDisposable using method so I thought the best thing was to simply try and put the whole project together including the sensor.and this seems to have helped with the memory leak.
Previously I was setting up a loop to simply read from a SD card file, populate the array and send via HTTP then read from a second file, send and start at the first file again. This loop seems to have been the real issue as it never "released" any of the threads?
Anyway now that the SD card read/array populate/http send are triggered by the sensor count the memory loss has stopped (apart from a few bytes for the counter variables obviously). So i can only imagine it's because that now there isn't a loop the garbage collector can release resources held by the various threads.
I'm still having timeout issues with the wifi module but at least it feels like another step forward.
The most recent version of the code below:
using System;using System.Collections;using System.IO;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Toolbox.NETMF.Hardware;using Toolbox.NETMF.NET;using VariableLabs.PowerManagment;namespace testToolbox21240{ public class Program { // Hardware: wifly, sensor and LCD static WiFlyGSX WifiModule; static InterruptPort mySensor; // SD Card file variables static string strWriteFile = "dataone"; static string strReadFile = "datatwo"; static int intDeviceID = 1; // WiFi SSID and password static string strSSID = "mySSID"; static string strPassword = "myPassword"; // Remote host URL static string strRemoteHost = "myRemoteHost"; // Counter variables static uint intCounter = 0; static int intSendCounter = 0; static int intArrayCounter = 0; static uint intTimeoutCounter = 0; static ArrayList counterDataArray = new ArrayList(); static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); public static SimpleSocket Socket; public static HTTP_Client WebSession; public static void Main() { PowerManagment.SetPeripheralState(Peripheral.Ethernet, false); Debug.EnableGCMessages(true); connectToWifi(); // setup sensor interrupt mySensor = new InterruptPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); mySensor.OnInterrupt += new NativeEventHandler(mySensor_OnInterrupt); Thread.Sleep(Timeout.Infinite); } public static void mySensor_OnInterrupt(uint port, uint state, DateTime time) { string strDateTime = (DateTime.Now.AddHours(2).Month.ToString() + "/" + DateTime.Now.AddHours(2).Day.ToString() + "/" + DateTime.Now.AddHours(2).Year.ToString() + "%20" + DateTime.Now.AddHours(2).Hour.ToString() + ":" + DateTime.Now.AddHours(2).Minute.ToString() + ":" + DateTime.Now.AddHours(2).Second.ToString()); using (var filestream = new FileStream(@"SD" + strWriteFile + ".txt", FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("deviceID=" + intDeviceID + "&count=" + intCounter + "&dateTimeStamp=" + strDateTime); sw.Flush(); sw.Close(); } intCounter++; intSendCounter++; Debug.Print("intCounter: " + intCounter + "intSendCounter: " + intSendCounter); Thread.Sleep(250); if (intSendCounter == 5) { intSendCounter++; populateArray(); } } public static void populateArray() { if (strWriteFile == "dataone") { strWriteFile = "datatwo"; strReadFile = "dataone"; } else { strWriteFile = "dataone"; strReadFile = "datatwo"; } Debug.Print("Populate array from: " + strReadFile); using (var filestream = new FileStream(@"SD" + strReadFile + ".txt", FileMode.Open)) { string strSendLine; StreamReader sr = new StreamReader(filestream); while ((strSendLine = sr.ReadLine()) != null) { counterDataArray.Add(strSendLine); } sr.Close(); sr.Dispose(); } Thread httpSendThread = new Thread(httpSendData); httpSendThread.Start(); } public static void httpSendData() { try { foreach (string value in counterDataArray) { HTTP_Client.HTTP_Response Response = WebSession.Get("/default.aspx?" + value); } } catch (System.ApplicationException e) { Debug.Print("Error Code: " + e); intTimeoutCounter++; Debug.Print("intTimeoutCounter: " + intTimeoutCounter); using (var filestream = new FileStream(@"SDlog.txt", FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("DateTime: " + DateTime.Now.AddHours(2) + "rnError Code: " + e + "rnintTimeoutCounter: " + intTimeoutCounter + "rn"); sw.Flush(); sw.Close(); sw.Dispose(); } Thread.Sleep(1500); httpSendData(); } catch (System.NullReferenceException f) { Debug.Print("Error Code: " + f); using (var filestream = new FileStream(@"SDlog.txt", FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("DateTime: " + DateTime.Now.AddHours(2) + "rnError Code: " + f + "rnintTimeoutCounter: " + intTimeoutCounter + "rn"); sw.Flush(); sw.Close(); sw.Dispose(); } } finally { cleanUp(); } } public static void cleanUp() { File.Delete(@"SD" + strReadFile + ".txt"); counterDataArray.Clear(); Debug.Print("Free Memory: " + Debug.GC(true).ToString()); intSendCounter = 0; Debug.GC(true); } public static void connectToWifi() { WifiModule = new WiFlyGSX(); WifiModule.EnableDHCP(); WifiModule.JoinNetwork(strSSID, 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, strPassword); Thread.Sleep(3500); // Showing some interesting output Debug.Print("Local IP: " + WifiModule.LocalIP); Debug.Print("MAC address: " + WifiModule.MacAddress); // Set the RTC for GMT + 2 SNTP_Client TimeClient = new SNTP_Client(new WiFlySocket("ntp2.is.co.za", 123, WifiModule)); Thread.Sleep(1000); TimeClient.Synchronize(); Debug.Print("DateTime.Now: " + DateTime.Now.AddHours(2)); Socket = new WiFlySocket(strRemoteHost, 80, WifiModule); WebSession = new HTTP_Client(Socket); } }}
Thanks for the help... I'll keep you posted on any further progress!
Have a great weekend! #43909 Memory leak
I don't think the HTTP delay has anything to do with the server, but rather the time the wifly module takes to process the request. I have changed to the remote host from the Toolbox example and it's still taking about a second per HTTP request.
Also since stripping out the try/catch statements the memory leak has gone from 684 bytes to a whopping 1728 bytes??!!
Here's the code:
using System;using System.Collections;using System.IO;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Toolbox.NETMF.Hardware;using Toolbox.NETMF.NET;using VariableLabs.PowerManagment;namespace testToolbox21240{ public class Program { // Hardware: wifly, sensor and LCD static WiFlyGSX WifiModule; // SD Card file variables static string strWriteFile = "datatwo"; static string strReadFile = "dataone"; // WiFi SSID and password static string strSSID = "mySSID"; static string strPassword = "myPasssowrd"; // Remote host URL static string strRemoteHost = "www.netmftoolbox.com"; // Counter variables static uint intCounter = 0; static ArrayList counterDataArray = new ArrayList(); public static SimpleSocket Socket; public static HTTP_Client WebSession; public static void Main() { PowerManagment.SetPeripheralState(Peripheral.Ethernet, false); Debug.EnableGCMessages(true); connectToWifi(); Thread.Sleep(Timeout.Infinite); } public static void populateArray() { Debug.Print("Populate array from: " + strReadFile); using (var filestream = new FileStream(@"SD" + strReadFile + ".txt", FileMode.Open)) { string strSendLine; StreamReader sr = new StreamReader(filestream); while ((strSendLine = sr.ReadLine()) != null) { counterDataArray.Add(strSendLine); } sr.Close(); sr.Dispose(); } Debug.Print("send data from array"); httpSendData(); } public static void httpSendData() { foreach (string value in counterDataArray) { HTTP_Client.HTTP_Response Response = WebSession.Get("/helloworld/"); Debug.Print("value: " + value); Debug.GC(true); } cleanUp(); } public static void cleanUp() { if (strWriteFile == "dataone") { strWriteFile = "datatwo"; strReadFile = "dataone"; } else { strWriteFile = "dataone"; strReadFile = "datatwo"; } counterDataArray.Clear(); Debug.Print("Free Memory: " + Debug.GC(true).ToString()); Debug.Print("Record count: " + intCounter); Debug.GC(true); populateArray(); } public static void connectToWifi() { WifiModule = new WiFlyGSX(); WifiModule.EnableDHCP(); WifiModule.JoinNetwork(strSSID, 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, strPassword); Thread.Sleep(3500); // Showing some interesting output Debug.Print("Local IP: " + WifiModule.LocalIP); Debug.Print("MAC address: " + WifiModule.MacAddress); SNTP_Client TimeClient = new SNTP_Client(new WiFlySocket("ntp2.is.co.za", 123, WifiModule)); Thread.Sleep(1000); TimeClient.Synchronize(); Debug.Print("DateTime.Now: " + DateTime.Now.AddHours(2)); Socket = new WiFlySocket(strRemoteHost, 80, WifiModule); WebSession = new HTTP_Client(Socket); populateArray(); } }} #43868 Memory leak
Hi skobyjay,
Thanks for the suggestion...
I have moved the socket and websession out of the "send" routine and only create them once now when I first connect to the wifi network. This has helped reduce the memory leak per loop to just 684 bytes.
The problem is that something is still taking up memory which will mean the device cannot run all day as we'd like it to without a restart.
Further to that the HTTP request is very slow and the Netduino takes between 1-2 seconds to process the request. This means that we'll not be able to cycle all the requests fast enough when the count tally could be increasing by 1 a second.
The average querystring looks like this: deviceID=1&count=6&dateTimeStamp=12/7/2012%2013:31:34
I have to be able to get the FTP working over the wifi so that I can upload a text file with the querystrings in it and then have the server handle the processing. It's too much for the Netduino to do. It would be fine if the sensor was only collecting data every minute or so, but with it collecting a count every second it's going to overwhelm the Netduino. #41421 Wifi timeout
Hi Stefan,
So it seems the reason it never timed out last night was because I'd forgotten to include the HTTP request; so it was just connecting to the socket, closing that connection and then re-opening it again in a loop... no chance of that timing out ![]() This morning I have added in the HTTP request and setup a catch for the timeout and it's working well. The application loops through and sends the querystring to my aspx page, which then adds a record to my database. To simulate the counter I have just created a variable called intCount which increases by 1 after each successful HTTP request. When a timeout occurs it is caught by the "catch" and the wifi module is reset and it attempts the HTTP request again. It does this successfully but then freezes on "socket.connect()" the next time around. I thought maybe it was something to do with the N+2 running out of memory (because of the loop running in the background while the wifi reset is happening) but that doesn't seem to be the case. Any ideas? Here's the code: using System; using System.Collections; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using Toolbox.NETMF; using Toolbox.NETMF.NET; using Toolbox.NETMF.Hardware; using VariableLabs.PowerManagment; namespace liveCountBeta003 { public class Program { public static string strSSID = "mySSID"; public static string strPassword = "myPassword"; public static string strSocketHostname = "my.url.com"; public static uint intCount = 0; const int updateInterval = 3000; static WiFlyGSX WifiModule; static SimpleSocket socket; static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); public static void Main() { //Turn off the Ethernet controller Debug.Print("Turn off the Ethernet controller"); PowerManagment.SetPeripheralState(Peripheral.Ethernet, false); //Connect to wifi network Debug.Print("connect to Wifi"); connectToWifi(); while (true) { delayLoop(updateInterval); updateDatabase("deviceID=6640&count=" + intCount); } } static void updateDatabase(string tsData) { Debug.Print("start updateDatabase - freemem: " + Debug.GC(true) + "\n"); led.Write(true); String request = "GET /default.aspx?" + tsData + " HTTP/1.1\r\n"; request += "Host: " + strSocketHostname + "\r\n"; request += "Connection: Close\r\n"; request += "\r\n"; sendHTTP_Request(request); led.Write(false); } private static void sendHTTP_Request(String request) { try { socket = new WiFlySocket(strSocketHostname, 80, WifiModule); Debug.Print("IsConnected: " + socket.IsConnected); Debug.Print("socket connect"); socket.Connect(); while (socket.IsConnected) { Debug.Print("Send request: " + intCount); socket.Send(request); Debug.Print("close socket"); socket.Close(); Debug.Print("increase counter by 1"); intCount++; Debug.Print("send complete\n"); } } catch (System.ApplicationException e) { Debug.Print("************************************************************"); Debug.Print("Code: " + e); Debug.Print("************************************************************"); Debug.Print("reset wifi and reconnect"); WifiModule.Dispose(); connectToWifi(); Debug.Print("try socket connect - after reconnecting wifi"); socket = new WiFlySocket(strSocketHostname, 80, WifiModule); socket.Connect(); while (socket.IsConnected) { Debug.Print("Send request: " + intCount); socket.Send(request); Debug.Print("close socket"); socket.Close(); Debug.Print("increase counter by 1"); intCount++; Debug.Print("send complete\n"); } } Debug.Print("leave sendHTTP_Request()\n"); } public static void connectToWifi() { try { Debug.Print("Create new instance"); WifiModule = new WiFlyGSX(); // wait for wifly to start Thread.Sleep(4000); Debug.Print("EnableDHCP"); WifiModule.EnableDHCP(); Debug.Print("Join network"); WifiModule.JoinNetwork(strSSID, 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, strPassword); // wait for DHCP Thread.Sleep(2500); // Get the Local IP to confirm connection to the wifi network string strLocalIP; strLocalIP = WifiModule.LocalIP; Debug.Print("wifi connected; IP address: " + strLocalIP); Thread.Sleep(1500); } catch (System.InvalidOperationException e) { Debug.Print("System.InvalidOperationException: " + e.StackTrace.ToString()); } catch { Debug.Print("can't access wifi"); } } static void delayLoop(int interval) { long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; int offset = (int)(now % interval); int delay = interval - offset; Thread.Sleep(delay); } } } Here's the Debug output before and after the timeout:
Thanks, Donovan #41302 Wifi timeout
Hi Chuck,
Thanks for the response. I'll take a look and post my feedback.
Is this a problem with the RN-XV module or the wiflyGSX.dll that requires a power reset when it times out?
Thanks,
Donovan
#41175 Wifi timeout
Hi Chris ,
It's hooked up via the Wifi sheild. ![]() Is there a way to cycle the power to the wifly without having to physically use the switch? Is there really no other way to reset the wifly once it hangs? Thanks, Donovan #41143 Wifi timeout
Hi there,
I am creating a data logger which uses a photo sensor, a Sparkfun RN-XV WifiModule and a netduino Plus 2. Basically what happens is that when the photo sensor is interrupted it initiates an HTTP Post to a server which then logs the activity to a database via a querystring. The problem I am having is that if there is a connection timeout the WifiModule simply locks up and I don't know how to reset it to try the request again. To try and solve this timeout issue I modified an example from ThingSpeak.com; without the photo sensor and created a loop which sends the HTTP request. I can sometimes send 100 requests without a timeout and then sometimes only about 20... either way once the connection times out the whole application stops. How should I handle the timeout and how do I reset the WifiModule to try again? using System; using System.Collections; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using Toolbox.NETMF; using Toolbox.NETMF.NET; using Toolbox.NETMF.Hardware; namespace timeoutTest { public class Program { const int updateInterval = 3000; static WiFlyGSX WifiModule; static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); public static void Main() { WifiModule = new WiFlyGSX(); // wait for wifly to start Thread.Sleep(2000); WifiModule.EnableDHCP(); WifiModule.JoinNetwork("mySSID", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "myPassword"); // Get the Local IP to confirm connection to the wifi network string strLocalIP; strLocalIP = WifiModule.LocalIP; Debug.Print(strLocalIP); while (true) { delayLoop(updateInterval); updateThingSpeak("variable=664"); } } static void updateThingSpeak(string tsData) { Debug.Print("Connecting to server...\n"); led.Write(true); String request = "POST /default.aspx?" + tsData + " HTTP/1.1\n"; request += "Host: some.hostname.here.com\n"; request += "Connection: Close\n"; request += "Content-Type: application/x-www-form-urlencoded\n"; request += "Content-Length: " + tsData.Length + "\n\n"; Debug.Print(request); try { String tsReply = sendPOST(request); Debug.Print(tsReply); Debug.Print("...disconnected.\n"); led.Write(false); } catch (SocketException se) { Debug.Print("Connection Failed.\n"); Debug.Print("Socket Error Code: " + se.ErrorCode.ToString()); Debug.Print(se.ToString()); Debug.Print("\n"); led.Write(false); } } private static String sendPOST(String request) { SimpleSocket serverSocket = ConnectSocket(); while(serverSocket.IsConnected) { serverSocket.Send(request); } Byte[] buffer = new Byte[1024]; String page = String.Empty; page = page + new String(Encoding.UTF8.GetChars(buffer)); return page; } private static SimpleSocket ConnectSocket() { SimpleSocket socket = new WiFlySocket("some.hostname.here.com", 80, WifiModule); try { socket.Connect(); } catch (System.ApplicationException e) { Debug.Print("Code: " + e); ConnectSocket(); } return socket; } static void delayLoop(int interval) { long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; int offset = (int)(now % interval); int delay = interval - offset; Thread.Sleep(delay); } } } Thanks, Donovan #41313 Wifi timeout
Hi Stefan,
I've replaced "Toolbox.NETMF.Hardware.WiFlyGSX.dll" with the latest downloaded version and now my application won't deploy. I just took the new one from the zip file and overwrote the old one; is that the wrong way to do it? All I get is this and then the "output" window closes and the debug stops running:
Thanks, Donovan #41394 Wifi timeout
Hi Stefan, Now that I can compile again I made these changes and my little application has not timed out. I have been running it for about an hour now and it's not frozen. I will run more tests in the morning and then tidy up the code and post for others. Thank you very much for your help ![]() Cheers, Donovan #41478 Wifi timeout
Have just upgraded my Firmware from 4.2.0.3 to 4.2.1.1 and it hasn't helped
![]() Long shot I know... but I thought worth a try ![]() #41473 Wifi timeout
Hi guys,
Does anyone have any ideas about why the wifly module would hang after a timeout?
I've tried restarting the module after the timeout as well as calling the send request from an array, instead of the loop, and none of it seems to help.
Today the application gets to the timeout, restarts the wifi and then does about another two sends before it hangs at the socket.connect...
...so I'm not sure what to try next??
Thanks,
Donovan
#41529 Wifi timeout
Ok... so still no luck with this. Here's what else I have tried:
I put a try/catch around the "socket.connect()" in the hopes of finding out what's tripping it up. socket = new WiFlySocket(strSocketHostname, 80, WifiModule); Debug.Print("socket connect"); try { socket.Connect(); } catch (System.ApplicationException errorCode) { Debug.Print("Socket connect error: " + errorCode); } The first time around it reveals a timeout as the problem:
The very next time it simply hangs at the connect, even the try/catch doesn't help:
Am I missing something obvious or is there a problem with the Toolbox.NETMF.Hardware.WiFlyGSX.dll and it's locking the shield after a timeout? I have tried resetting the wifly shield by power cycling it(using Arron Chapman's PowerManagement.cs) and re-joining the wifi network but it still hangs on the next socket.connect(). I create a new socket each time (socket = new WiFlySocket(strSocketHostname, 80, WifiModule);) as well so surely that should reset it after a timeout? Any suggestions? Thanks, Donovan
| ||||||||||||||
![]() |
||||||||||||||
![]() |
|
![]() |
||||||||||||
![]() |
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ![]() |
||||||||||||
![]() |