looking for ideas ...

Hello,

I’m working on a project with a Mega 2560 which reads a number of SHT71 temperature/humidity sensors. It also runs a web server so that the current values can be read from a browser. I’m also posting the values to sen.se on a regular basis.

So - the server code on the Arduino is getting more complex. I’m sending the HTML from the Arduino using println statements such as …

client.println(" Arduino Web Server <meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”> ");

which, as the lines get longer is getting more and more tedious.

I’m actually developing the HTML code using Dreamweaver on a Mac and I’d love to run Ajax-type techniques from the Arduino - but the idea of copy/pasting the code from the Mac to Arduino and then going through the HTML and escaping all the quotes and so on is a bit daunting.

So, I’m wondering if anyone has any cunning ideas about how to “println” large chunks of character strings without worrying about them containing cr/lf, quotes, etc.?

I’ve thought of using a “println-safe” code obfuscator - but I doubt if such a beast exists.

Many thanks in advance for any ideas/help/pointers
G8VKV

It's amazing how the articulation of a problem often suggests a solution.

I've now got a bash script that will escape the quotes and remove EOLs - so hopefully that will do the trick.

Any other thoughts still appreciated tho'

I foresee RAM shortage (if you are using an UNO so consider this a warning :wink:

client.println(" Arduino Web Server <meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”> ");

The Arduino has little only 2K RAM so all the spaces that are not necessary can be removed. Further consider removing HTML tags that are not strictly needed. The above string could become as short as:
client.println(“Arduino Web Server”);

Further you might move fixed strings to progmem (search the forum/playground for the how) to save RAM.

Moving HTML 1 to 1 from dreamweaver to Arduino directly creates long strings, so you could even consider storing them on a SDCARD…

If you have the ethernet shield with the SC card reader on that, you can store section of the web page there, in separate files. When you need to send a web page, you can read the fixed stuff from file(s) on the SD card, mixing in dynamic stuff (sensor values, etc.) as required.

Hi,

Thanks for the responses. I’d not thought about using the SD card, but that would be an interesting thing to try - also removing redundant tags.

I hadn’t even bothered worrying about RAM - so thanks for that! I’m not sure how much it’s going to be an issue, I’m using a Mega 2560, which has 8K (I think) of RAM - also, would it be the case that, for example …

client.println(" some long literal string ");

… takes up RAM?

The bash command to clean up, which seems good so far, is …

tr -d ‘\n’ < arduino.html | sed -e ‘s/"/\"/g’ -e ‘s/ */ /g’ | tr ‘\t’ ’ ’ > ardclean

… but I’m sure there are many other ways.

Cheers
G8VKV

would it be the case that, for example ..

client.println(" some long literal string ");

... takes up RAM?

The " some long literal string " part takes up SRAM. The code itself does not.

Right - my brain has now latched into its proper state and I understand - I'd forgotten that it's SRAM and not RAM.

So I guess it would be wise to re-jig my string storage ideas, just to be on the safe side. I could use the SD slot, but maybe that'd be a bit more hassle.

Cheers G8VKV

Another approach is to handle the HTML generation on the computer with JSP, PHP, ASP or whatever, and have it call a script to pull the data from the Arduino via serial - separating out the data (on arduino) from presentation (in the HTML templates).

Or have the arduino send the data to a file on the computer regularly somehow, just include that file in the HTML generation when wanted - that way the Arduino doesn't need to be up and running for the webpage to work. Best to timestamp the data.

You could contemplate sending the data to a local database, and then the HTML generation can pick out any data past or present... All getting more complex of course :)