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

Netduino 3 Wifi - Hello World Success!


  • Please log in to reply
10 replies to this topic

#1 dx9s

dx9s

    Member

  • Members
  • PipPip
  • 12 posts

Posted 31 May 2015 - 08:22 PM

Well after windows update after windows update (started Friday -- ended up "giving" up and continuation Saturday -- computer had not been on for over 10 months -- takes a long time to update a "Developer" machine with all these development libraries)...

 

Success!!

 

First Hello World was the blinking light.

 

Second hello world was connecting to my wireless and setting up a mini web server (borrowed most of the code from an existing example -- only changed two lines basically).

 

Got that done 30 minutes before midnight last night. Very cool.

 

I will past the source code inline (it's pretty short) in a follow up, but I've noticed a few things. It seems that after a while the N3 Wifi or something goes into a state where it takes longer to reply or times out. I suspect it might be some power management or perhaps an issue with the code in general. I might need to double check the headers to make sure it is HTTP/0.9 (no keep-alive supported or attempted as it is currently HTTP/1.0 and see if that makes any difference).

 

Anybody have any better "web server" projects already written? I'd like to be able to actually serve pages from SD card for some of the things I am thinking of doing.

 

Eventually I'd like to do an AJAX like interface to be able to from web client trigger Javascript to send AJAX (json) packet to a "service" that then routes the information to the correct service-object to real-time change it's state via a web client. In order to do that, be nice to have a set of known jQuery libraries ready to serve (from SD) to web client to make a "client heavier" application. Weird idea but I think it will work okay given enough time developing.

 

I attached my program.cs inline below.

 

The Deploy interface for configuring Wifi is a little unusual and (if I understand it correctly) it appears possible to change the mac address (not recommended)?! Having the Wifi settings as a software controllable option and read from SD card would make it safer to some extent.

 

 

 

--Doug (dx9s)

 

P.S.> I did update the firmware to latest one I saw on the download page. Not sure, but figured it was a good idea. 4.3.2.2 it was.

Attached Files



#2 jinzai

jinzai

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationDavenport, IA

Posted 01 June 2015 - 12:33 AM

Awesome! I was paralleling you, apparently! Just a few thoughts...

 

No need to use quotes -- you are describing REST perfectly! That is exactly what GET is for -- not just the browser requesting static HTML, but -- the basis of XML web services -- just defining an endpoint and serving whatever you care to serve. Even WCF is just support code to make that happen -- authentication, DB access and the rest is just security wrapped around a GET verb.

 

Limor Fried has provided a rough HTTP server for use with the CC3000. It serves static HTML, however. I have seen and worked with some code for serving SD card files using the MegaADK and also Parallax Propellers using a different Wi-Fi unit. You can find code at Adafruit and Parallax, respectively. iirc, the Arduino IDE has examples....but they all use the same socket for the entire interaction.

 

The process is typical....find and open the file and then chunk it out. I have it working on my Propeller, but not the Netduino 3.

 

I am being greedy with my Netduino3 -- trying to leverage my desktop/ASPX knowledge and code. I have the same issue with this TI chip....namely, the code I see is not implementing a server according to the rules -- you are *supposed* to open a single socket for connect requests and service the GET with *another* socket.

 

I think that one of the main reasons for that is simplicity -- the socket for TCP is inherently a blocking socket, so -- its best to use threads for this, so that your application can continue to run. The upshot is -- only one client can connect at a time and these applications tend to appear to hang because sockets are not supposed to be reused in that manner. My initial tests indicated that the TI chip is just not "seeing" subsequent connect requests -- pretty sure that is because the last one was not completely handled -- to include some form of resetting the TI chip to the waiting for connect request state.

 

I have some more testing to do, in other words.

 

I actually use the same classes that I would use in a .NET desktop application and they work fine -- until...they don't. Again, I am fairly certain that I need to rewrite the server to use the network resource properly. I cannot see it being the Netduino 3 -- it has plenty of assets for the task.



#3 Nevyn

Nevyn

    Advanced Member

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

Posted 01 June 2015 - 06:18 AM

Have a look at the Neon.Mika web server (http://forums.netdui...nmikawebserver/). You will need to make a couple of modifications. One is to wait for the network before serving pages, the other problem I had was that the DHCP check had to be commented out. Small changes that only took a few minutes to get sorted out.

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


#4 Wernfried

Wernfried

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 01 June 2015 - 01:02 PM

I have adopted another WebServer for N2P, which should run on N3 too.

 

It serves pages from SD card and is able to handle Multipart request. Thus allows olso file uploads to SD card which I use fur CSS and HTML file update during developement instead of removing and inserting the SD card everytime. It uses streams, which is essential for Multipart messages. Unfortunately blocks are very small (128 Byte) otherwise N2P runs out of memory. 96K is not so much.

 

And I use a reduced jquery (about 9K), the full version is 90K, which is too large.

 

Only one unsolved problem I still have is with WebRequest send from Windows 8 or Windows Phone applications. IE, FF and Chrome works well.

 

PM me if you are interested. I will not publish the code untill the W8 problem is fixed.



#5 dx9s

dx9s

    Member

  • Members
  • PipPip
  • 12 posts

Posted 01 June 2015 - 02:47 PM

Nevyn: I did stumble on that after posting this. It looks possible -- I only skimmed over the source code but it might be a start or at least reference.

 

Wernfried: I am inerested but not in a hurry at this time.

 

All: My primary thing is to make sure the listener is threaded (each connection at least) to handle a single web browser making (usually) up to 4 parallel request at once as well as basic file serving with a "CGI" like gateway (for AJAX) to a service which really does the work behind the scene. That way the entire "UI" can be a static webpage with javascript that runs in client and the exposed interfaces (SOAP like perhaps but as simple as one can get it) over the HTTP protocol.

 

I plan to pick apart the Neon Mika web server initially as I see it had some reference to JSON in the source code some place. It also looked like that source code had a framework for extending. It might be the project that I use entirely.

 

(cryptic back-story): I plan to adapt some / simplify one of my Microchip source code to hand off some of the very time sensitive (talking nanoseconds, fractions of milliseconds) tasks and talk via serial. I got an original Netduino and was happy with the high level C# functions but needed higher deterministic timing resolution which I never moved forward on. Now with the N3 and Wifi, I have a crazy wireless redesign idea in mind using both a Netduino and 18F (K22 series) PIC (that should work). I am once again excited.

 

--Doug (dx9s)



#6 Wernfried

Wernfried

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 02 June 2015 - 07:38 AM

My implementation of the WebServer is threaded, but I'm afraid it fullfills your requirements running 4 requests. This is because auf the limited amount of RAM. I turned it currently to only use one thread and running very often in memory problems.

 

On the other hand it seems that NetMF doesn't execute multiple threads in parallel. It has only one core. Thus you can have multiple threads, but they are executed one after the other. And in executing on web request there is usually no gap for a second thread. The rqeusts in my WebServer are queued, but executed serial

 

The rest of the requirements it can fullfill.I provide a simple static (even in responsive design) site with javascript and css and AJAX requests. It provides a simple status site with some statistics (running up time, sites supported). JSON is not implemented, I decided to implement only Multipart messages which also can have parameter/value pairs. This decision I made because of the limited ROM.



#7 Nevyn

Nevyn

    Advanced Member

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

Posted 02 June 2015 - 09:11 AM

On the other hand it seems that NetMF doesn't execute multiple threads in parallel. It has only one core. Thus you can have multiple threads, but they are executed one after the other. 

If you want more information about threads in NETMF then have a look at this blog.

 

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


#8 Wernfried

Wernfried

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 02 June 2015 - 10:45 AM

Thanks for that hint, very usefull.

 

But for my WebServer it doesn't make any difference to execute the requests in parallel or in sequeal. The requesting site has to wait anyhow until all requests are proceeded. If I define mutiple threads then all of them assign memory, which is very small. In case of one thread only that one consumes the memory and can release it when finished.

 

And as I understood the blog corrcectly, multiple threads do not give any advantage according response time. It could even take longer because of thread switching.



#9 dx9s

dx9s

    Member

  • Members
  • PipPip
  • 12 posts

Posted 02 June 2015 - 03:26 PM

Yeah I know it is a "cooperative" Threaded model (hence no MUTEX support if my memory is correct). Perhaps I should review how NGINX (almost as popular as Apache) does it's (for lack of putting it better) "round-robin-like" approach. In reality, this might be overkill as only one network packet can be received at a time anyhow, and the IP stack will throw that into a buffer at some point. Perhaps simply accepting the connection into an array and then walking the array for incoming data and attempting to parse the HTTP header data into another structure until some flag (two new lines) for end of request. It could be done as an array, but the parsing (at least) and possibly responding would be an interesting framework for processing HTTP request.

 

I don't know enough of the NETMF IP stack to know how it deals with setting up multiple TCP-SYN's / SYN-ACK / ACK (typical TCP setup at the "3rd" layer) at a time. Time to break out Wireshark (formally Ethereal) and do some testing at least. I will have to look into writing some custom code to really stress the TCP portion of the NETNF stack.

 

Not sure how and when the TCP connect is established and then buffered/handed off to the application and further how incoming data is buffered. Perhaps most of this is already a non-issue (handling multiple connections at once like any decent web server). Offloading as much into the existing IP (and TCP) stack that exists in the NETMF should end up making the application simpler/smaller/more reliable (the goal is at least more reliable).

 

--Doug (dx9s)



#10 dx9s

dx9s

    Member

  • Members
  • PipPip
  • 12 posts

Posted 02 June 2015 - 05:18 PM

I was talking through MSDN and System.Net .. I know there is a WebClient class ( https://msdn.microso...(v=vs.110).aspx-- not this not NETMF ) for non-micro framework .NET.

 

So I went searching for the MSDN on .NET Micro Framework -> System.net -> https://msdn.microso...y/ee435218.aspxand spotted the HttpListener and related Http related things under the System.Net Namespace (that link is 4.1, but I think 4.3 includes all of the things from 4.1's System.Net Namespace).

 

I also stumbled on: http://blogs.msdn.co...work-netmf.aspxwhich references http://netmfwebserver.codeplex.com/ -- but the download/source code links appear broken.

 

This is good reference for re-using as much as possible from the framework. I thought I'd share it here for others to "stumble on" as well.

 

--Doug (dx9s)



#11 jinzai

jinzai

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationDavenport, IA

Posted 02 June 2015 - 05:58 PM

I am using HttpListener and the HTTP HttpRequest and HttpResponse from System.Net in a spawned thread.

They are quite nice, but do not give you access to the socket.

Single core processors always run threads serially.




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.