Netduino home hardware projects downloads community

Jump to content


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 Content

There have been 77 items by don664 (Search limited from 28-April 23)


By content type

See this member's


Sort by                Order  

#43086 Wifi timeout

Posted by don664 on 09 January 2013 - 06:56 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi guys,

 

Thanks for the advice.

 

After splitting into various threads (like one for connecting to the wifi and another for handling the data send), as well as now using the Toolbox.HTTP_Client reference, I seem to have resolved a timeout causing the Netduino/wifly module to hang  :D

 

I have been able to run a test with over 700 HTTP Get requests and although there were a number of timeouts none of them caused the Netduino to hang/crash!!

 

Only problem I have now though is that I run out of memory... and I can't understand why, but I think that's for another thread!

 

Please find my code below (please ignore all the "Debug.GC(true);" lines as it's part of my efforts to figure out the memory issue) , I hope it helps someone else. Thanks to everyone for their input!!

 

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;namespace testToolbox21240{    public class Program    {        static uint intCounter = 0;        static uint intTimeoutCounter = 0;        static WiFlyGSX WifiModule;        static string strWriteFile = "dataone";        static string strReadFile = "datatwo";        static ArrayList counterDataArray = new ArrayList();        public static void Main()        {            connectToWifi();            populateArray();            //httpSendData();                                    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.GC(true);            }            Debug.Print("send data from array");                        foreach (string value in counterDataArray)            {                httpSendData(value);                Debug.EnableGCMessages(true);            }                        counterDataArray.Clear();            Debug.GC(true);            cleanUp();                    }        public static void cleanUp()        {            if (strWriteFile == "dataone")            {                strWriteFile = "datatwo";                strReadFile = "dataone";            }            else            {                strWriteFile = "dataone";                strReadFile = "datatwo";            }            Debug.GC(true);            Debug.Print("Free Memory: " + Debug.GC(true).ToString());            Debug.Print("Record count: " + intCounter);            Debug.GC(true);            populateArray();        }        public static void connectToWifi()        {            //SimpleSocket Socket = new WiFlySocket("myURL.com", 80, WifiModule);            //httpSendData(Socket);            WifiModule = new WiFlyGSX();            WifiModule.EnableDHCP();            WifiModule.JoinNetwork("mySSID", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "myPassword");            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);            Debug.GC(true);        }        public static void httpSendData(string queryStringData)        {                        SimpleSocket Socket = new WiFlySocket("myURL.com", 80, WifiModule);            HTTP_Client WebSession = new HTTP_Client(Socket);            try            {                HTTP_Client.HTTP_Response Response = WebSession.Get("/default.aspx?" + queryStringData);                // Fetches a response header                Debug.Print("value: " + queryStringData);                Debug.GC(true);            }            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();                    Debug.GC(true);                }                Thread.Sleep(1500);                Debug.GC(true);                httpSendData(queryStringData);               }            finally            {                Socket.Close();                //intCounter++;                Debug.GC(true);            }                     }    }}



#42964 Wifi timeout

Posted by don664 on 08 January 2013 - 11:56 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi Eric,

 

Thanks for the sample... I will work with it later and let you know what I am able to come up with.




#42963 Wifi timeout

Posted by don664 on 08 January 2013 - 11:55 AM in Netduino Plus 2 (and Netduino Plus 1)

If interested, I can send you a copy of that excellent post...

 

Yes please  :D




#42910 Wifi timeout

Posted by don664 on 07 January 2013 - 04:04 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi guys,

 

Compliments of the season to you and I hope you all had a relaxing festive break; all the best for 2013!

 

First day back in the office today and I saw that there was a new release of the .NET Micro Framework Toolbox (21240). I downloaded it and created a new project to see if the newly compiled toolbox would help me get around the timeout problem I was having.

 

Excitedly I noticed a new reference (Toolbox.NETMF.NET.HTTP_Client) which I thought may be the answer I was looking for... and it turns out that the new reference seems to make all the difference!

 

The new reference seems to be able to successfully handle a caught timeout and then process the HTTP request again. I will post my code below. the only issue I now have is that after numerous timeouts I finally get the following: WARNING: TOO MANY NESTED EXCEPTIONS!!

 

 

 

Current date according to server: Mon, 07 Jan 2013 15:51:08 GMT
intCounter: 284
Current date according to server: Mon, 07 Jan 2013 15:51:11 GMT
intCounter: 285
WARNING: TOO MANY NESTED EXCEPTIONS!!
A first chance exception of type 'System.ApplicationException' occurred in Toolbox.NETMF.Hardware.WiFlyGSX.dll
An unhandled exception of type 'System.ApplicationException' occurred in Toolbox.NETMF.Hardware.WiFlyGSX.dll
 
Additional information: Connection timed out

 

 

Has anyone else come across this? I'm not sure it is going to be an issue though as in my main project there won't be an infinite loop like there is in this test project. So I don't imagine there will be that many nested exceptions...

 

using System;using System.Net;using System.Net.Sockets;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;namespace testToolbox21240{    public class Program    {        static uint intCounter = 0;        static WiFlyGSX WifiModule;        public static void Main()        {            WifiModule = new WiFlyGSX();            WifiModule.EnableDHCP();            WifiModule.JoinNetwork("mySSID", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "myPassword");            Thread.Sleep(2500);            // 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));            TimeClient.Synchronize();            Debug.Print("DateTime.Now: " + DateTime.Now.AddHours(2));            httpSendData();            Thread.Sleep(Timeout.Infinite);        }        public static void httpSendData()        {            SimpleSocket Socket = new WiFlySocket("myServer.com", 80, WifiModule);            HTTP_Client WebSession = new HTTP_Client(Socket);            while (true)            {                try                {                    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());                    HTTP_Client.HTTP_Response Response = WebSession.Get("/default.aspx?deviceID=123&count=" + intCounter + "&dateTimeStamp=" + strDateTime);                    // Did we get the expected response? (a "200 OK")                    if (Response.ResponseCode != 200)                        throw new ApplicationException("Unexpected HTTP response code: " + Response.ResponseCode.ToString());                    // Fetches a response header                    Debug.Print("Current date according to server: " + Response.ResponseHeader("date"));                    Debug.Print("intCounter: " + intCounter);                }                catch (System.ApplicationException e)                {                    Debug.Print("Error Code: " + e);                    Thread.Sleep(2000);                    Debug.Print("Go back to start");                    httpSendData();                }                intCounter++;            }        }    }}

 

 

Anyway, I'll keep you posted on this new "timeout" issue once I have had a chance to integrate the new reference (Toolbox.NETMF.NET.HTTP_Client) into my main project.

 

Thanks,

Donovan




#41540 Wifi timeout

Posted by don664 on 14 December 2012 - 08:51 AM in Netduino Plus 2 (and Netduino Plus 1)

...going to see if there is a firmware update for the RN-XV and will let you know if that helps

UPDATE: Have upgraded firmware to "WiFly Ver 2.38, 12-11-2012 on RN-171" and still no luck...



#41538 Wifi timeout

Posted by don664 on 14 December 2012 - 08:48 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi guys,

Thanks for taking a look...

I thought maybe it was my wifi network and have tried on a different network and it runs perfectly until the first timeout then can't connect to the socket again.

All I end up with is the little green LED (D1) blinking on the RN-XV and the PWR red LED blinking on the wifi shield.

:(



#41529 Wifi timeout

Posted by don664 on 14 December 2012 - 06:06 AM in Netduino Plus 2 (and Netduino Plus 1)

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:

Debug Output:

socket connect
A first chance exception of type 'System.ApplicationException' occurred in Toolbox.NETMF.Hardware.WiFlyGSX.dll
Socket connect error: System.ApplicationException: Connection timed out


The very next time it simply hangs at the connect, even the try/catch doesn't help:

Debug Output:

socket connect

....then nothing


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



#41478 Wifi timeout

Posted by don664 on 13 December 2012 - 02:53 PM in Netduino Plus 2 (and Netduino Plus 1)

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

Posted by don664 on 13 December 2012 - 01:51 PM in Netduino Plus 2 (and Netduino Plus 1)

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



#41421 Wifi timeout

Posted by don664 on 12 December 2012 - 08:17 AM in Netduino Plus 2 (and Netduino Plus 1)

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:

start updateDatabase - freemem: 104640

IsConnected: False
socket connect
Send request: 115
close socket
increase counter by 1
send complete

leave sendHTTP_Request()

start updateDatabase - freemem: 104640

IsConnected: False
socket connect
A first chance exception of type 'System.ApplicationException' occurred in Toolbox.NETMF.Hardware.WiFlyGSX.dll
************************************************************
Code: System.ApplicationException: Connection timed out
************************************************************
reset wifi and reconnect
Create new instance
EnableDHCP
Join network
wifi connected; IP address: 192.168.0.9
try socket connect - after reconnecting wifi
Send request: 116
close socket
increase counter by 1
send complete

leave sendHTTP_Request()

start updateDatabase - freemem: 100596

IsConnected: False
socket connect

*** it just hangs here now ***


Thanks,
Donovan



#41394 Wifi timeout

Posted by don664 on 11 December 2012 - 04:55 PM in Netduino Plus 2 (and Netduino Plus 1)

I don't know why you use:

public static WiFlyGSX connectToWifi()
private static SimpleSocket ConnectSocket()
Instead of:
public static void connectToWifi()
private static void ConnectSocket()

Since it's not the right type for normal code.

Do you currently get an error message by the way?


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 :D

Cheers,
Donovan



#41390 Wifi timeout

Posted by don664 on 11 December 2012 - 03:26 PM in Netduino Plus 2 (and Netduino Plus 1)

...ok, so it seems to have something to do with these assemblies being compiled for 4.1 or 4.2 I have gone back to using "Toolbox.NETMF.Hardware.WiFlyGSX.dll" from "Toolbox-17446" and it's compiling again. Is there an error in the "Toolbox-20618" release?



#41388 Wifi timeout

Posted by don664 on 11 December 2012 - 02:31 PM in Netduino Plus 2 (and Netduino Plus 1)

I can't find a WiFlyGSX.cs file in the netmftoolbox-20618 zip. I have re-installed both MicroFrameworkSDK_NETMF42_QFE2 and netduinosdk_32bit_NETMF42 wiothout any success. This issue started yesterday when I copied "\Toolbox-20618\Release (4.2)\Toolbox.NETMF.Hardware.WiFlyGSX.dll" from the zip over the existing Toolbox.NETMF.Hardware.WiFlyGSX.dll I was using. Stefan, you suggested in another post (http://forums.netdui...error-a3000000/) to delete the OBJ and BIN folders and I have deleted those from my project and still it won't work. Do I need to uninstall Visual C# 2010 Express and start again?



#41366 Wifi timeout

Posted by don664 on 11 December 2012 - 07:04 AM in Netduino Plus 2 (and Netduino Plus 1)

Now I'm back to this error when trying to debug :(

Link failure: some assembly references cannot be resolved!!


Assembly: Toolbox.NETMF (0.1.0.0) needs assembly 'mscorlib' (4.1.2821.0)

Assembly: Toolbox.NETMF (0.1.0.0) needs assembly 'Microsoft.SPOT.Hardware' (4.1.2821.0)

Assembly: wiflyTimeout (1.0.0.0) needs assembly 'Toolbox.NETMF.Hardware.WiFlyGSX' (1.0.0.0)

Assembly: wiflyTimeout (1.0.0.0) needs assembly 'Toolbox.NETMF.NET' (1.0.0.0)

Assembly: Toolbox.NETMF.Hardware.WiFlyGSX (1.0.0.0) needs assembly 'Toolbox.NETMF.NET' (1.0.0.0)

Assembly: Toolbox.NETMF.Hardware.WiFlyGSX (1.0.0.0) needs assembly 'Toolbox.NETMF' (0.1.0.0)

Assembly: Toolbox.NETMF.NET (1.0.0.0) needs assembly 'Toolbox.NETMF' (0.1.0.0)

Error: a3000000

Waiting for debug commands...

The program '[1] Micro Framework application: Managed' has exited with code 0 (0x0).


Where have those assemblies gone?



#41330 Wifi timeout

Posted by don664 on 10 December 2012 - 07:11 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi Stefan, Still a newbie so bound to mix some things up ;-) Thanks for taking a look, I'll make those amends in the morning and try again. As always thanks for the help! Donovan



#41316 Wifi timeout

Posted by don664 on 10 December 2012 - 02:04 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi guys,

I'm still working with the power management and even after "restarting" the wifly shield it's still unable to connect to the socket again.

It has no problem rejoining the wifi network but something is stopping it from connecting to the socket, is this something to do with a TX port or something on the N+2 itself... so even though the wifly has restarted it's the board that's hung up?


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 = "myURL.com";
        
        const int updateInterval = 3000; 

        static WiFlyGSX WifiModule;

        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        public static void Main()
        {            
            Debug.Print("Turn off the Ethernet controller");
            //Turn off the Ethernet controller
            PowerManagment.SetPeripheralState(Peripheral.Ethernet, false);

            connectToWifi();
            
            while (true)
            {
                delayLoop(updateInterval);
                updateThingSpeak("deviceID=22664");                
            }
        }

        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: " + strSocketHostname + "\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);
                connectToWifi();
                ConnectSocket();
                String tsReply = sendPOST(request);
                Debug.Print(tsReply);
                Debug.Print("...disconnected.\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;
        }

        public static WiFlyGSX connectToWifi()
        {
            try
            {
                //Turn off the wifly sheild
                Debug.Print("Turn off the wifly sheild");
                PowerManagment.SetPeripheralState(Peripheral.PowerHeaders, false);
                Debug.Print("waiting..");

                Thread.Sleep(10000);

                //Turn on the wifly sheild
                Debug.Print("Turn on the wifly sheild");
                PowerManagment.SetPeripheralState(Peripheral.PowerHeaders, true);
                // wait for power cycle to complete
                Thread.Sleep(6500);

                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);
            }

            catch (System.InvalidOperationException e)
            
            {
                Debug.Print("System.InvalidOperationException: " + e.StackTrace.ToString());
            }
            catch
            {
                Debug.Print("can't access wifi");
            }

            return WifiModule;
        }

        private static SimpleSocket ConnectSocket()
        {
            SimpleSocket socket = new WiFlySocket(strSocketHostname, 80, WifiModule);
            try
            {
                socket.Connect();
            }
            catch (System.ApplicationException e)
            {
                Debug.Print("************************************************************");
                Debug.Print("Code: " + e);
                Debug.Print("************************************************************");

                Debug.Print("module dispose");
                WifiModule.Dispose();
                if (socket.IsConnected)
                {
                    Debug.Print("close socket");
                    socket.Close();
                }
                Debug.Print("connect to wifi()");
                connectToWifi();
                Debug.Print("socketConnect()");
                socket.Connect();
            }
            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);
        }
    }
}



Any ideas?

Thanks,
Donovan



#41315 Wifi timeout

Posted by don664 on 10 December 2012 - 01:14 PM in Netduino Plus 2 (and Netduino Plus 1)

I think I'm going to start again... ...will let you know how it goes :)



#41313 Wifi timeout

Posted by don664 on 10 December 2012 - 12:31 PM in Netduino Plus 2 (and Netduino Plus 1)

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:

Assembly: wiflyTimeout (1.0.0.0) needs assembly 'Toolbox.NETMF.NET' (1.0.0.0)

Assembly: Toolbox.NETMF.Hardware.WiFlyGSX (1.0.0.0) needs assembly 'Toolbox.NETMF.NET' (1.0.0.0)

Assembly: Toolbox.NETMF.Hardware.WiFlyGSX (1.0.0.0) needs assembly 'Toolbox.NETMF' (0.1.0.0)

Assembly: Toolbox.NETMF.NET (1.0.0.0) needs assembly 'Toolbox.NETMF' (0.1.0.0)

Error: a3000000

Waiting for debug commands...

The program '[4] Micro Framework application: Managed' has exited with code 0 (0x0).


Thanks,
Donovan



#41302 Wifi timeout

Posted by don664 on 10 December 2012 - 05:34 AM in Netduino Plus 2 (and Netduino Plus 1)

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

Posted by don664 on 07 December 2012 - 07:38 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi Chris ,

It's hooked up via the Wifi sheild.

Posted Image

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

Posted by don664 on 07 December 2012 - 02:42 PM in Netduino Plus 2 (and Netduino Plus 1)

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



#41030 HttpWebRequest GetResponse Error

Posted by don664 on 05 December 2012 - 03:14 PM in General Discussion

Thanks Stefan ;)



#41016 HttpWebRequest GetResponse Error

Posted by don664 on 05 December 2012 - 09:17 AM in General Discussion

Thanks Stefan... and which namespace is HttpClient in?



#41007 HttpWebRequest GetResponse Error

Posted by don664 on 05 December 2012 - 07:39 AM in General Discussion

Hi guys,

How would I check for "GetResponse" when using SimpleSocket for WiFly?


SimpleSocket Socket = new WiFlySocket("www.someSite.com", 80, WifiModule);

Socket.Connect();

Socket.Send("GET /default.aspx?var=something HTTP/1.1\r\n");
Socket.Send("Host: " + Socket.Hostname + "\r\n");
Socket.Send("Connection: Close\r\n");
Socket.Send("\r\n");

if(Socket.ResponseCode != 200)
{
  Debug.Print("Error:" + Socket.ResponseCode);
} 

Socket.Close();


Thanks,
Donovan



#40291 RN-XV WiFly Module driver

Posted by don664 on 27 November 2012 - 08:21 AM in Project Showcase

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




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.