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

#41 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 11 February 2012 - 02:20 PM

it's just a small mistake in your url.

Look at the thread starting post, there you find a list of methods...


Quote:


switchDigitalPin
> [ipnetduino]/switchDigitalPin?pin=[0-13]
setDigitalPin
> [ipnetduino]/setDigitalPin?pin=[0-13]&state=[true|false]




Some time ago i added the "digital" word to the command, try it with this... And if you are still learning, have a look at "breakpoints" and step by step debugging (f10) in visual studio. This really helps finding code mistakes. :)

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


#42 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 11 February 2012 - 04:30 PM

Thanks for the update, with that change keyed into the address bar, It Works. Maybe I have a version of your project before you made this change. Where do I look to see what version of your code I'm executing? Either way I'm gonna download & try it again. The code I displayed back to you was from your original code and the documentation also shows it without the word Digital. Again thank you for putting this together

#43 Guest_Ahmed Osman_*

Guest_Ahmed Osman_*
  • Guests

Posted 13 March 2012 - 03:11 PM

First thanks for sharing this great lib :)

Second I got a bug with it :). Sometimes when I cancel file request the server stop response to any new requests.

I tracked the bug and I found it in this code

using (FileStream inputStream = new FileStream(filePath, FileMode.Open))
            {
                mainThread = Thread.CurrentThread;
                Send200_OK(mType, (int)inputStream.Length, RequestArguments.Client);

                byte[] readBuffer = new byte[Settings.FILE_BUFFERSIZE];
                int sentBytes = 0;

                //Sending parts in size of "Settings.FILE_BUFFERSIZE"
                
                while (sentBytes < inputStream.Length)
                {
                    int bytesRead = inputStream.Read(readBuffer, 0, readBuffer.Length);
                    try
                    {
                        Debug.Print("in try");
                        sentBytes += RequestArguments.Client.Send(readBuffer, bytesRead, SocketFlags.None);
                    }
                    catch (Exception ex) //ToDo: Error code if client closes browser during file transport
                    {
                        Debug.Print("Browser Closed");
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        return false;
                    }
                    Debug.Print("out of try");
                }
            }
            return true;

the output

in try
out of try
in try
out of try
in try
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
Browser Closed
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
out of try
in try
Failed allocation for 343 blocks, 4116 bytes

It hangs in try code :(

#44 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 13 March 2012 - 05:11 PM

I updated the code and uploaded it.

Now the index-pages shows the possible commands to make things a little more clear: Just call your Netduinos IP :)

I cannot reproduce your problem, i have no SD card here :P But I hope it helps to call a RequestArguments.Client.Close()...

A also had the problem with a not-responding server 1 week ago. But it was not the servers fault, it was the clients.

Here is the code that I use to send commands to the Netduino:

try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(server + "/switchDigitalPin?pin=" + pin);
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {                    
                    return true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }




You need to use the "using" because sometimes (espacially if you send requests often and fast) your HttpWebResponse doesn't get "deconstructed" (was this the right term?). But this HAS to be done, otherwise the underlying Socket will keep blocking your new HttpWebRequest.

I hope there was something that could help you.

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


#45 Guest_Ahmed Osman_*

Guest_Ahmed Osman_*
  • Guests

Posted 14 March 2012 - 03:54 PM

Thanks Mark but this was not my prob :) My prob with file response not HTTP. Sometimes if browser had been closed when loading file -ex. style.css- the server don't response to any new requests :( it hangs in the try code and don't go to catch

#46 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 14 March 2012 - 04:21 PM

Probably the .Send on a closed Socket "shoots" the Netduino.

I now added a check if the Socket is still open. It looks like that:

protected bool SocketConnected(Socket s)
        {
            bool part1 = s.Poll(1000, SelectMode.SelectRead);
            bool part2 = (s.Available == 0);
            if (part1 & part2)
                return false;
            else
                return true;
        }

I uploaded it, so you can try it. Now the server should recognise, that the socket is closed and should avoid the exception.

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


#47 Guest_Ahmed Osman_*

Guest_Ahmed Osman_*
  • Guests

Posted 14 March 2012 - 05:02 PM

Thanks Mark but I couldn't find the new version :)

#48 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 15 March 2012 - 04:04 PM

Sorry, seems like there was a problem with the upload, it will be up in 1 minute ;)

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


#49 Guest_Ahmed Osman_*

Guest_Ahmed Osman_*
  • Guests

Posted 18 March 2012 - 08:53 AM

Thanks Mark it's working :)

#50 GrZeCh

GrZeCh

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationPoland

Posted 24 March 2012 - 11:14 PM

Hello, can you give me a little hint how I can connect and POST some text to remote IP address from Netduino+ without any request from outside (I want to use netduino to sent some request when motion sensor will discover movement or temperature will change)? Regards

#51 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 25 March 2012 - 05:55 AM

Netduino has some helper classes like HttpWebRequest etc., but i would suggest you to use Sockets. To send a POST from Netduino to a server just create a Socket, bind it to the server's IP, and use mySocket.Write(...) to send the data. Have a look at the wiki-page http://de.wikipedia....tocol#HTTP_POST to get some knowledge of http (if you don't have it already :P) Greats, 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. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#52 gnomathibus

gnomathibus

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationFrance

Posted 25 April 2012 - 10:50 AM

Hello, Neon Mika.Webserver is really good :) if I try to send the entire contents of an array to xml, is this possible?

#53 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 25 April 2012 - 06:38 PM

For sure!

Just use some code similar to the following:

private void SendMyArray(RequestReceivedEventArgs e, Hashtable results)
{

int[] myArr = new int[]{11,13,2};
for(int i = 0; i < myArr.Length; i++)

 {
results.Add("value"+i, myArr[i]);

 }
 }

Then you need to add the method to your webserver:

WebServer.AddResponse(new XMLResponse("sendmemyarray", new XMLResponseMethod(SendMyArray)));

Now you can call your webserver method via

http://192.168.0.2/sendmemyarray

//or whatever ip your netduino has


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


#54 gnomathibus

gnomathibus

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationFrance

Posted 25 April 2012 - 07:03 PM

thank you very much for your answer it works, but with a Multidimensional Array how to?

#55 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 25 April 2012 - 08:22 PM

just use 2 for-loops in each other....
private void SendMyArray(RequestReceivedEventArgs e, Hashtable results)
{

for(int row = 0; row < myArr.GetLength(1); row++)
 {
for(int col = 0; col < myArr.GetLength(0); col++)
{
 results.Add("value_"+row+"_"+col, myArr[row,col]); 
}
 }
 }

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


#56 gnomathibus

gnomathibus

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationFrance

Posted 25 April 2012 - 09:22 PM

ok my result is : <Response> <value_26>0</value_26> <value_10>0</value_10> <value_5>0</value_5> </Response> but I would have <Response> <id>26</id> <value>0</value> </Response> <Response> <id>10</id> <value>0</value> </Response> <Response> <id>26</id> <value>0</value> </Response>

#57 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 28 April 2012 - 10:46 AM

Thank you for using Neonmika.Webserver. I sat down this night to develop a Little XML library which allows nested XML tags, Supports Arrays and hashtables, and a Little more. I will Post another reply when i uploaded the New Version, have to do some more debugging and speeding up :) 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. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#58 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 28 April 2012 - 05:22 PM

Here we go!
I am proudly presenting my little XML "library". So now you have support for nested XML.
Have a look at the following code to get a litte overview:


/// <summary>
        /// Example for the useage of the new XML library
        /// Use the hashtable if you don't need nested XML (like the standard xml responses)
        /// If you need nested XML, use the XMLPair class. The Key-parameter is String.
        /// As value the following types can be used to achieve nesting: XMLPair, XMLPair[] and Hashtable
        /// </summary>
        /// <param name="e"></param>
        /// <param name="h"></param>
        /// <returns></returns>
        private void MultipleXML(RequestReceivedEventArgs e, Hashtable returnHashtable)
        {
            returnHashtable.Add("UseTheHashtable", "If you don't need nested XML");

            XMLPair[] Phones = new XMLPair[2];
            Phones[0] = new XMLPair("Phone");
            Phones[1] = new XMLPair("Phone");

            XMLPair[] PhoneAttributes0 = new XMLPair[2];
            PhoneAttributes0[0] = new XMLPair("Type", "Nokia");
            PhoneAttributes0[1] = new XMLPair("AvailableColours", new XMLPair[] {new XMLPair("Colour","Cyan"), new XMLPair("Colour","Black")});
            Phones[0].Value = PhoneAttributes0;

            XMLPair[] PhoneAttributes1 = new XMLPair[2];
            PhoneAttributes1[0] = new XMLPair("Type", "HTC");
            PhoneAttributes1[1] = new XMLPair("AvailableColours", new XMLPair("Colour", "Grey"));
            Phones[1].Value = PhoneAttributes0;

            returnHashtable.Add("Phones", Phones);
        }


The above code will produce the following XML:

<!--XML created by NeonMika Webserver-->
<Response>
<Phones>
<Phone>
<Type>
Nokia
</Type>
<AvailableColours>
<Colour>
Cyan
</Colour>
<Colour>
Black
</Colour>
</AvailableColours>
</Phone>
<Phone>
<Type>
Nokia
</Type>
<AvailableColours>
<Colour>
Cyan
</Colour>
<Colour>
Black
</Colour>
</AvailableColours>
</Phone>
</Phones>
<UseTheHashtable>
If you don't need nested XML
</UseTheHashtable>
</Response>

If you have questions feel free to ask :)

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


#59 gnomathibus

gnomathibus

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationFrance

Posted 29 April 2012 - 12:30 PM

hello, great reactivity! ;) I just tried the test code "multixml" but I get the following error in the debuger when I call to the function / multixml: customer connected Final byte count: 315 Request URL = multixml Start checking Requests A first chance exception of type 'System.Exception' Occurred in NeonMika.XML.dll WAS thrown exception: System.Exception

#60 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 29 April 2012 - 02:09 PM

Puh, I'm not at home today and tomorrow, so I can't look into it... Probably you can find the error by setting a breakpoint and walk step by step (F10 and F11) and watch in which line the exception is thrown. I will look for the error asap. I'm really sorry, i tested it before uploading (it worked on my N+). 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.