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

#161 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 23 May 2013 - 10:52 PM

Hey, that's cool!

Thanks for sharing! :)


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#162 Goofmobber

Goofmobber

    New Member

  • Members
  • Pip
  • 4 posts

Posted 05 June 2013 - 04:07 AM

I'm experiencing a bit of trouble.

 

I can use /setDigitalPin just fine (192.168.2.22/setDigitalPin?pin=7&state=true)

 

However, when I try PWM, nothing happens. Here is an example of the URL I try: (192.168.2.22/pwm?pin=5&period=10000&duration=1000)

 

 

Also worth mentioning that the netduino replies with [font="monospace;font-size:13px;"]<success>[/font][color=rgb(0,0,0);font-family:monospace;font-size:13px;]10000/1000[/color][font="monospace;font-size:13px;"]</success>.[/font]

 

Am I doing something wrong? I've tried different periods and durations and nothing changes.

 

Thanks in advance.

 

Edit: Link formatting



#163 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 07 June 2013 - 07:05 AM

In the last time I didn't have time to work with my N+ / PWM.

Could it be that period and duration should be switched in you example? I'm not sure about that...

 

Here the code which handles the request:

/// <summary>        /// Submit a 'pin' (5,6,9,10), a period and a duration (0 for off, period-value for 100% on) GET parameter to control PWM        /// </summary>        /// <param name="e"></param>        /// <param name="h"></param>        /// <returns></returns>        private void SetPWM(Request e, Hashtable h)        {            if (e.GetArguments.Contains("pin"))            {                if (e.GetArguments.Contains("period"))                {                    if (e.GetArguments.Contains("duration"))                    {                        try                        {                            int pin = Int32.Parse(e.GetArguments["pin"].ToString());                            try                            {                                uint duration = UInt32.Parse(e.GetArguments["duration"].ToString());                                try                                {                                    uint period = UInt32.Parse(e.GetArguments["period"].ToString());                                    if (PinManagement.SetPWM(pin, period, duration))                                        h.Add("success", period + "/" + duration);                                    else                                        h = XMLResponse.GenerateErrorHashtable("PWM", ResponseErrorType.InternalValueNotSet);                                }                                catch (Exception ex)                                {                                    h = XMLResponse.GenerateErrorHashtable("period", ResponseErrorType.ParameterConvertError);                                    Debug.Print(ex.ToString());                                }                            }                            catch (Exception ex)                            {                                h = XMLResponse.GenerateErrorHashtable("duration", ResponseErrorType.ParameterConvertError);                                Debug.Print(ex.ToString());                            }                        }                        catch (Exception ex)                        {                            h = XMLResponse.GenerateErrorHashtable("pin", ResponseErrorType.ParameterConvertError);                            Debug.Print(ex.ToString());                        }                    }                    else                        h = XMLResponse.GenerateErrorHashtable("duration", ResponseErrorType.ParameterMissing);                }                else                    h = XMLResponse.GenerateErrorHashtable("period", ResponseErrorType.ParameterMissing);            }            else                h = XMLResponse.GenerateErrorHashtable("pin", ResponseErrorType.ParameterMissing);        }

NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#164 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 09 July 2013 - 02:06 AM

Am I missing something? I downloaded the N+2 Version (10.12.12) and have it running,  but I can't create the "network name". Its not a parameter in

Server WebServer = new Server(PinManagement.OnboardLED, 80, false, "192.168.1.25", "255.255.255.0", "192.168.1.1");

 

[font="arial, helvetica, sans-serif;"]Does the N+2 version have this?[/font]



#165 anoehre

anoehre

    New Member

  • Members
  • Pip
  • 1 posts

Posted 07 August 2013 - 06:14 PM

Very interesting project. Will there be a version for 4.3?



#166 1cintron

1cintron

    New Member

  • Members
  • Pip
  • 1 posts

Posted 09 October 2013 - 02:04 AM

[color=rgb(37,51,64);font-family:'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;font-size:13px;]I was having a few issues with the JSON returned until I noticed that the JsonArray class outputs invalid JSON. The server was returning a JSON string where there's a comma (,) after the last element in the array. In order to fix this, on the JsonArray.cs ToString() overload replace:[/color]

if (result.Length > 0)

[color=rgb(37,51,64);font-family:'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;font-size:13px;]with[/color]

if (result.Length > 0 && part != parts[Count-1])

in order to fix it and receive valid JSON serialized data. 



#167 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 15 November 2013 - 03:39 PM

Hi Guys,

I had to put my NetDuinoPlus away for awhile but now I have the time to get re-involved.  Over a year ago I had NeonMika Webserver working but currently I'm missing something.

 

I updated my firmware to 4.2 & re-downloaded NeonMika and it all works great. 

 

I want the webserver to render an HTML page I have stored on my SD card.  I've gone thru the documentation and just can't find what I knew a year ago.  I think it has something to do with Resources(???)

 

Can anyone tell me what I need to change in the code to make this happen?

 

Many Thanks



#168 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 01 December 2013 - 03:39 PM

Hi Guys,

I've been trying to get this webserver running on a Netduino Plus v1 and have run into a problem that I can't figure out.  I sure would appreciate any and all thoughts on this problem.

 

I have a webpage on my SD card that gets displayed when I type in the URL.   It's very basic, from the PC I want to turn LEDs on & off and display the results on the PC.  So the PC screen shows the status of the Netduino. 

 

Here's what happens:

The webpage gets displayed, the LED turns on, then I turn it off. And again everything works. Now here is the problem if I try to turn it on again it doesn't turn back on on the Netduino, however, It turns back on on the PC's webpage. When I run this in break mode I don't see Markus's displays in the output window from the 3rd try.

 

Netduino Plus v1

Firmware: 4.2

IE 11

 

Thanks for your help.



#169 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 11 December 2013 - 03:11 PM

Another Day, Another Question 

First  off I found I needed to add a date/time stamp to my Http Request to make every Get unique.  Now I can turn my LEDs on and off as many times as I want without any problems. 

 

Now for todays project.  Has anyone got the Upload to work?  I'm using the following:

html

<form>   <fieldset> <legend>   File Transfer: </legend>  <div class="method2">   <form method="post" enctype="multipart/form-data">   <input type="file" id="fileInput" size="70" > &nbsp; &nbsp;   <button onclick="startUpload();">Send to NetDuino</button>     <progress id="progressBar" max="100" value="0"/>   </form>   </div>   </fieldset> </form>

 

js:

addr="upload";   xhr.open("POST", addr, true);   xhr.setRequestHeader("Content-Type", fileInput.files[0].type);   xhr.send(fileInput.files[0]);

 

I've tried various settings on the addr  but always get the same results.

 

I get an empty file (lastPOST) with no file type on the SD card..  It says it has 46 bytes in it but when I open the file I don't see anything in the file.  I've tried tracing it thru the C# code but just don't know c# enough to really know what I'm watching.

 

Any thoughts?

Thanks



#170 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 16 January 2014 - 02:29 PM

Hi CT1, sorry, I've been away too for very long time here.

Thanks for using NeonMika.Webserver.

 

Now regarding your questions:

* "[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I want the webserver to render an HTML page I have stored on my SD card." ... This should be possible by trying a call like "[/color][color=rgb(37,51,64);font-family:'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;font-size:13px;]http://192.168.0.2/SD/folder/file.txt"[/color]

 

* "[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]First  off I found I needed to add a date/time stamp to my Http Request to make every Get unique.  Now I can turn my LEDs on and off as many times as I want without any problems." ... That's great that you figured out how to get it working, I always have been using [/color][color=rgb(37,51,64);font-family:'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;font-size:13px;]-> netduinoplus/setDigitalPin?pin=[0-13]&state=[true|false][/color][color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;] without problems, so I'm not sure what was the exact problem at your project.[/color]

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]* "[/color][color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Has anyone got the Upload to work?" ... I'm sorry, I'm not really an web developer (or to be honest, I'm far away from it :P) so I only developed client code for which the upload works. I can give this to you and hope that you can figure out what's happening there. Probably you can port it to js. Basicly what I can see is the difference at "[/color]request.ContentType = "application/x-www-form-urlencoded";"

private void StartUploadButton_Click(object sender, RoutedEventArgs e)        {            try            {                // Create a request using a URL that can receive a post.                 WebRequest request = WebRequest.Create(ServerTextBox.Text);                // Set the Method property of the request to POST.                request.Method = "POST";                // Create POST data and convert it to a byte array.                FileStream fs = new FileStream(LoadFileTextBox.Text, FileMode.Open, FileAccess.Read);                BinaryReader br = new BinaryReader(fs);                byte[] byteArray = new byte[fs.Length];                for (int i = 0; i < fs.Length; i++)                    byteArray[i] = br.ReadByte();                // Set the ContentType property of the WebRequest.                request.ContentType = "application/x-www-form-urlencoded";                // Set the ContentLength property of the WebRequest.                request.ContentLength = byteArray.Length;                // Get the request stream.                Stream dataStream = request.GetRequestStream();                // Write the data to the request stream.                dataStream.Write(byteArray, 0, byteArray.Length);                // Close the Stream object.                dataStream.Close();                // Get the response.                WebResponse response = request.GetResponse();                // Display the status.                System.Diagnostics.Debug.WriteLine(((HttpWebResponse)response).StatusDescription);                // Get the stream containing content returned by the server.                dataStream = response.GetResponseStream();                // Open the stream using a StreamReader for easy access.                StreamReader reader = new StreamReader(dataStream);                // Read the content.                string responseFromServer = reader.ReadToEnd();                // Display the content.                System.Diagnostics.Debug.WriteLine(responseFromServer);                // Clean up the streams.                reader.Close();                dataStream.Close();                response.Close();            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString());            }        }

NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#171 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 16 January 2014 - 03:24 PM

Hi Markus, thanks for the response.  I knew sooner or later you would return.  I'm sure you have gone off to bigger & better things.

I will have some time over the weekend to see what I can do with your suggestions.

Thanks

CT1



#172 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 25 January 2014 - 04:04 PM

Hi Markus,

I'm still trying to get the upload to work but I think I am making progress.

 

Just a quick question: 

   Is it your intention that the file be named lastPOST or should it be the name of the file from the PC that I'm uploading?

I keep getting a file on my SD card called lastPOST when I am expecting to see Test.txt but is that your intention?

The file is empty when I open it with Notepad but the size in the directory matches the size in the directory of the file on the PC.

 

So I'm making progress

Thanks for your help



#173 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 28 January 2014 - 10:50 AM

Hmm... It has been a long time since i wrote the code. As far as I know I save the currently uploaded file temporarly in the file lastPOST.

From there it will be copied to the given destination... 

 

I just have my break at work, so let's see what I can find out in 5 minutes :P

if (tempRequest.Method == "POST"){//POST was incoming, it will be saved to SD card at Settings.POST_TEMP_PATHPostToSdWriter post = new PostToSdWriter(tempRequest, buffer, header.Length);post.ReceiveAndSaveData();}

This is the code, that is excecuted in Server.cs if a POST is incoming.

PostToSdWriter can be found here: https://neonmikawebs...stToSdWriter.cs

 

Things I see there: Be sure "Content-Length"-Header is included (normally this is default)

 

Oh man! The "lastPOST" file doesn't get copied to a destination / renamed.

I didn't remember that this was not implemented by me... Or is it? I don't have the time at the moment to look into it where PostFileReader is used, probably you have time?

 

But lastPOST should contain the uploaded file (i tested it with pictures)... Try the debug / step-through the ReceiveAndSaveData method in PostToSdWriter.

 

So, I've got to get back to work.

 

I hope you can work it out :)

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#174 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 29 January 2014 - 04:59 PM

Hello Markus

Your last post got me thinking and I spent a couple hours trying different file types and I thought I'd share my observations. 

I think I will be able to fix these but just wanted to let you know what I have found out.  I thought I was losing it when I couldn't get the updates to go to the right file names, so glad you confirmed what I was thinking.

 

I have a file called ATest.txt - it just contains some text info about 5 lines long - when I uploaded it, lastPost is empty.

When I step thru the code the content type is text/plain, so thinking something it doesn't like about this file type.

 

I have tried uploading .htm, .css & .js files and the data appears in lastPOST -  yea.....but there's always a but ....

In the files that upload to lastPost, I think the first line of data gets dropped.  I'm guessing a buffer issue but haven't looked at it yet.

 

If the file exist on the SD card I can upload a new version but if the file doesn't exist I get a 404 error returned, Is this by design? 

 

I will look into these items and hopefully find a fix.

Thank you again for all your help.



#175 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 30 January 2014 - 01:48 PM

Hey CT1, today's no university, so I will give it a glimpse now :)

 

Just have to setup my Netduino development on may laptop and then I'll get started... Let's see what I can do, I will let you know if I could fix it... If so, I will upload a new version to codeplexx, give me 12 hours, will write back here :)

 

I'm pretty sure we will get it working, thanks for all your infos :)

 

Greets. Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#176 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 30 January 2014 - 05:20 PM

Hey CT1, great news!

Got the POST-Upload working.

Most of the "not-working" code was really that some parts of the header were also written and not only the POST-body.

Furthermore, some string.Replace('/','') were missing.

 

I now fixed all of this problems and will upload Version 1.2 in some minutes.

Hope you get your code working with that.

 

Let me hear from you how it's going :)

 

Great, Markus

 

PS: For upload i used the code that i posted some posts age with ServerTextBox.Text being http://192.168.0.200...rectory/pic.jpg

 

Now also the file-access and the file-directory should work without problems. Just enter http://192.168.0.200/SD (for sure with your netduinos ip) to get a view of you whole "netduino file system".

 

PPS: New download online, will grab a beer now and write some documentation :P


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#177 upstream

upstream

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationBrasil

Posted 01 February 2014 - 04:33 PM

Hi Markus,

 

I'm having fun using your code on my home automation projects. It has been a short cut to web access problems apps.

I really appreciate this project. My first contact was long ago when I found it on DIY brewery project.

 

Many thanks!


"- Somewhere there's a bug to fix..."

#178 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 01 February 2014 - 04:44 PM

Hey thanks for letting me know that my code was useful for you :)

I wrote it to help people getting started faster with network-apps, so I'm happy for every reply i hear from devs using my library :)

 

DIY brewery... Yes, I think that was one of the first projects that made use of NeonMika.Webserver :P

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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


#179 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 01 February 2014 - 08:58 PM

Hey Markus, thanks for the quick update.  I wish I could respond to you as quickly as you do to me.

 

I've downloaded v1.2, I now have data in lastPost for txt files but I am thinking you forgot the rename?

 

Also I see if I'm uploading a new file that doesn't currently exist on the SD drive say BText.txt a 404 is returned. 

Is that a feature that should work?

 

When you get tried of my questions let me know. :)

Thanks



#180 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 01 February 2014 - 09:06 PM

No, it's good that someone points me in the right direction...

 

This was my first bigger project for the open source community and so I have to admit that not everthing is working perfectly... And I could not improve my code if nobody would respond...

 

Do you have skype? If so it would be much easier for you to give me the input I need to fix it, just add neomika92 and text me... I start my netduino and will look at the problem you just mentions...

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

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






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.