emailing my sensor readings

I am still new to programming my Arduino, but think I have made some progress. I have a location where if the temperature gets too high, I could lose some electronics equipment. So, for some piece of mind, I have written this code to send me an alert if the A/C fails and the temperature starts to climb. It will also kill power to the equipment. I have been able to have it email me successfully, but now want to have it email me my sensor readings once per day and I don't know how to put that in the email. If you look at the code you'll see an int for count. Basically, I am taking a reading every 60 seconds, so when the count gets to 1440, I want it to send me an email with the sensor readings. So far all the code has been tested and works, but now I am stuck.

I also just discovered that the count isn't incrementing....

I am using an Arduino UNO, an Ethernet Shield 2, DHT22, plus a relay

Any help would be appreciated.

// High temp warning unit for AC rack at my place

// Libraries
#include <DHT.h>;
#include <SPI.h>;
#include <Ethernet2.h>;

// Constants
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 90.0;
// name constant for the pin sending to the relay unit
const int relayPin = 7;

// Variables
float hum;  //Stores humidity value
float temp; //Stores temperature value
float highTemperature = 0.0;
float lowTemperature= 1000.0;
float avgTemperature = 0.0;
int count = 1;

// Arduino network information
byte mac[] = {  *, *, *, *, *, * };
EthernetClient client;
char smtpServer[] = "mail.smtp2go.com";

void setup(){
  // open a serial connection to display values
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
  Serial.begin(9600);
  dht.begin();
  setupComm();
}

void loop(){
  //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.print(" Celsius");
    float fahrenheit = (temp*1.8)+32;
    Serial.print(", Fahrenheit: ");
    Serial.println(fahrenheit);

    // Calculating and printing the high, low, and average temps
    if(highTemperature < fahrenheit){
      highTemperature = fahrenheit;
    }

    if(lowTemperature > fahrenheit){
      lowTemperature = fahrenheit;
    }

    if(count = 1){
      avgTemperature = (lowTemperature + highTemperature) / 2;
    }
    else{
      avgTemperature = (fahrenheit + avgTemperature) / 2;        
    }
    Serial.print("High temperature is: ");
    Serial.println(highTemperature);
    Serial.print("Low temperature is: ");
    Serial.println(lowTemperature);
    Serial.print("Average temperature is: ");
    Serial.println(avgTemperature);
    Serial.println();

// insert email code here with low, high, and avg temperatures if count is at a certain baseline
    
    count++;
    
  // if the current temperature is higher than the baseline
  // turn off power to the Studio Technologies units and send an email
  if(fahrenheit > baselineTemp){
    digitalWrite(relayPin, HIGH);
    email("The air conditioner unit is failing.");
    for (;;) // Now just loop forever until someone shows up to reset it.
      ;
  } 
  /* Just for testing purposes, disable this code when in use
    else {
    digitalWrite(relayPin, LOW);
    }
  */
  delay(60000);
}

//  ethernet shield connection init
void setupComm()
{
  Serial.println("Trying to connect");
  if (!Ethernet.begin(mac)){
    Serial.println("Failed to DHCP");
    // verifyng connection
    while(true);
  }
  delay(10000);
  // IP address is:
  Serial.print("IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}
// now I send email
bool email(char* text)
{
  bool success = false;
  Serial.println("Sending email...");
  if (client.connect(smtpServer, 2525)){            //2525 is SMTP Server port
    Serial.println("connected");
    delay(100);
    client.println("EHLO arduino");
    for(int i=0; i<999; ++i){
      if(client.read() > 0)
        break;
    }
    Serial.println("responded");
    client.println("AUTH LOGIN");                     //see "http://base64-encoder-online.waraxe.us/"
    client.println("*");                    //Type your username  and encode it
    client.println("*");                   //Type your password  and encode it</p>
    // Put your "from" email address here
    client.println("MAIL FROM:<*>"); //Seems you can write what you want here...
    for(int i=0; i<999; ++i){
      if(client.read() > 0)
        break;
    }
    client.println("RCPT TO:<*>");
    for(int i=0; i<999; ++i){
      if(client.read() > 0)
        break;
    }
    client.println("DATA");
    for(int i=0; i<999; ++i){
      if(client.read() > 0)
        break;
    }
    //Sender
    client.println("from: *"); //Sender address
    client.println("to: *");  //Receiver address
    client.println("SUBJECT: WARNING my place WARNING");
    client.println("");
    client.println(text);
    client.println(".");
    client.println("QUIT");
    for (int i = 0; i<999; ++i){
      if(i > 998){
        Serial.println("error: No response");
      }
      if(client.read() > 0)
        break;
    }
    success = true;
    client.println();
    Serial.println("end");
  }
  else {
    Serial.println("Failed");
    client.println("QUIT"); //Disconnection
  }
  client.stop();
  return success;
}
    if(count = 1){

On every pass through loop(), you assign 1 to count. Strange doing that in an if statement...

Look at the difference between = and ==.

You pass a variable to email() (nice job with the functions and meaningful names). Passing it a text string containing 1,440 values is going to result in a large string, containing a minimum of 2,880 characters, which is more SRAM that many Arduinos have.

Since the Arduino is wearing an ethernet shield, it could make a GET request to store each temperature value in a database. Then, you could plot the data, etc.

Bah, I fixed the ==

I completely missed that. Thank you.

The 1440 is simply a counter number in order to trigger sending and email with a string saying something like:

"High temp was 100.2, low temp was 85.6, avg temp was 92.1"

I just can't figure out how to include the sensor readings in the email().

I just can't figure out how to include the sensor readings in the email().

float loTemp = 85.6;
float hiTemp = 100.2;
float avTemp = 92.1;

char loStg[10], hiStg[10], avStg[10];

void loop()
{
   dtostrf(loTemp, 8, 2, loStg);
   dtostrf(hiTemp, 8, 2, hiStg);
   dtostrf(avTemp, 8, 2, avStg);
  
   char msg[80];
   sprintf(msg, "High temp was %s, low temp was %s, avg temp was %s", hiStg, loStg, avStg);

   email(msg);
}

Thank you very much, I will try this.

PaulS:

float loTemp = 85.6;

float hiTemp = 100.2;
float avTemp = 92.1;

char loStg[10], hiStg[10], avStg[10];

void loop()
{
  dtostrf(loTemp, 8, 2, loStg);
  dtostrf(hiTemp, 8, 2, hiStg);
  dtostrf(avTemp, 8, 2, avStg);
 
  char msg[80];
  sprintf(msg, "High temp was %s, low temp was %s, avg temp was %s", hiStg, loStg, avStg);

email(msg);
}