Streamlining / Efficiency / Optimisation - Help Required Please

Hi,

I’m building a homebrew monitor which monitors a cabinet where beer is being fermented.
I have two DS18B20 probes and an additional DHT11 sensor (which has been commented out of my code for the moment).

One DS18B20 hangs in the cabinet monitoring air temperature and the other is suspended in the beer to monitor the liquid wort temperature.

Upon a reading that is too high or too low, a text message is sent via a SIM900 module.
All the while, the program writes a log of temps and times via a datalogging module.
I’ve also included the ability to recieve SMS messages with instructions but I’m not yet happy with that but I’ll work on that part later.

I’ve got my code to the point where it’s doing what I want for now but it’s not very elegant and I bet it’s bloated in places. It currently uses 89% of Program Storage and 70% of Dynamic Memory on an Atmega328.

What I’d like to add next is the ability to upload the temperature data to my website or home server via GPRS as well but I’m lacking the room on the arduino.

As you can see, my code is very simplistic (I’m not the best programmer) but I’d like some advice on what else I might be able to do to make more space if possible. I’ve used the F macro where possible and have now eliminated all non-essential Serial.Print debugging messages.

If I try and include the GSM.h library at this point, it takes the RAM way over to near on 102%

Any ideas on where I could save some space would be appreciated please.

Sorry, I can’t post the code into a post. Won’t let me. 9000 Character limit on posts :S

RoomDataLogger-GSM.ino (8.81 KB)

      char message[120];
      //int Year = timestamp.year();
      //int Month = timestamp.month();
      int Day = timestamp.day();
      int Hour = timestamp.hour();
      int Minute = timestamp.minute();
      //int Second= timestamp.second();
      
      sprintf(message, "%02d:%02d", Hour,Minute);

How many hours in a day in your world? How many seconds in an hour?

Can you count? 2 + 1 + 2 + 1 is no where near 120.

Use of the String class is a bad idea, if you care about memory. Make message (smaller and) static, and return a pointer to char.

void sendMessage(String smsMessage){

Another waste of memory. There is no reason to pass a global object to the function, whether that object is a String or an array of chars. There is no reason to make the object a String, either.

      do{
          // if there are data in the UART input buffer, reads it and checks for the asnwer
          if(SIM900.available() != 0){   
              response[x] = SIM900.read();
              //Serial.print(response[x]);
              x++;
              // check if the desired answer is in the response of the module
              if (strstr(response, expected_answer) != NULL)   
              {
                  answer = 1;
              }
          }
          // Waits for the asnwer with time out
      }
     
  
  
      while((answer == 0) && ((millis() - previous) < timeout));

The white

space after

the } is a waste.

Use a while statement, not a do/while.

      Serial.println("END OF AT SEND");

Where did the F() go?

PaulS: How many hours in a day in your world? How many seconds in an hour?

Can you count?

Nice, cheers!