Forum >Triggered Email
Triggered Email

So, I'm using an Arduino UNO, and DFRduino Ethernet Shield V2.1 to attempt to send an email on a trigger.
I'm using a DHT11 humidity and temperature sensor on digital pin 4, and the purpose is to, when the temperature reads 85º (which is also recorded in the serial monitor) that the program makes an email saying "the temperature is greater than 85º Fahrenheit!"
I have used a choreo from Temboo and modified it a little bit to make sure that the trigger is when the fahrenheit reading is >= 85º.
The trigger works perfectly fine. It's just that as soon as the emailing portion of it begins, it fails saying that the arduino was trying to send something that the server couldn't understand.
I'm really a beginner at all of this so I'd appreciate as much help as I can get,
Thank you!
I'm including the text from the codes below in separate sections VVV
Error message:
sendMail.ino:
TembooAccount.h:
I'm using a DHT11 humidity and temperature sensor on digital pin 4, and the purpose is to, when the temperature reads 85º (which is also recorded in the serial monitor) that the program makes an email saying "the temperature is greater than 85º Fahrenheit!"
I have used a choreo from Temboo and modified it a little bit to make sure that the trigger is when the fahrenheit reading is >= 85º.
The trigger works perfectly fine. It's just that as soon as the emailing portion of it begins, it fails saying that the arduino was trying to send something that the server couldn't understand.
I'm really a beginner at all of this so I'd appreciate as much help as I can get,
Thank you!
I'm including the text from the codes below in separate sections VVV
Error message:
Code: Select all
(the serial monitor just stops here. Sometimes, it'll just constantly throw out the DHT readings endlessly w/o delay)DHCP:OK
DHTxx test!
Setup complete.
Sensor: 398
Failed to read from DHT sensor!
Sensor: 294
Humidity: 83.00 %
Temperature: 31.00 *C 87.80 *F
Heat index: 41.96 *C 107.53 *F
Triggered! Calling SendEmail Choreo...
HTTP_CODE
400
Bad Request
Content-Type: text/html; charset=iso-8859-1
Date: Thu, 11 Aug 2016 02:45:54 GMT
Vary: Accept-Encoding
Content-Length: 318
Connection: Close
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at akitak9821.temboolive.com Port 443</address>
</body></html>
Sensor: r:
Failed to read from DHT sensor!
Sensor: r:
Humidity: 84.00 %
Temperature: 30.00 *C 86.00 *F
Heat index: 38.84 *C 101.91 *F
Trig
sendMail.ino:
Code: Select all
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information
#include "DHT.h"
#define DHTPIN 4 // what digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
#define warnPin 7
byte ethernetMACAddress[] = ETHERNET_SHIELD_MAC;
EthernetClient client;
// The number of times to trigger the action if the condition is met
// We limit this so you won't use all of your Temboo calls while testing
int maxCalls = 10;
// The number of times this Choreo has been run so far in this sketch
int calls = 0;
int inputPin = A4;
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Serial.print("DHCP:");
if (Ethernet.begin(ethernetMACAddress) == 0) {
Serial.println("FAIL");
while(true);
}
Serial.println("OK");
delay(5000);
// Initialize pins
pinMode(inputPin, INPUT);
Serial.println("DHTxx test!");
pinMode(warnPin, OUTPUT);
digitalWrite(warnPin, LOW);
dht.begin();
Serial.println("Setup complete.\n");
}
void loop() {
int sensorValue = analogRead(inputPin);
Serial.println("Sensor: " + String(sensorValue));
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");Serial.print(h);Serial.print(" %\n");
Serial.print("Temperature: ");Serial.print(t);Serial.print(" *C ");Serial.print(f);Serial.print(" *F\n");
Serial.print("Heat index: ");Serial.print(hic);Serial.print(" *C ");Serial.print(hif);Serial.println(" *F\n");
int val;
if (f >= 85)
{
digitalWrite(warnPin, HIGH);
delay(200);
}
else{
digitalWrite(warnPin, LOW);
}
delay(5000);
if (f >= 85) {
if (calls < maxCalls) {
Serial.println("\nTriggered! Calling SendEmail Choreo...");
runSendEmail(sensorValue);
calls++;
digitalWrite(warnPin, HIGH);
delay(200);
} else {
Serial.println("\nTriggered! Skipping to save Temboo calls. Adjust maxCalls as required.");
digitalWrite(warnPin, LOW);
}
}
delay(250);
}
void runSendEmail(int sensorValue) {
TembooChoreo SendEmailChoreo(client);
// Set Temboo account credentials
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
// Set Choreo inputs
String FromAddressValue = "Arduino";
SendEmailChoreo.addInput("FromAddress", FromAddressValue);
String UsernameValue = "[email protected]";
SendEmailChoreo.addInput("Username", UsernameValue);
String ToAddressValue = "[email protected]";
SendEmailChoreo.addInput("ToAddress", ToAddressValue);
String SubjectValue = "ARDUINO WARNING";
SendEmailChoreo.addInput("Subject", SubjectValue);
String PasswordValue = "eenxdsshzexdgyum";
SendEmailChoreo.addInput("Password", PasswordValue);
String MessageBodyValue = "Temperature is above 85º";
SendEmailChoreo.addInput("MessageBody", MessageBodyValue);
// Identify the Choreo to run
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
// Run the Choreo
unsigned int returnCode = SendEmailChoreo.run();
// Read and print the error message
while (SendEmailChoreo.available()) {
char c = SendEmailChoreo.read();
Serial.print(c);
}
Serial.println();
SendEmailChoreo.close();
}
TembooAccount.h:
Code: Select all
/*
IMPORTANT NOTE about TembooAccount.h
TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h,
and copy this content into it.
*/
#define TEMBOO_ACCOUNT (((((not including this in the forum for security)))))
#define TEMBOO_APP_KEY_NAME "TembooApp" // Your Temboo app key name
#define TEMBOO_APP_KEY (((((not including this in the forum for security)))))
#define ETHERNET_SHIELD_MAC { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
/*
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the
main .ino file without worrying that you forgot to delete your credentials.
*/
2016-08-12 00:52:51 Hello
Sorry, I have not played the project you mentioned, I will do a test and any progress will be updated here.
Wendy.Hu
Sorry, I have not played the project you mentioned, I will do a test and any progress will be updated here.
