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.
NeonMika.Webserver
Started by
NeonMika / Markus VV.
, Nov 07 2011 04:42 PM
NeonMika.Webserver is an pre-setup and easy to extend webserver. With minimal (to no) code you can achieve great results controlling your Netduino+, accessing and uploading files and more!
It's supports:
- SD card access
- Controlling your Netduino using existing methods like setPWM or setDigitalPinState (see full list below)
- Adding your own webservice-like methods so you can expand NeonMika.Webserver to your own needs for every project.
How easy is it?
Server WebServer = new Server PinManagement.OnboardLED, 80, false, "192.168.0.200", "255.255.255.0", "192.168.0.1", "NETDUINOPLUS");
The parameter for setup are: The OnboardLED, Port, DHCPenable, ipAdress, subnetMask, gateway, name.
You don't need anything more to run it!
Here is a list with all pre-coded webmethods you can use within your browser or any other application to communicate with your Netduino:
echo (Returns the submitted value)
-> netduinoplus/echo?value=[a-Z]
switchDigitalPin (Switches the selected pin from true to false and vis-a-vis)
-> netduinoplus/switchDigitalPin?pin=[0-13]
setDigitalPin (Set the selected digital pin to the selected state)
-> netduinoplus/setDigitalPin?pin=[0-13]&state=[true|false]
pwm (Set the PWM of the pin to the submitted period & duration
-> netduinoplus/pwm?pin=[5|6|9|10]&period=[int]&duration=[int]
getAnalogPinValue (Return the value of the selected analog pin)
-> netduinoplus/getAnalogPinValue?pin=[0-5]
getDigitalPinState (Returns your selected pin's state (on / off))
-> netduinoplus/getDigitalPinState?pin=[0-13]
getAllAnalogPinValues (Return the value for each analog pin)
-> netduinoplus/getAllAnalogPinValues
getDigitalPinState (Returns the state for each digital pin)
-> netduinoplus/getAllDigitalPinStates
getAllPWMValues (Returns the values for all PWM ports)
-> netduinoplus/getAllPWMValues
fileUpload (Uploads a file to the path on the SD card via POST. You have to write the file-data (bytes) into the POST body)
-> netduinoplus/upload?path=[a-Z]
AND FOR SURE:
File and directory response
Just type in netduinoplus/[pathtomyfile] and you can view / download your file. If the given path is a directory, a directory view will be returned
- Index page(8.11.2011)
- Screenshot ofecho, switchPin and index page (8.11.2011)
- JSON support(30.11.11)
- PWM(30.11.11)
- getAnalogPinValue and getDigitalPinState (30.11.2011)
- Examples(30.11.2011)
- FileResponseimproved (15.3.2012)
- Changed indexpage (15.3.2012)
- Nested XMLsupport (28.4.2012)
- Example method for nested XML -> see MultipeXML(28.4.2012)
- Code cleanup(28.4.2012)
- POST working!(22.11.2012)
- File upload(22.11.2012)
- Better XML(22.11.2012)
- Choosing between DHCP and fixed IP (22.11.2012)
- Return filelist from directory (Directory view) (22.11.2012)
- Some changes to the code (Somewhere here between )
- Videos (13.3.2013)
- Nameservice (28.3.2013)
- Server code refactor and restructure (28.3.2013)
- Index page (28.3.2013)
- New webserver methods (28.3.2013)
--- GetAllPWM (Returns duration and period for all PWM pins)
--- GetAllDigitalPinStates (Returns the state for all digital pins)
--- GetAllAnalogPinValues (Returns the value for all analog pins)
- NeonMika.Webserver.ClientLibrary Version 0.1 (28.3.2013)
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Oh wow, Markus. That's pretty cool.
Do you have a sample "site" for it already? Can you show off screenshots/photos so people can see what NeonMika.Webserver can do?
Chris
Do you have a sample "site" for it already? Can you show off screenshots/photos so people can see what NeonMika.Webserver can do?
Chris
I will sit down tonight @ my girlfriends place to write a little index.html
But i don't have a SD card atm, so i will write a sample "Complex response" so people can see how this is done.
Tomorrow i will take some screenshots and a little video. So stay tuned for more visual info tomorrow
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I added some screenshots, did'nt have time for the video, have to go to work #2 now...
Probalby in the night, otherwise tomorrow =)
But i hope that the screenshots help to understand how to use it
Greets, Markus
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Markus,
I've pulled down your code and have been trying to use it for an interface to a temperature logger that I'm building. The concept really fits into what I need, however I've noticed that after running for a couple of minutes it seems to be going off into nowhere and never answers.
I'm running under the .NetMF 4.2 RC3 firmware, so I'm not sure if it is the newer firmware or maybe the code. Have you run into anything like this or does it run without issue for you?
Just trying to figure out where I should be spending my time trouble shooting.
Thanks
I've pulled down your code and have been trying to use it for an interface to a temperature logger that I'm building. The concept really fits into what I need, however I've noticed that after running for a couple of minutes it seems to be going off into nowhere and never answers.
I'm running under the .NetMF 4.2 RC3 firmware, so I'm not sure if it is the newer firmware or maybe the code. Have you run into anything like this or does it run without issue for you?
Just trying to figure out where I should be spending my time trouble shooting.
Thanks
Are you running in debug mode?
There you can check if incoming requests get ignored...
Probably you get a outofmemory-exception?
I sometimes had the problem that it just worked fine for a time and then it stopped receiving requests, i will look into that as soon as i have time
It mustbe something in the Server-class' Listening loop...
Probably you can find an error there (about 20 lines of code)...
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Are you running in debug mode?
There you can check if incoming requests get ignored...
Probably you get a outofmemory-exception?
I sometimes had the problem that it just worked fine for a time and then it stopped receiving requests, i will look into that as soon as i have time
It mustbe something in the Server-class' Listening loop...
Probably you can find an error there (about 20 lines of code)...
Greets
Markus,
It is not throwing an exception of any kind, but I think you are right with it running out of resources. I was playing with the server listening loop and did make some changes and now it runs without issue. Let me spend some time comparing my changes to the original code and I'll post an issue to the codeplex page.
I also made some changes to the Handle Request method and changed from an array list to a hashtable to speed up request processing. I'll also post those changes as well.
I've posted the differences out on codeplex for you. Hopefully they'll be of help.
Cheers,
Jim Lavin
Thank you Jim!
Doing some error handling, good idea. Next time I'll consider it more
So did you find out why exactly the code was stopping working? Or are you also not sure and just do some "workaround" with the errorhandling block?
And thank you for the tip with the using for the ClientSocket and the hashtable, i will include them in my next version and will upload the new code in the next few days
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
You are so right, I think that's the point!
It's great to have people like you around that help to find this little problems you spend hours on and don't find them (even if it is just one line )
Greets, Markus
PS: I just updated the project main page and the thread start post. The next step will be to build a more "beautiful" index page you can use as a "control center". The last days I read through w3schools.com on HTML, HTML5, CSS and a bit Javascript. I am excited how my first "website" will look like
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
This looks like it could be a very noobe friendly server but I have a few questions.
1, Is there a plan to add PWM control to the server to dim the outputs?
2, Would it be possible to add a web page side method that alows you to control which input is tied to which output
i.e:input 1, analogue, :output 1,PWM
Sorry I'm a noob to programming and not getting much time to learn how to code things yet.
Thanks for your idea sharing.
PWM gets on the to-do list. But it's not that difficult at all. This is why i wanted to build this server extendable. You can have a look at this: http://neonmikawebse...m/documentation
Just build a method in this way:
private void Methodname(RequestReceivedEventArgs e, Hashtable h)
{
//fill h with your response keys and values
}
I never worked with PWM, but I think it will look something like this:
private void PWM(RequestReceivedEventArgs e, Hashtable h)
{
SecretLabs.NETMF.Hardware.PWM pwm = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5);
if(e.Request.GetArguments.Contains("pulse")
{
int pulse = Convert.ToInt32(e.Request.GetArgumenst["pulse"];
pwm.SetPulse(20000, pulse);
h.Add("newPulse",pulse);
}
else
h.Add("ERROR","No 'pulse'-value transmitted");
}
}
Then you have to add this method to your webserver instance:
Just did that out of mind without IDE, this is probably not going to work without changes.
Then you could set your PWM via this URL:
"http://netduinoip:port/pwm?pulse=4000"
Sorry, I'm no native speaker. Could you explane your second question in more detail?
I dont have my netduino at home to work with it today, but i will sit down today to expand the server code (probably i also include pwm)
Tomorrow you can test the new version
Greets, Markus
Edited by Markus VV., 29 November 2011 - 11:17 AM.
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorry, times I forget not all clever people are english
What I was thinking was eather 2 buttons up and down to alter the value or a slider to adjust the brightness level.
Sorry, times I forget not all clever people are english
What I was thinking was eather 2 buttons up and down to alter the value or a slider to adjust the brightness level.
That shouldn't be that hard, I'm already in the Javascript learning phase
The slider (or buttons) only have to execute the "http://netduinoip:port/pwm?pulse=[INSERT VALUE HERE 0-20000]" command with the wanted value. E.g. 0 is completly off, 20000 is completly on...
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm doing something similar by using jQuery to post data back to the server.
First I added additional pin types to the Pin Management class, then I added a couple of new request methods like Markus discussed.
I then have web pages that can be returned from the server which contain my user interface which have jQuery methods that send the request back to the server to be processed and return the results. This way I can interact with the Netduino however I wish, I can even use this method to set
the time and network settings on the device.
You just have to be careful about how much functionality you try to shoehorn into the device since memory is pretty tight. To build my temperature controller complete with logging and history charts I end up with about 30K worth of code when all finished. That included a complete library to send back JSON formatted data.
You can do quite a bit.
Markus,
I had to add code to handle the HTM and HTML file types to the extension handler so it would return the proper MIME type. It seems if you request index.html from the server it was always coming back as application/octetstream instead of text/html.
I also added a JSON request handler that uses a JSON library to return requests in JSON format.
Let me know if you want me to post the code for you to include.
Cheers,
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Wow, now that was some long work:
But I am proud to announce Version 0.2. Now with:
- JSON support
Thanks to Jim aka Coding Smackdown for sending me his code to include JSON support into NeonMika.Webserver
- PWM
- getAnalogPinValue and getDigitalPinState
Now you can not only send commands to your Netduino like switchPin, now you can also query the actual state of your digital and analog pins.
- Examples
Have a look at the thread opening post. There are now examples how to write xml and json responses and how to set up a simple webserver.
I don't have my Netduino+ at my place today. I will test it tomorrow
But I hope everything works fine
And again a big thanks at Jim!
Have fun with the new version of NeonMika.Webserver.
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------