Webduino outputting a large file

142 views
Skip to first unread message

Coriolan Weihrauch

unread,
Jul 14, 2013, 4:52:34 AM7/14/13
to webd...@googlegroups.com
Hi,

I've read the posts on this group and I'm sorry to hear about the Webduino considered obsolete. With growing code, I was facing frequent bugs on the Arduino ethernet (ATmega328) but on my Mega 2560 it works great :)

I've designed a single-page web interface for reading sensors and controlling relays. The page is around 32kB, currently stored on my computer and accessing the Arduino using ajax.

As I have plenty of space left on the Mega2560 (around 150k) I'd like to shift the web interface onto the arduino as well.
It's (now) a monolithic page which doesn't need to be parsed or otherwise processed. It's a single file with embedded CSS/JS/images. I just need to save it in flash and read it out.

My question is, do you have any suggestions on how to do that ? I've tried something like this:
 server << "<!DOCTYPE html> <html> ..32k of code here.. </html>";
which complied after some tuning but doesn't run (nothing happens anymore, no serial console, no pings...). I've tried splitting the code into multiple lines, but that doesn't seem to help either :(

I guess the system is overwhelmed by the amount of data and hope there's some way to do this.

Thanks for any suggestions!
Regards,
Coriolan

Ben Combee

unread,
Jul 16, 2013, 2:34:57 AM7/16/13
to webduino
This is what the WebServer::printP method is for. This outputs a large string directly from Flash. The string has to be declared using the form

P(largeString) = "This is about 30K of text";

P() is a macro that declares the string with the right attributes for it to live solely in flash memory. printP knows how to interpret that flash memory pointer to output the string without needing an intermediate copy of it in RAM, which is very limited on the Arduino boards.


--
You received this message because you are subscribed to the Google Groups "Webduino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webduino+u...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webduino.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Konsarna

unread,
Oct 22, 2013, 5:12:04 AM10/22/13
to webd...@googlegroups.com
I have a query regarding the syntax of     P(largeString) = "This is about 30K of text";

Well the problem is that I am trying to write a code that will display measurements from a  digital temp sensor (ds18b20)and when the temp is e.g.30 then some buttons will appear.For that reason I am using the example from Web_AjaxBuzzer of course with changes.I am using the P(largeString) and so far I ve written html code that has to do with the appearence of the page (all the styles can be displayed and the letters of paragraphs )but when it comes to display the variables nothing happens its empty so I guess I don't know how to display the variables or write commands like:

if tempC>30.....,
sensorsReading,
tempC=sensors.getTempC(insideThermometer)
in the  P(largeString)=......is it imposseble to write these kind of things in it??I guess no but hao can I make them visible?

thank you in advance

Ben Combee

unread,
Oct 22, 2013, 12:23:55 PM10/22/13
to webduino
If you're using a P() declared string, that's stored in the Flash ROM of the ATMega chip, so it's not writable memory.
I'd suggest splitting your HTML into parts, so you can write the first part, then write the variable value, then write the rest.

Konsarna

unread,
Oct 22, 2013, 1:12:38 PM10/22/13
to webd...@googlegroups.com
Thanks a lot I was trying to find out how P is syntaxed but there is not much stuff in Internet.Although I find it strange because in the example of Web_AjaxRGB_mobile there is some code in
 P (message)=.... "$(document).ready(function(){ $('#red, #green, #blue').slider; $('#red, #green, #blue').bind( 'change', function(event, ui) { jQuery.ajaxSetup({timeout: 110}); /*not to DDoS the Arduino, you might have to change this to some threshold value that fits your setup*/ var id = $(this).attr('id'); var strength = $(this).val(); if (id == 'red') $.post('/rgb', { red: strength } ); if (id == 'green') $.post('/rgb', { green: strength } ); if (id == 'blue') $.post('/rgb', { blue: strength } ); });});"

 I am working with the Web_AjaxRGB_mobile example the one with the buttons.I want to make it work like getting sensor measurements and after a value it will display the buttons that can happen of course no i think I am using the right example..
so what you suggest is still using the P(message) but break it into pieces like 

  P(message) = 
"<!DOCTYPE html><html><head>"
  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
  "<meta http-equiv=\"refresh\" content=\"10\">"
 .........................
serverprintP(message)...

/*then the code for displaying the ds18b20 temp variable/*
sensors.requestTemperatures();
printTemperature(insideThermometer);
float tempC = sensors.getTempC(insideThermometer);
(tempC);

if tempC>20{ //the other piece of P (message) now for displaying the buttons//
 P (message)=
"$(document).ready(function(){ $('#red, #green, #blue').slider; $('#red, #green, #blue').bind( 'change', function(event, ui) { jQuery.ajaxSetup({timeout: 1000}); /*not to DDoS the Arduino, you might have to change this to some threshold value that fits your setup*/ var id = $(this).attr('id'); var strength = $(this).val(); if (id == 'red') $.post('/remote', { red: strength } ); if (id == 'green') $.post('/remote', { green: strength } ); if (id == 'blue') $.post('/remote', { blue: strength } ); });});"
  "</script>"
    "<div class=\"ui-body ui-body-a\">"        
      "<div data-role=\"fieldcontain\">"
        "<h2>led</h2>"
"<label for=\"flip-3\">diakoptis 1</label>"

}.......

of course the above is just a quick version of what I am going to write.Have I understand well?
thanks



Konsarna

unread,
Oct 25, 2013, 12:17:10 PM10/25/13
to webd...@googlegroups.com
hi again,
well,with the use of some P(messages) inside the GET part of the  Web_AjaxRGB_mobile sketch I can now see both the measurements of my temp sensor and after a certain value the buttons are displayed as well.My problem now is that  I can turn on  and off a led  only during the time before the refresh.As a result the led can still be on but the screen shows that it is in 0 (off ).I assume the problem is the line:

 "<meta http-equiv=\"refresh\" content=\"10\">" //refresh 

I use for the refresh of the sensor . I tried to put it in the end of  my code so that it will be refreshed only for the sensor part and not for the buttons but still the same.Is there any command that stops locally the refresh so that only one part will be the same and the other (sensor) will be renewed every 10 sec ?I think that's my solution...
thanks again!!
Reply all
Reply to author
Forward
0 new messages