Go Down

Topic: A way to smoothen this sketch? (Read 1 time) previous topic - next topic

compiling

Jun 19, 2019, 05:09 pm Last Edit: Jun 19, 2019, 06:48 pm by compiling
So been busy with Arduino lately, use of home automation by making a server.
Did a few sketches with uno, ethernet shield and SD but found it was to slow reacting.
Got myself a mega and started without the use of the SD but things got a bit out of hand and out of memory, so used the (F ) to save sram memory to flash, this however slowed things down a bit, not as much as reading from SD but still.
My site is refreshing every 2 seconds and on sram only the site changes pretty smooth, now on flash it's not that smooth anymore.
On sram only it used up 85% (edited more lateron so probebly would be more now.
Arduino is warning for low on memory but I think it looks at the percentage, not the left bytes.
Therefor the memory warning with an uno is at the same procent as the mega whilst the mega has lots of more bytes left, wil it really get bad?
Well I changed a lot to flash, not knowing it would slow down.
Anyone a suggestion to smoothen this up?

maybe go with ajax? I rather not start all over again...

Aj, message is over 9000characters, how do I upload?
Do it in 2 times?

Hard to explain the sketch, too much going on

/* sketch, webserver without sd for use on mega + ethernet shield,
  for in my pumphouse, controling electric dogfence, electric fences, irrigation and pumps (4 subjects)
  making 4 subjects with buttons to show contents of each subject (and an INDEX button to go back), hiding the other subjects.
  with checkboxes to see some activity
  contents consist of switching relais, reading switches and analog inputs with different colors for on and off, etc
  also use of colored boxes and buttons showing turn on when it is turned off etc
*/
 

compiling

even in half it exceeds 9000 characters  :smiley-confuse:

compiling

there are more than 1000 lines, 27650 bytes (10%) program storage and 4551 bytes (55%) dynamic memory
should I forget about posting it here?

compiling

So maybe I can just show what I put in flash memory, hoping to hear what lines I could better leave out...
BTW it's not that bad but a little smoother would be nice...
All the text actually on the site are written in sram, not in flash

Code: [Select]

  // Open serial communication at a baud rate of 9600
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print(F("server is at "));
  Serial.println(Ethernet.localIP());
}

// Display dashboard page with on/off buttons for showing several "pages" where to control relays and more
void dashboardPage(EthernetClient &client) {
  client.println(F("<!DOCTYPE html>"));
  client.println(F("<html>"));
  //refreshes the page without keeping the commands so its possible to control with several clients at the same time
  client.println(F("<meta http-equiv=\"refresh\" content=\"2;url=http://192.168.8.19/\">"));
  //make it fit for mobile
  client.println(F("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head>"));
  client.println();
  client.println(F("<head>"));
  client.println(F("<title>Pump House</title>"));
  client.println(F("</head>"));
  client.println(F("<body>"));
  client.println(F("<body style=background-color:BLACK>"));
  client.println(F("<center>"));

  client.println("<h1>Pump House</h1>");
  client.println("<hr />");

  client.println(F("<style>"));
  //boxes and fonts (sizes) made to look good on iPhone 5s
  //black boxes
  client.println(F(".IO_boxZ1 {float: left;margin: 0 5px 5px 0;border: 4px solid black;padding: 0 5px 5px 5px;width: 124px;}"));
  client.println(F(".IO_boxZ2 {float: left;margin: 0 5px 5px 0;border: 4px solid black;padding: 0 5px 5px 5px;width: 124px;height: 160px;}"));
  client.println(F(".IO_boxZ3 {float: left;margin: 0 5px 5px 0;border: 4px solid black;padding: 0 5px 5px 5px;width: 124px;height: 270px;}"));
  client.println(F(".IO_boxZ4 {float: left;margin: 0 5px 5px 0;border: 4px solid black;padding: 0 5px 5px 5px;width: 124px;height: 170px;}"));
  //red boxes
  client.println(F(".IO_boxR1 {float: middle;margin: 0px 0px 0px 0px;border: 3px solid Maroon;padding: 5px 0px 70px 5px;width: 294px;}"));
  client.println(F(".IO_boxR2 {float: middle;margin: 0px 0px 0px 0px;border: 3px solid Maroon;padding: 5px 0px 180px 5px;width: 294px;}"));
  client.println(F(".IO_boxR3 {float: middle;margin: 0px 0px 0px 0px;border: 3px solid Maroon;padding: 5px 0px 290px 5px;width: 294px;}"));
  client.println(F(".IO_boxR4 {float: middle;margin: 0px 0px 0px 0px;border: 3px solid Maroon;padding: 5px 0px 190px 5px;width: 294px;}"));
  //fonts and colors
  client.println(F("h1 {font-size: 140%;color: DarkSeaGreen;margin: 0px 0 0px 0;}"));
  //for OFF
  client.println(F("h2 {float: right; font-size: 90%;color: YELLOW;margin: 5px 0 0px 0;}"));
  //for ON
  client.println(F("h3 {float: right; font-size: 90%;color: RED;margin: 5px 0 0px 0;}"));
  //normal fonts
  client.println(F("h4 {float: left; font-size: 90%;color: DarkSeaGreen;margin: 5px 0 3.8px 0px;}"));
  //small font bottom
  client.println(F("h5 {font-size: 70%;color: #737373;margin: 0 0 0 0}"));
  //for numbers
  client.println(F("h6 {float: right; font-size: 90%;color: YELLOW;margin: 5px 0 5px 0;}"));
  client.println(F("h7 {font-size: 110%;color: RED;margin: 5px 0 0px 0;}"));
  //to make spaces
  client.println(F("h8 {font-size: 90%;color: Darkslategrey;margin: 5px 0 0px 0px;}"));
  client.println(F("h9 {float: left; font-size: 90%;color: Darkslategrey;margin: 5px 0 5px 0px;}"));
  //for OPEN
  client.println(F("h0 {float:right; font-size: 110%;color: #00ff00;margin: 0px 0 0px 15px;}"));

  client.println(F("p, form, button {font-size: 80%;color: #252525;}"));
  client.println(F("p, form, .IO_boxZ1 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxZ2 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxZ3 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxZ4 {background-color:Darkslategrey;}"));
  //only nessesairy if next 4 boxes have an other color
  client.println(F("p, form, .IO_boxR1 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxR2 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxR3 {background-color:Darkslategrey;}"));
  client.println(F("p, form, .IO_boxR4 {background-color:Darkslategrey;}"));
  client.println(F("</style>"));
 
//and then at the end of void

 client.println(F("</body></html>"));

//and totaly at the end

 Serial.println(F("client disonnected"));

PaulS

there are more than 1000 lines, 27650 bytes (10%) program storage and 4551 bytes (55%) dynamic memory
should I forget about posting it here?
You should read the stickies at the top of the forum which show you how to properly post code, even when the code exceeds the 9000 character limit.
The art of getting good answers lies in asking good questions.

compiling

Hi PaulS,

I thought putting it inbetween code-tags was the way to do it but then I get this 9000 character message.
I did read the sticky btw. :)
What am I missing ?

PaulS

#6
Jun 20, 2019, 04:49 pm Last Edit: Jun 20, 2019, 04:50 pm by PaulS
Quote
What am I missing ?
Apparently, the fact that you can use the Reply button (NOT the quick reply field), and there will be a link (yeah, I know it hardly looks like a link. That's not my fault) called Attachments and other options that will allow you to attach your code.
The art of getting good answers lies in asking good questions.

compiling

Thanks,
sketch in attachment.

wildbill

You apparently have a little under half your RAM available so if you're convinced use of flash is slowing you down, why not try a version with all (or some of) the F macro usage removed.

Don't forget that some of the the "free" RAM is going to be used by your variables though.

Also, your use of Strings will become increasingly risky, the less free RAM is available for the heap.

compiling

Thanks, I'll try that,
Not quite finished with this sketch though, wanna add an automatic timer to automate the irrigation, will take some ram too...

WaitSome

#10
Jun 30, 2019, 05:18 pm Last Edit: Jun 30, 2019, 05:20 pm by WaitSome
Not quite finished with this sketch though, wanna add an automatic timer to automate the irrigation, will take some ram too...
I did not look at your code, but it sounds to me like you are trying to get the base to do everything. I have a similar kind of IoT system but using nrF24l01 radios. I made the Sensors "smart" so they react to controls from the base but mostly they handle the node's object (Swamp, pump, sensors etc) . You need to distribute the control code.

For instance, the swamp cooler runs on a Nano and it gets a time signal from the Base (Mega with RTC) every 30-minutes so it can keep a pretty reasonable idea of time with a seconds-pump. This is included in every Node.

Code: [Select]

  ///////////////////////////////////////////
  bool timePumpSecSM(uint32_t &secSM) {
    if (millis() - timePumpMillis > timePumpTIME) {
      ++secSM;
      secHMS(secSM);  // This locally breaks it into Hours, Mins and Secs
      timePumpMillis = millis();
      return true;
    } else {
      return false;
    }
  }


From there, the swamp-Nano has all of the code to run the pump, cycle the fan, purge the tray etc. It also changes set-temp between periods like, "Sleep," "Morning" etc. It gets the current temp sent to it by the base from an appropriate smart-temp sensor in each room. It (swamp Nano) decides what time of day it is and which temp to use.

Consequently the base-Mega as has a tiny amount of code as all of the heavy-lifting control is in each Node. This also makes it simple to add more Nodes as they are "smart" for their purpose, so the Base needs to know little more than their ID to send the the time occasionally and any other data they may need.

The base does not need to know or understand the data it is sending. Each Node send data about every minute or so depending on the need. The tank level only needs sending every hour, the temp every 30-seconds. All Nodes have a "SendStatus" command which is triggered by a command from the base if I want to know something between those times.

Adding more code to your base is going to hit a wall soon. :)

I suspect you should bite the bullet and start again with an open ended design. But -- I have been wrong before. :)

Go Up