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.
Photo

Changes to netmftoolbox


  • Please log in to reply
18 replies to this topic

#1 Bussibaer

Bussibaer

    New Member

  • Members
  • Pip
  • 3 posts

Posted 29 June 2012 - 02:04 PM

Hi,

I couldn't figure out how the patches work on codeplex so I post this here.

I'm using a RN-XV WiFly module 2.32 to connect to my WiFi and issue a request to my web server every few seconds. I used the .NET Micro Framework Toolbox for that, but I had some minor problems. Most of them are fixed and now I wanted to share my changes with you in order that they'll get included in the Toolbox.

1) WiFlyGSX._CommandMode_Start() hangs
At the end of that method is a while loop which waits until command mode was entered. Unfortunately there is no timeout like in OpenSocket, so if this._Mode is not changed, then it waits forever.
I found the problem when I enabled DebugMode. When the program hung, then the last lines in the debug window were:
O: $$$
I: <2.32> CMD\r\n
I.e. sometimes my WiFly responds to the $$$ to enter the command mode with "<2.32> CMD\r\n" instead of just "CMD".
I could fix this in _SerialPort_LineReceived(). I changed
if (Text == "CMD" && this._Mode == Modes.Idle)
to
if (this._Mode == Modes.Idle && Text.IndexOf("CMD") > -1)

2) HTTP_Client.HTTP_Response.ResponseBody starts with "\r\n\r\n"
These are actually the line feeds to seperate the HTTP headers from the body and should not be part of the body. I changed the HTTP_Response constructor to this:
            public HTTP_Response(string ResponseData)
            {
                // First, find the point that breaks between headers and content
                int BreakPoint = ResponseData.IndexOf("\r\n\r\n");
                if (BreakPoint > -1)
                {
                    this._ResponseBody = ResponseData.Substring(BreakPoint + 4);
                }
                else
                {
                    BreakPoint = ResponseData.IndexOf("\n\n");
                    // Lets set the response apart
                    if (BreakPoint > -1)
                        this._ResponseBody = ResponseData.Substring(BreakPoint + 2);
                    else
                        BreakPoint = ResponseData.Length;   // no response body found -> take all as headers
                }

                // The headers remain
                this._Headers = ResponseData.Substring(0, BreakPoint).Split('\n');
                // The first header also contains the ResponseCode
                if (this._Headers.Length > 0)
                {
                    string[] Parts = this._Headers[0].Split(' ');
                    this._ResponseCode = int.Parse(Parts[1]);
                }
            }
This also does the work of Parse_Header(). This method mainly copied arrays which is actually not needed. The method can be removed now.

3) ResponseBody sometimes ends with "*CLOS*"
I didn't fix this yet. It should be somewhere in WiFlyGSX._SerialPort_DataReceived but I don't know when this happens exactly.

4) Timeout in WiFlyGSX.OpenSocket
Sometimes the socket does not get connected. But I also did not find this issue yet. As it is only on program start and not in subsequent requests, I guess something was not initialized properly.

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 29 June 2012 - 03:04 PM

1) 2) Thanks, I made a ticket about it (http://netmftoolbox....om/workitem/735), when I have time, I'll put them in. I'll mention your name in the changelog. I really appreciate the work you put into it! 3) I knew about, it's also commented in my code. A solution is difficult since *CLOS* could also be something else; it's a configurable variable. 4) If you have repro code, it would be most welcome!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 04 July 2012 - 04:52 PM

First of all, sorry for the late reply. Some private obligations were keeping me occupied from working on this in the past few weeks.

I implemented your fixes into the .NETMF Toolbox, see http://netmftoolbox....t/changes/16256 for more.

To get more in detail;

1) WiFlyGSX._CommandMode_Start() hangs
At the end of that method is a while loop which waits until command mode was entered. Unfortunately there is no timeout like in OpenSocket, so if this._Mode is not changed, then it waits forever.
I found the problem when I enabled DebugMode.

I.e. sometimes my WiFly responds to the $$$ to enter the command mode with "<2.32> CMD\r\n" instead of just "CMD".


I never had this issue myself, but I could read and understand your fix. I just implemented it, hoping it will work for everyone now.

2) HTTP_Client.HTTP_Response.ResponseBody starts with "\r\n\r\n"
These are actually the line feeds to seperate the HTTP headers from the body and should not be part of the body.


Good one, I've got this fixed.

This also does the work of Parse_Header(). This method mainly copied arrays which is actually not needed. The method can be removed now.


Ohh that's funny! To explain how that came into existence; I ported this from a way bigger HTTP library I wrote for PHP once. It had way more header checks. Since this is made for a compact framework, I didn't include all those checks. You made it even more compact. Thanks for that!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 19 November 2012 - 12:29 AM

hey I am using that same module and have issues with repeated requests. On the second or third request the response is ended with that same *CLOS* and then it get stuck on this line on the next request waiting for a response:
HTTP_Client.HTTP_Response Response = WebClient.Get("/wifiget.asp");

I cant figure out what the issue is, any guesses? Where does that *CLOS* come from?
James

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 November 2012 - 06:45 AM

I cant figure out what the issue is, any guesses? Where does that *CLOS* come from?

It's the socket termination signal of the wifi module, which isn't filtered out properly because *CLOS* is sent over multiple packets sometimes.
It shouldn't block the request though, that's a bit odd. I have planned some changes in these classes for this week, so maybe it'll fix this. Please stay tuned!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 19 November 2012 - 06:13 PM

what would be the best way to keep the socket open? or should I always open a new one for each request?

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 November 2012 - 08:22 PM

what would be the best way to keep the socket open? or should I always open a new one for each request?

for http? I would recommend to use a single socket for each request.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 21 November 2012 - 08:56 PM

yeah i can only make a few requests before i get the *CLOS* and am blocked. I have tried using a single socket and creating a new one for each request, but either way it still gets blocked. Any guesses? did it work for you making repeated requests?

#9 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 28 November 2012 - 04:00 PM

any updates here?

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 28 November 2012 - 04:05 PM

Not yet, I just didn't found the time yet to work on this :( it's not my job but my hobby to work on these things. I wish I had more hobby time ;)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 09 December 2012 - 11:56 PM

Yeah, just a hobby for me too, but one that I spend a great deal of time thinking about and working on. I wish my 9-5 was this entertaining :)

Maybe you could just help me understand what is going on and I can figure a way through it. From what I can tell I make a few requests and one of them ends up coming back with the additional *CLOS* at the end. When that happens, I can tell the RN-XV has gone into a weird state because suddenly the 01 LED on the RN-XV starts flashing rapidly. After that starts any requests to the WebClient get blocked and will wait but never return.

WebClient.Get("/wifiget.asp","iteration=" + requestCount.ToString());//this is where it freezes


I have even tried looking for that *CLOS* and attempting to open a new socket when that happens but even though i see it and start the new socket it still gets stuck in the same place

if (Response.ResponseBody.IndexOf("*CLOS*") > 0)
                {
                    socket.Close();

                    WifiModule.OpenSocket("www.signalvehicle.com", 80);

                    Debug.Print("get new socket");
                    socket = new WiFlySocket("www.signalvehicle.com", 80, WifiModule);
                    WebClient = new HTTP_Client(socket);
                }


I am not sure what to even try next. Your code makes sense and seems right so I don't want to have to scrap it and start from scratch. I cant tell whats actually going wrong here.

#12 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 December 2012 - 08:49 AM

Hi contractorwolf, Yesterday I actually fixed a blocking issue. When did you download the class for the last time?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#13 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 10 December 2012 - 02:37 PM

Yeah, I just found and started using your 4.2 code, looked at the framework code and made a project with the framework code in it so that I could debug all the way through. Seems to work better but I still eventually hit another issue, blocks at 200 requests instead of 6, so way better. I will update you when I have dug in a little more. I turned the "debugging" section of your code on so that I can see a lot more of whats happening. I wonder if that causes me to run out of space or something since it is so verbose? Ill update you when I have more. Is there a later version of the code then the 4.2 version of the framework or a specific project that I should be using from it?

#14 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 10 December 2012 - 02:40 PM

FYI, I am making a webclient request (against my own server) every 15 seconds. The requests themselves are very small, just like 20 characters each way

#15 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 December 2012 - 04:50 PM

Is there a later version of the code then the 4.2 version of the framework or a specific project that I should be using from it?

The latest version is just in the zip file currently, which you can download at http://netmftoolbox....list/changesets
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#16 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 10 December 2012 - 07:26 PM

hmm, now I get the following in the debug data:
I: *
D: Left streaming mode
1015 -- 06/01/2011 04:37:07: this is a test*CLOS*
make request
O: $$$
I: <2.32> CMD\r\n
D: Successfully enterred the command mode
O: open www.signalvehicle.com 80\r
I: open www.signalvehicle.com 80\r\r\n
I: Connect to 66.165.151.90:80\r\n
D: Enterred streaming mode
O: GET /wifiget.asp?iteration=1016 HTTP/1.1\r\nAccept: */*\r\nAccept-Language: en\r\nReferer: http://www.signalvehicle.com/wifiget.asp?iteration=1015\r\nUser-Agent: NETMFToolbox/0.1 (textmode; NetduinoGo; WiFlySocket; HTTP_Client)\r\nHost: www.signalvehicle.com\r\nCookie: ASPSESSIONIDSQCATQTD=KKELDECDLDGHEOFGCFCOMMJH\r\nConnection: Close\r\n\r\n
I: HTTP/1.1 200 OK\r\n
I: Ser
I: v
I: e
I: r
I: :
I:
I: M
I: i
I: crosoft-IIS/5.0\r\nD
I: ate
I: :
I:
I: M
I: o
I: n
I: ,
I: 10 Dec 2012 18:16
I: :01
I:
I: G
I: M
I: T
I: \r
I: \n
I: MicrosoftOfficeWeb
I: Ser
I: v
I: e
I: r
I: :
I:
I: 5
I: .
I: 0
I: _
I: P
I: u
I: b
I: \r
I: \n
I: X-Powered-By: ASP.
I: NET
I: \r
I: \n
I: C
I: o
I: n
I: n
I: ection: close\r\nCon
I: ten
I: t
I: -
I: L
I: e
I: n
I: g
I: th: 14\r\nContent-Ty
I: pe:
I:
I: t
I: e
I: x
I: t
I: /
I: h
I: tml\r\nCache-control
I: : p
I: r
I: i
I: v
I: a
I: t
I: e
I: \r\n\r\nthis is a test
I: *CL
I: O
I: S
I: *
D: Left streaming mode
1016 -- 06/01/2011 04:37:24: this is a test
make request
O: $$$
I: CMD\r\n
D: Successfully enterred the command mode
O: open www.signalvehicle.com 80\r
I: open www.signalvehicle.com 80\r\r\n
I: Connect to 66.165.151.90:80\r\n
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




that happens here:

            // Are we timed out?
            if (!this.SocketConnected) throw new ApplicationException("Connection timed out");


#17 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 10 December 2012 - 07:29 PM

mind you, that happens after running successfully for 4 hours of requests every 15 seconds. That is pretty successful, I just need to find a way to swallow that exception and continue on if possible.

#18 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 December 2012 - 07:33 PM

Could you use a try/catch statement and retry after that?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#19 contractorwolf

contractorwolf

    Member

  • Members
  • PipPip
  • 23 posts

Posted 10 December 2012 - 09:20 PM

yeah im going to try (no pun intended) that after i get home




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.