Pages: [1] 2   Go Down
Author Topic: increase sketch size for arduino webserver ( Uno and ethernet shield)  (Read 3331 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I just got my nice Arduino Uno and the ethernet shield. I Want to make a website hosted on the shield to control som leds.
but when I started to make a simple one LED on and off test website I noticed that I used almost half of the Max sketch size.
When I bought the Arduino I didn't realize that there would be a limit to the sketch size ( at least not that fast).

So my question is how (if possible) do I increase the Max sketch size is there something I can buy/exchange to get say 1-5 MB

I have the SD slot can that be used? if so how do I go about it or will the MAX sketch size increase if I just place a SD card in there?

I hope my question isn't stupid because all of you here knows the answer already.

Thanks,

Patrikk
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No there is not really anything you can do, except by an Arduino Mega that has more flash and more RAM.

Of course thee is always the possibility that your sketch can be optimized / rewritten in some way to take up less space.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I read somewhere that they bought more memory but they never explained howthey used it for the arduino
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50507
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I read somewhere that they bought more memory but they never explained howthey used it for the arduino
They who?

There are any number of things you can do. It is likely that sketch size is not your problem, but that memory is. Of course, we haven't seen any code, so that is purely a guess.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well I guess there is no need for the code because the things that will take up all of the memory is the actual HTML and jquery.js and the css file. on top of that my plan was to also control a LCD display. only the jquery is over 200K then the html is so far 17k css is about 100k so with the basic webserver sketch on about 14k with the includes we can see that there is not way it will all fit.

hmm. I thought:

is the max 32k total space on the UNO or is it just the sketch file? if its just the sketch file then maybe I could minimize the html to a few rows and then use an iframe to include the pages from the client ( read them from the SD? )

what do you think of that is it posible?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50507
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because the things that will take up all of the memory is the actual HTML and jquery.js and the css file.
All of which could be read from an SD card and sent. Of course, having that elaborate a web site served by a tiny web server hardly makes sense. Scaling back your expectations might be in order.

What, exactly, is the style sheet contributing?

What, exactly, is the jquery.js thing going to do?
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Small optimization: you don't have to serve jQuery yourself.  Google will serve it for you if you reference the right url from a script tag in your HTML:

    https://developers.google.com/speed/libraries/

-br

Edit: PS: You can do the same with your .css if you put it up on web hosting somewhere.  Even a public Dropbox folder would do.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well I guess there is no need for the code because the things that will take up all of the memory is the actual HTML and jquery.js and the css file. on top of that my plan was to also control a LCD display. only the jquery is over 200K then the html is so far 17k css is about 100k so with the basic webserver sketch on about 14k with the includes we can see that there is not way it will all fit.

You seem to be trying to host a conventional web site on an Arduino. It's not at all well suited to that. You would be far better off hosting the presentation layer of your web site on an ordinary web server on a computer, and just use a web service (or whatever other comms mechanism you may prefer) to access business layer functions in the Arduino.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I guess Im trying to host a conventional web site with a nice gui för the leds.

Thank you all fot the input.

How would I go about reading and showing a HTML file from the SD card.?

What Im actually trying to do it make n sliders to control the n leds and set time interval for diming the leds up and down.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50507
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What Im actually trying to do it make n sliders to control the n leds and set time interval for diming the leds up and down.
Is that what the jquery.js part is doing? Sliders are not normal HTML elements.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What Im actually trying to do it make n sliders to control the n leds and set time interval for diming the leds up and down.
Is that what the jquery.js part is doing? Sliders are not normal HTML elements.

Yes thats what jquery is being used for and jquery ui.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9701
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tinkered with servo sliders in the past like below. So far loading the below on the SD card still uses too much memory.

http://web.comporium.net/~shb/servoslider.htm
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tinkered with servo sliders in the past like below. So far loading the below on the SD card still uses too much memory.

http://web.comporium.net/~shb/servoslider.htm


I've looked into this matter with javascript and file size some more I compared your code ( I removed all but one of the sliders) and your file ends up at about 9k and the current code I got for one slider is about 2k (the 2k file have the css and javascript file in the HTML not includes).

I will be trying to slim the other js things I want as well but I guess it's a good start.

do you know how far off you are regarding memory usage?
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9701
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The below code compiles to 22.6k. The file sizes don't seem to be the issue, so it appears the SD.h might be the bloating factor.

Code:
//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //delay(2000);
  server.begin();
  Serial.println("Ready");

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          File myFile = SD.open("hello.txt");
          //File myFile = SD.open("boom.htm");
          //File myFile = SD.open("HYPNO.JPG");
          //File myFile = SD.open("BLUEH_SL.GIF");
          //File myFile = SD.open("BLUEV_BG.GIF");
          //File myFile = SD.open("SLIDER.JS");
          //File myFile = SD.open("servosld.htm");
          //File myFile = SD.open("SERVOSLD.HTM");
          if (myFile) {
            //Serial.println("test.txt:");
            // read from the file until there's nothing else in it:
            while (myFile.available()) {
              client.write(myFile.read());
            }
            // close the file:
            myFile.close();

          }
            delay(1);
            //stopping client
            client.stop();
            readString="";
         
        }
      }
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9701
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The below will serve the slider files from the SD card. Next to add back the servo control code.

Code:
//zoomkat 1/25/13
//SD server slider test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84/servosld.htm when submited
//for use with W5100 based ethernet shields
//put the servosld.htm, slider.js, bluev_sl.gif,
//and bluev_bg.gif on the SD card
//files at http://web.comporium.net/~shb/servoslider.htm page


#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = {
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = {
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //delay(2000);
  server.begin();
  Serial.println("Ready");

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          if(readString.indexOf("servosld") >=0) {
          client.println("Content-Type: text/html");
          client.println(); }

          if(readString.indexOf("slider") >=0) {
          client.println("Content-Type: application/x-javascript");
          client.println(); }
         
          if(readString.indexOf("bluev") >=0) {
          client.println("Content-Type: image/gif");
          client.println(); }

          if(readString.indexOf("servosld") >=0) {
            File myFile = SD.open("SERVOSLD.HTM");
            if (myFile) {
              while (myFile.available()) {
                client.write(myFile.read());
              }
              myFile.close();
            }
          }

          if(readString.indexOf("slider") >=0) {
            File myFile = SD.open("slider.js");
            if (myFile) {
              while (myFile.available()) {
                client.write(myFile.read());
              }
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_sl") >=0) {
            File myFile = SD.open("bluev_sl.gif");
            if (myFile) {
              while (myFile.available()) {
                client.write(myFile.read());
              }
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_bg") >=0) {
            File myFile = SD.open("bluev_bg.gif");
            if (myFile) {
              while (myFile.available()) {
                client.write(myFile.read());
              }
              myFile.close();
            }
          }

          delay(1);
          //stopping client
          client.stop();
          readString="";

        }
      }
    }
  }
}
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1] 2   Go Up
Jump to: