NeonMika.Webserver
#41
Posted 11 February 2012 - 02:20 PM
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 down - 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
Posted 11 February 2012 - 04:30 PM
#43 Guest_Ahmed Osman_*
Posted 13 March 2012 - 03:11 PM
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
Posted 13 March 2012 - 05:11 PM
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 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 down - 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_*
Posted 14 March 2012 - 03:54 PM
#46
Posted 14 March 2012 - 04:21 PM
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 down - 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_*
Posted 14 March 2012 - 05:02 PM
#48
Posted 15 March 2012 - 04:04 PM
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 down - 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_*
Posted 18 March 2012 - 08:53 AM
#50
Posted 24 March 2012 - 11:14 PM
#51
Posted 25 March 2012 - 05:55 AM
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 down - 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
Posted 25 April 2012 - 10:50 AM
#53
Posted 25 April 2012 - 06:38 PM
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 down - 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
Posted 25 April 2012 - 07:03 PM
#55
Posted 25 April 2012 - 08:22 PM
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 down - 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
Posted 25 April 2012 - 09:22 PM
#57
Posted 28 April 2012 - 10:46 AM
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 down - 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
Posted 28 April 2012 - 05:22 PM
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 down - 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
Posted 29 April 2012 - 12:30 PM
#60
Posted 29 April 2012 - 02:09 PM
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 down - 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
Hardware →
Netduino 3 →
Web server, socket, reading buffer data?Started by TheBrian , 10 Feb 2016 web server, socket, buffer |
|
|
||
Hardware →
Netduino 3 →
ND3 SD Filestream.Read() seems to become brokenStarted by ukkiwisurfer , 08 Nov 2015 SD |
|
|
||
Hardware →
Netduino 3 →
ND3 hangs calling File.Delete()Started by ukkiwisurfer , 06 Nov 2015 SD, Wifi, Netduino |
|
|
||
General →
General Discussion →
Support for Micro SD Card > 2 GBStarted by TechnoGuy , 10 Sep 2015 MicroSD, SD, SDHC, SDXC, FAT12 and 3 more... |
|
|
||
Hardware →
Netduino Plus 2 (and Netduino Plus 1) →
Why do I have to reboot my device to change the IP address?Started by cSharper , 31 Jul 2015 webserver, ip, netduino, change and 1 more... |
|
|
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users