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

NeonMika.Webserver

webserver web server neonmika internet web server http sd xml json

  • Please log in to reply
213 replies to this topic

#101 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 27 December 2012 - 09:05 PM

Hey Dave,   If you remove the 2 unneeded 72mb dat files it will compress to about a meg and a half.   Question...   Why did you remove references to SecretLabs.NETMF.Hardware.NetduinoPlus and replace with SecretLabs.NETMF.Hardware.Netduino?
If you read the firmware documentation for Netduino Plus 2, it uses the SecretLabs.NETMF.Hardware.Netduino DLL not the SecretLabs.NETMF.Hardware.NetduinoPlus DLL. The SecretLabs.NETMF.Hardware.NetduinoPlus DLL is only for the Netduino Plus (1).

#102 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 27 December 2012 - 09:13 PM

See what I get for assuming??? Thus the Netduino PLUS 2...

 

Thanks. No wonder my damn board wasn't functioning right.

 

Saved the day dude!



#103 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 27 December 2012 - 10:17 PM

See what I get for assuming??? Thus the Netduino PLUS 2...   Thanks. No wonder my damn board wasn't functioning right.   Saved the day dude!
Let us know if you get it running. Always like success stories!

#104 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 27 December 2012 - 10:51 PM

Ok, I have successfully got this running on N+2 but there is a bug in the socket code that causes the web server to drop the client about 3 out of 5 requests.Here is where the bug is under the server.cs...

 

The problem is that when the socket connects there are not bytes yet in the buffer. If the byte count is 0 he breaks out which causes the client browser to receive a dropped connection. This can be fixed by inserting a thread.sleep(100) up a few lines. Once this sleep is placed initially before the first byte check, the buffer has enough time to start populating. I have commented where the thread.sleep needs to be Fix that and this thing purrs.

 

Very nice web server. TONS of functionality.

private void WaitingForRequest( )        {            while ( true )            {                try                {                    using ( Socket clientSocket = _ListeningSocket.Accept( ) )                    {                        // Add the Thread.Sleep(100) Here                         int availableBytes = 0;                        int newAvBytes;                        //if not all incoming bytes were received by the socket                        do                        {                                                       newAvBytes = clientSocket.Available - availableBytes;                            if ( newAvBytes == 0 )                                break;                            availableBytes += newAvBytes;                            newAvBytes = 0;                            Thread.Sleep(1);                        } while ( true );                        if ( availableBytes > 0 )                        {                            byte[] buffer = new byte[availableBytes > Settings.MAX_REQUESTSIZE ? Settings.MAX_REQUESTSIZE : availableBytes];                            byte[] header = new byte[0];                            int readByteCount = clientSocket.Receive(buffer, buffer.Length, SocketFlags.None);                            for ( int headerend = 0; headerend < buffer.Length - 3; headerend++ )                            {                                if ( buffer[headerend] == 'r' && buffer[headerend + 1] == 'n' && buffer[headerend + 2] == 'r' && buffer[headerend + 3] == 'n' )                                {                                    header = new byte[headerend + 4];                                    Array.Copy(buffer, 0, header, 0, headerend + 4);                                    break;                                }                            }                            //reqeust created, checking the response possibilities                            using ( Request tempRequest = new Request(Encoding.UTF8.GetChars(header), clientSocket) )                            {                                Debug.Print("... Client connected ... URL: " + tempRequest.URL + " ... Final byte count: " + availableBytes);                                if ( tempRequest.Method == "POST" )                                {                                    //POST was incoming, it will be saved to SD card at Settings.POST_TEMP_PATH                                    PostToSdWriter post = new PostToSdWriter(tempRequest, buffer, header.Length);                                    post.Receive( );                                }                                //Let's check if we have to take some action or if it is a file-response                                 HandleGETResponses(tempRequest);                            }                            Debug.Print("Client loop finished");                            try                            {                                //Close client, otherwise the browser / client won't work properly                                clientSocket.Close( );                            }                            catch ( Exception ex )                            {                                Debug.Print(ex.ToString( ));                            }                        }                    }                }                catch ( Exception ex )                {                    Debug.Print(ex.Message);                }            }        }


#105 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 27 December 2012 - 10:56 PM

Chris, it's difficult to share the code, because VS hangs, the board hangs, the result in th debug window exactly the same of Mercer one. I'm using N2+ with 4.2.1.2 Today i was testing even the netmftoolbox-20443 basic speaker sample, and i had the same result: VS and the board hang. VS must be terminated, and the board must be reflashed. Thank you, and I want to thank you for N2+, absolutely a great project! Gerardo

 

I had the same problem. Flashed my board twice! Daves build works plus the bug fix I posted. Runs fine.



#106 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 27 December 2012 - 11:02 PM

Chris,
FYI I had the same mercer problem explained here Blue screen.
I first suspected was my pc, but I tried at least 5 times and had always the same result using this web server project. After reflashing the board, I tested may other
project with no problem, as soon as I start this web server everything hangs.
Moreover, trying to detach the USB cable during VS hang, blue screen appears, while terminating VS first and then detach the board no blue screen appear, and I only have to
reflash the board.

Hope this could help you
Gerardo

Hey Gerardo,

 

Never unplug the USB cable while VS is deploying. The BSOD is sure to follow. There is an option to cancel deployment under View/Toolbars/Build

 

Always use this and DO NOT unplug the board. I realize this does not fix the issue that the 3 of us cannot reproduce but there is definitely an issue I can vouch for. Since I just got my N+2 today it will take me a bit of time to figure out whats going on.


  • JJJ likes this

#107 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 27 December 2012 - 11:15 PM

Here is another non trivial fix. There are two threads fighting to flash the onboard LED.

 

In the static main remove the entire while loop with Thread.Sleep(Timeout.Infinite)



#108 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 28 December 2012 - 12:40 AM

Hopefully Markus is monitoring this thread and he can make the appropriate changes.

#109 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 28 December 2012 - 10:58 AM

Hey Gerardo,

 

Never unplug the USB cable while VS is deploying. The BSOD is sure to follow. There is an option to cancel deployment under View/Toolbars/Build

 

Always use this and DO NOT unplug the board. I realize this does not fix the issue that the 3 of us cannot reproduce but there is definitely an issue I can vouch for. Since I just got my N+2 today it will take me a bit of time to figure out whats going on.

Thanks a lot!

I will never do that



#110 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 28 December 2012 - 11:04 AM

Ok, I have successfully got this running on N+2 but there is a bug in the socket code that causes the web server to drop the client about 3 out of 5 requests.Here is where the bug is under the server.cs...

 

The problem is that when the socket connects there are not bytes yet in the buffer. If the byte count is 0 he breaks out which causes the client browser to receive a dropped connection. This can be fixed by inserting a thread.sleep(100) up a few lines. Once this sleep is placed initially before the first byte check, the buffer has enough time to start populating. I have commented where the thread.sleep needs to be Fix that and this thing purrs.

 

Very nice web server. TONS of functionality.

private void WaitingForRequest( )        {            while ( true )            {                try                {                    using ( Socket clientSocket = _ListeningSocket.Accept( ) )                    {                        // Add the Thread.Sleep(100) Here                         int availableBytes = 0;                        int newAvBytes;                        //if not all incoming bytes were received by the socket                        do                        {                                                       newAvBytes = clientSocket.Available - availableBytes;                            if ( newAvBytes == 0 )                                break;                            availableBytes += newAvBytes;                            newAvBytes = 0;                            Thread.Sleep(1);                        } while ( true );                        if ( availableBytes > 0 )                        {                            byte[] buffer = new byte[availableBytes > Settings.MAX_REQUESTSIZE ? Settings.MAX_REQUESTSIZE : availableBytes];                            byte[] header = new byte[0];                            int readByteCount = clientSocket.Receive(buffer, buffer.Length, SocketFlags.None);                            for ( int headerend = 0; headerend < buffer.Length - 3; headerend++ )                            {                                if ( buffer[headerend] == 'r' && buffer[headerend + 1] == 'n' && buffer[headerend + 2] == 'r' && buffer[headerend + 3] == 'n' )                                {                                    header = new byte[headerend + 4];                                    Array.Copy(buffer, 0, header, 0, headerend + 4);                                    break;                                }                            }                            //reqeust created, checking the response possibilities                            using ( Request tempRequest = new Request(Encoding.UTF8.GetChars(header), clientSocket) )                            {                                Debug.Print("... Client connected ... URL: " + tempRequest.URL + " ... Final byte count: " + availableBytes);                                if ( tempRequest.Method == "POST" )                                {                                    //POST was incoming, it will be saved to SD card at Settings.POST_TEMP_PATH                                    PostToSdWriter post = new PostToSdWriter(tempRequest, buffer, header.Length);                                    post.Receive( );                                }                                //Let's check if we have to take some action or if it is a file-response                                 HandleGETResponses(tempRequest);                            }                            Debug.Print("Client loop finished");                            try                            {                                //Close client, otherwise the browser / client won't work properly                                clientSocket.Close( );                            }                            catch ( Exception ex )                            {                                Debug.Print(ex.ToString( ));                            }                        }                    }                }                catch ( Exception ex )                {                    Debug.Print(ex.Message);                }            }        }

I had the same problem. Calling the webserver, sometimes (3 out of 5 is a correct statistic), it drops the client.

I'm testing some other solutions (I do not like Thread.Sleep), even if the the Bendage one works for now.

 

As soon as my solution passed my tests I will post it.

Gerardo



#111 Joshua

Joshua

    Member

  • Members
  • PipPip
  • 20 posts

Posted 03 January 2013 - 08:48 PM

Has anyone tried to use this to receive a JSON posted array?  I am having trouble and when i debug.. It looks like the client is never receiving the full content-length sized byte array.  It gets the header and then crashed on post.receive().  Any ideas?



#112 JeffJohnson

JeffJohnson

    Member

  • Members
  • PipPip
  • 15 posts

Posted 05 January 2013 - 05:24 PM

This looks like exactly what I've been searching endlessly for.  However, I can't unzip the files b/c they are password-protected.  What am I doing wrong?  I signd into codeplex...



#113 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 05 January 2013 - 05:45 PM

This looks like exactly what I've been searching endlessly for.  However, I can't unzip the files b/c they are password-protected.  What am I doing wrong?  I signd into codeplex...
I just downloaded it and it opened fine. Didn't ask for a password of any kind.

#114 JeffJohnson

JeffJohnson

    Member

  • Members
  • PipPip
  • 15 posts

Posted 05 January 2013 - 10:24 PM

Greets,

 

I have been trying (and trying) to run this project on my N+2 but am getting deployment errors that I hve gathered (through wonderful folks in chat room) that I need to re-build all the source files to net mf 4.2.  Can one of you smart guys help me do that?  I'd be much obliged.

 

JeffJ



#115 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 05 January 2013 - 11:59 PM

Greets,   I have been trying (and trying) to run this project on my N+2 but am getting deployment errors that I hve gathered (through wonderful folks in chat room) that I need to re-build all the source files to net mf 4.2.  Can one of you smart guys help me do that?  I'd be much obliged.   JeffJ
The link to the ND+2 version is in this thread. I think it is post #91 if I recall. I posted a link to my dropbox account to download it.

#116 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 06 January 2013 - 11:39 AM

The link to the ND+2 version is in this thread. I think it is post #91 if I recall. I posted a link to my dropbox account to download it.

It was indeed post #91 and I can verify that it does work as I loaded it onto my N+2 a few days ago.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#117 Joshua

Joshua

    Member

  • Members
  • PipPip
  • 20 posts

Posted 07 January 2013 - 08:42 PM

I'm having trouble receiving post data with this.  I have a var set which has some JSON data in it.  When i try to post that data with the below button code, chrome shows it as posting all of the data, but when you look at what was received by the n+2 by putting a break point at the end of the post.receive() code.. All there is is the header.. and nothing after it.

$("input:submit").button().click(function(){        $.ajax({                url:'/SaveConfig',                type:'POST',                dataType:'json',                data:{json:JSON.stringify(config)},                success: function (data)                {                    var obj = $.parseJSON(data);                }            });});});


#118 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 08 January 2013 - 12:30 AM

I'm having trouble receiving post data with this.  I have a var set which has some JSON data in it.  When i try to post that data with the below button code, chrome shows it as posting all of the data, but when you look at what was received by the n+2 by putting a break point at the end of the post.receive() code.. All there is is the header.. and nothing after it.

$("input:submit").button().click(function(){        $.ajax({                url:'/SaveConfig',                type:'POST',                dataType:'json',                data:{json:JSON.stringify(config)},                success: function (data)                {                    var obj = $.parseJSON(data);                }            });});});

Have you checked to see what was written to the SD card or stepped into the post.Request( ); function further? I haven't looked thoroughly at the code but I believe you only see the header up to that point but stepping farther into the code it parses out the content and writes it.



#119 Joshua

Joshua

    Member

  • Members
  • PipPip
  • 20 posts

Posted 08 January 2013 - 02:47 PM

Have you checked to see what was written to the SD card or stepped into the post.Request( ); function further? I haven't looked thoroughly at the code but I believe you only see the header up to that point but stepping farther into the code it parses out the content and writes it.

I have stepped into the post.Request() code and it throws an exception at the end of it because there are no additional bytes received after the header is.  So it throws a null reference exception.  Nothing was written to the temp post file either.



#120 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 08 January 2013 - 03:34 PM

Are you able to post a small test project to test with?  I don't have a spare ND+2 setup right now, but I could try to take a step through it.  You may also want to try and reach out to Markus VV since he wrote it.  He may be able to give more guidance.  He doesn't come on that often it appears.  He's been offline since Dec 12th.







Also tagged with one or more of these keywords: webserver, web server, neonmika, internet, web, server, http, sd, xml, json

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.