Large Sketch ?

Hi all,

so what do I do if need more space for my sketch ? I'm trying to make a little web device, just flashes an led and connect 232 to a device. I want to have a little setup page hosted on the arduino to store auto replies and handle some basic logic ... so I'm going to use the ethernet sheild (Which I need to find a good solution for setting an ip) but I was thinking of using an SD card to store the HTML pages and images, but from what I'm reading that doesn't seem to work very well either, anyone upgrade to the 328p with an ethernet sheild and sd card ? or has anyone tried any of this already ? or any is there anything else thats this easy to program that has a ethernet option ?

Thanks already

If you're intending to use the Ethernet Shield that allows you to connect an Xport, the Xport has an embedded web server and a few hundred KB of space you can store images and HTML. If you have the Arduino interactive web stuff and the Xport static web stuff on different ports, it should be possible to do what you need.

On the other hand, if you plan to use an ethernet shield that has a Wiznet chip on it, then you will need to find some external storage method.

Im using a 328p and serving up a simple page with a table, graph via google graph api and the table of values for the graph and still seem to have space to spare. Even with using a serial lcd and a couple of temperature sensors.
Most of the table is generated in a loop. So less text/html stored.
The graph url is generated from a loop with an array of values.

So as you can see you can get quite a lot out of the arduino as a web server.

Output posted as seen by the browser here :

<html>
<head>
<title>Arduino Weather Station</title>
<style type="text/css">
h3 {color:blue}
p {color:blue}
.t {width:50}
.l {width:100}
</style>
</head>
<body>
<h3>Arduino Weather Station</h3>
<table>
<tr><td class="l"></td>
<td class="t">Curr</td>
<td></td>
<td class="t">Min</td>

<td></td>
<td class="t">Max</td></tr>
<tr><td>External</td>
<td>11.37</td>
<td></td>
<td>3.25</td>
<td></td>
<td>14.50</td><td></td></tr>
<tr><td>Internal</td>
<td>18.31</td>

<td></td>
<td>14.68</td>
<td></td>
<td>20.18</td>
<td></td></tr></table>
<p>Temperature history chart </p>
<img alt="Temp history chart" src="http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=t:67.56,67.87,67.81,67.87,68.81,70.12,68.75,69.56,68.37,68.25,68.12,67.56,67.31,66.93,66.50,66.12,65.93,65.81,65.68,67.43,68.50,68.93,68.81,68.43|59.50,61.81,61.93,62.75,62.56,59.68,58.18,58.81,58.25,58.00,57.25,56.68,57.06,56.06,55.50,55.56,55.68,55.81,55.87,56.18,56.62,57.31,58.87,60.37&chco=FF0000,0000FF&chdl=Int|Ext&chxt=x,y&chxl=0:|-24|-23|-22|-21|-20|-19|-18|-17|-16|-15|-14|-13|-12|-11|-10|-9|-8|-7|-6|-5|-4|-3|-2|-1|1:|-50|-40|-30|-20|-10|0|10|20|30|40|50&chg=0,50,1,0"><p>Temperature history values </p>
<table><tr>
<td class="l">Hours ago </td>
<td class="t"> -24</td>

<td class="t"> -23</td>
<td class="t"> -22</td>
<td class="t"> -21</td>
<td class="t"> -20</td>
<td class="t"> -19</td>
<td class="t"> -18</td>

<td class="t"> -17</td>
<td class="t"> -16</td>
<td class="t"> -15</td>
<td class="t"> -14</td>
<td class="t"> -13</td>
<td class="t"> -12</td>

<td class="t"> -11</td>
<td class="t"> -10</td>
<td class="t"> -9</td>
<td class="t"> -8</td>
<td class="t"> -7</td>
<td class="t"> -6</td>

<td class="t"> -5</td>
<td class="t"> -4</td>
<td class="t"> -3</td>
<td class="t"> -2</td>
<td class="t"> -1</td>
</tr><tr>
<td>Int </td>

<td class="t">17.56</td>
<td class="t">17.87</td>
<td class="t">17.81</td>
<td class="t">17.87</td>
<td class="t">18.81</td>
<td class="t">20.12</td>
<td class="t">18.75</td>
<td class="t">19.56</td>
<td class="t">18.37</td>

<td class="t">18.25</td>
<td class="t">18.12</td>
<td class="t">17.56</td>
<td class="t">17.31</td>
<td class="t">16.93</td>
<td class="t">16.50</td>
<td class="t">16.12</td>
<td class="t">15.93</td>
<td class="t">15.81</td>

<td class="t">15.68</td>
<td class="t">17.43</td>
<td class="t">18.50</td>
<td class="t">18.93</td>
<td class="t">18.81</td>
<td class="t">18.43</td>
</tr><tr>
<td>Ext </td>
<td class="t">9.50</td>

<td class="t">11.81</td>
<td class="t">11.93</td>
<td class="t">12.75</td>
<td class="t">12.56</td>
<td class="t">9.68</td>
<td class="t">8.18</td>
<td class="t">8.81</td>
<td class="t">8.25</td>
<td class="t">8.00</td>

<td class="t">7.25</td>
<td class="t">6.68</td>
<td class="t">7.06</td>
<td class="t">6.06</td>
<td class="t">5.50</td>
<td class="t">5.56</td>
<td class="t">5.68</td>
<td class="t">5.81</td>
<td class="t">5.87</td>

<td class="t">6.18</td>
<td class="t">6.62</td>
<td class="t">7.31</td>
<td class="t">8.87</td>
<td class="t">10.37</td>
</tr></table>
</body></html>

And this is the webserver part of my sketch.
I havnt tidies it up yet and theres a lot more to do to optimise it.
And Ive modified my print.cpp to take a precision value.
So the code wont work unless you modify those lines.

When I finally get round to finishing this ill post it all up in full.

void webServer(){
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    
    while (client.connected()) {
      message("Webserver busy");
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output html header
          client.println("<html>");
          client.println("<head>");
          client.println("<title>Arduino Weather Station</title>");
          client.println("<style type=\"text/css\">");
          client.println("h3 {color:blue}");
          client.println("p {color:blue}");
          client.println(".t {width:50}");
          client.println(".l {width:100}");
          client.println("</style>");
          client.println("</head>");
          client.println("<body>");

          // output the temp in table
          // 1st row
          client.println("<h3>Arduino Weather Station</h3>");
          client.println("<table>");
          client.println("<tr><td class=\"l\"></td>");
          client.println("<td class=\"t\">Curr</td>");
          client.println("<td></td>");
          client.println("<td class=\"t\">Min</td>");
          client.println("<td></td>");
          client.println("<td class=\"t\">Max</td></tr>");
          // 2nd row
          client.println("<tr><td>External</td>");
          client.print("<td>");
          client.print(extTemp,(uint8_t)2);
          client.println("</td>");
          client.println("<td></td>");
          client.print("<td>");
          client.print(extTempMin,(uint8_t)2);
          client.println("</td>");
          client.println("<td></td>");
          client.print("<td>");
          client.print(extTempMax,(uint8_t)2);
          client.print("</td>");
          client.println("<td></td></tr>");
          // 3rd row
          client.println("<tr><td>Internal</td>");
          client.print("<td>");
          client.print(intTemp,(uint8_t)2);
          client.println("</td>");
          client.println("<td></td>");
          client.print("<td>");
          client.print(intTempMin,(uint8_t)2);
          client.println("</td>");
          client.println("<td></td>");
          client.print("<td>");
          client.print(intTempMax,(uint8_t)2);
          client.println("</td>");
          client.println("<td></td></tr></table>");

          // print google chart api url
          client.println("<p>Temperature history chart </p>");
          client.print("<img alt=\"Temp history chart\" src=\"http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=t:");
          // data here !!
          //internal
          for( int i = 0; i < tempHistoryElem; i++)
          {
            client.print(intTempHistory[i]+50,(uint8_t)2);
            if(i<tempHistoryElem-1){
              client.print(",");
            }
          }
          client.print("|");
          //external
          for( int i = 0; i < tempHistoryElem; i++)
          {
            client.print(extTempHistory[i]+50,(uint8_t)2);
            if(i<tempHistoryElem-1){
              client.print(",");
            }
          }          
          client.print("&chco=FF0000,0000FF&chdl=Int|Ext&chxt=x,y&chxl=");
          client.print("0:|");
          //-12|-11|-10|-9|-8|-7|-6|-5|-4|-3|-2|-1|
          for( int i = 0; i < tempHistoryElem; i++){
            client.print("-");
            client.print(tempHistoryElem-i);
            client.print("|");
          }
          client.print("1:|-50|-40|-30|-20|-10|0|10|20|30|40|50&chg=0,50,1,0\">");
          
         
          // temperature history
          client.println("<p>Temperature history values </p>");
          client.println("<table><tr>");
          client.println("<td class=\"l\">Hours ago </td>");
          for( int i = 0; i < tempHistoryElem; i++)
          {
            client.print("<td class=\"t\"> -");
            client.print(tempHistoryElem-i);
            client.println("</td>");
          }    
          client.println("</tr><tr>");
          client.println("<td>Int </td>");
          for( int i = 0; i < tempHistoryElem; i++)
          {
            client.print("<td class=\"t\">");
            client.print(intTempHistory[i],(uint8_t)2);
            client.println("</td>");
          }
          client.println("</tr><tr>");
          client.println("<td>Ext </td>"); 
          for( int i = 0; i < tempHistoryElem; i++)
          {
            client.print("<td class=\"t\">");
            client.print(extTempHistory[i],(uint8_t)2);
            client.println("</td>");
          }
          client.println("</tr></table>");
 
          
          // html footer
          client.println("</body></html>");

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } 
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
      messageClear();
    }
    client.stop();
  }
}

Right ... I'm interfacing with a couple devices over 232 ... and was hoping to have a kind of setup page that would allow the user to set there own commands ... and what to do when commands come in ... I looked at the Xport stuff ... i might be wrong but it seems like you have to interface with there web page ... and you can talk to the arduino over a different port ???

thx GordonEndersby for your code post because i'm interested in monitoring the temp in a graph so please when you finish your work dont forget to post it ....
there is an example sketch ethershield_web_temp it work good but it doesnt show a permanent temp, every time i must press on get temp to view the current temp and there is no history ....any ideas?
thx for u all

Sorry, I was just demonstrating that you can squeeze a lot of html output on to a 328.
If I understand what you are asking.

If you want forms and form handlers on the arduino so you can pass actions or commands over to be handled by the arduino. Its just a matter of handling the request in code on the arduino.
You can capture and interpret the value pairs passed in the query string.

So for example:
http://myipaddress?led=on

In the request look for the value pair led=on and turn on an led.

This request could either be entered by you on the address bar of a browser or as a result of a web page containing a form that was served up by the arduino.

Theres are some simple examples with the nuelectronics ehternet boards.
http://www.nuelectronics.com/estore/?p=12.
They wont work with the Arduino Ethernet board but you canget some ideas on how to do it by adapting there code to work with the arduino board.

Gordon

Thanks ...

I'm going to just push the data to my web server ... Its a bummer because now I have another piece involved but you do what you have to do ....

Thanks again

I would be inclined to suggest you don't give up on using the shield idea until you've tried it out.

You might be surprised how far you can get.

--Phil.

I've been working on it ... and the arduino seems to do weird things when I get even close to filling the memory up ... ???

If you are using many strings--which I suspect you probably are in order to generate your page--you want to make sure they are stored in PROGMEM and not RAM. If you are trying to use too much RAM you will get odd behaviour like you are describing.

--Phil.

you are right .... how do I tell it where to store those ?

Thanks

Here is a previous post of mine where I posted some code which uses PROGMEM strings and copies them into a temporary buffer as needed:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1233535986/7#7

Try to get it working on the Arduino. If it doesn't, try a Sanguino. sanguino.cc. It's basically an arduino that uses an atmega 644p, which has 64k of flash and 4k of RAM. At least I think its 4K, not sure off the top of my head.