Currently my project for the N+ is 56396 bytes. I need to get it under 48kB. Any suggestions?
Thanks
Decrease size of project
Started by smarcus3, Apr 14 2012 12:16 AM
6 replies to this topic
#2
Posted 14 April 2012 - 01:43 AM
Hi smarcus3,
Are you using System.Net.Http? Removing that will free up a lot of space...and you can use a simpler socket method instead...
We may have as much as 57,344 bytes available in the NETMF 4.2 RC5 firmware. No promises, but we're working on it. Although even then...too close for comfort on your project
Chris
#3
Posted 14 April 2012 - 01:48 AM
I am using system.http as well as the microliquidcrystal library.
What simplier one can I use. I utilize the HTTPWebRequest function.
#4
Posted 14 April 2012 - 02:04 AM
Here is the only part of my code which utilizes anything HTTP related.
public static string GetOnlineWebPage(string url, int beginnigTrimAmmount, int maxStringLength) { /* THIS FUNCTION GETS ONLINEWEBPAGES AS LONG AS THEY ARE NOT HTTPS. THE NETDUINO AT THIS POINT DOESNT * HANDLE DEALING WITH HTTPS PAGES OR SSL. THE WORK AROUND TO THIS IS TO USE AN PHP WEBSITE. THE FUNCITON * RETURNS THE ENTIRE WEBSITE AS A LONG, LONG STRING. ALL OF THE HTML WILL BE RETURNED WITH THIS FUNCTION * SUCH AS HEADER AND BODY BREAKS. THIS FUNCTION GOES HAND IN HAND WITH GETSTRINGINBETWEEN * * INPUT: URL ---> A STRING WHICH CONTAINS THE URL OF THE SITE SUCH AS HTTP://WWW.GMAIL.COM * * OUTPUT: A STRING WHICH CONTAINS ALL THE RAW DATA OF THE WEBSITE */ // used to build entire input //clStringBuilder sb = new clStringBuilder(); // used on each read operation byte[] buf = new byte[25]; //8192 was the original value but we ran out of memory. //bool hasItBeenFound = false; string fullstring = ""; //while (hasItBeenFound == false) //{ try { // prepare the web page we will be asking for HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // execute the request HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); int count = 0; bool keepGoing = true; bool hasFirstTrimHappened = false; bool hasSecondTrimHappened = false; do { // fill the buffer with data count = resStream.Read(buf, 0, buf.Length); // make sure we read some data if (count != 0) { // translate from bytes to ASCII text //tempString = Encoding.ASCII.GetString //(buf, 0, count); fullstring += new string(Bytes2Chars(buf)); // continue building the string //fullstring += tempString; //sb.Append(tempString); } else keepGoing = false; //Add data has been read //cuts off the worthless front end data if ((hasFirstTrimHappened == false || hasSecondTrimHappened == false) && fullstring.Length > beginnigTrimAmmount / 2) { fullstring = fullstring.Substring(beginnigTrimAmmount / 2); if (hasFirstTrimHappened == false) hasFirstTrimHappened = true; else hasSecondTrimHappened = true; } if (fullstring.Length > maxStringLength && hasFirstTrimHappened == true) keepGoing = false; } while (keepGoing == true); // any more data to read? //fullstring = fullstring.Substring(beginnigTrimAmmount - 1); if (maxStringLength < fullstring.Length) fullstring = fullstring.Substring(0, maxStringLength - 1); return fullstring; } catch { return "BADWEBPAGE"; } }
#5
Posted 14 April 2012 - 02:05 AM
Hi smarcus3,
Take a look at the SocketClient sample that comes with the .NET MF SDK samples. Also, some community members have created some "light" wrappers for Http. Cuno Pfister probably has quite a few ideas; he wrote the "Getting Started with the Internet of Things" book.
Chris
#7
Posted 14 April 2012 - 11:56 PM
I think i rewrote my function to not use the system.net stuff and use the toolbox one instead. The size is now 33944 bytes. Success.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users