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

Decrease size of project


  • Please log in to reply
6 replies to this topic

#1 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

Posted 14 April 2012 - 12:16 AM

Currently my project for the N+ is 56396 bytes. I need to get it under 48kB. Any suggestions? Thanks
Steve


My Other Hobby: Engineer Turned Baker

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

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


My Other Hobby: Engineer Turned Baker

#4 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

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";
            }
        }

Steve


My Other Hobby: Engineer Turned Baker

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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

#6 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

Posted 14 April 2012 - 02:06 AM

Will do thanks.
Steve


My Other Hobby: Engineer Turned Baker

#7 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

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


My Other Hobby: Engineer Turned Baker




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.