I have a fairly large sketch running on a Mega2560. I would like the sketch to send out emails when error situations occur within the sketch. This would be done via the following code on a ESP8266-01
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "SSID";
const char* password = "Password";
//-------------------------------------------------------
// NEED TO GET THESE TWO VALUES FROM CODE ON ARDUINO
//
int paramOne = 78;
int paramTwo = 16;
//-------------------------------------------------------
String strOne = "errnum=";
String strTwo = "&error=";
void setup () {
strOne += paramOne;
strTwo += paramTwo;
Serial.begin(9600);
WiFi.begin(ssid, password);
delay(3000);
if (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
else {
Serial.println("Connected!!!");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; // declare an object of class HTTPClient
//
// fill in needed parameters
//
String dataline = "http://www.mytest.com/alarm_test.php?";
dataline += strOne += strTwo;
bool httpResult = http.begin(dataline); //specify request destination
// http.GET to send the email
int httpCode = http.GET(); //send the request
if(!httpResult){
Serial.println("Invalid HTTP request:");
Serial.println(dataline);
}
else
{
int httpCode = http.GET();
}
if (httpCode > 0)
{ // Request has been made
Serial.printf("HTTP status: %d Message: ", httpCode);
//String payload = http.getString();
//Serial.println(payload);
}
else
{ // Request could not be made
Serial.printf("HTTP request failed. Error: %s\r\n", http.errorToString(httpCode).c_str());
}
if (httpCode > 0) { //Check the returning code
//String payload = http.getString(); //Get the request response payload
//Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
//delay(30000); //Send a request every 30 seconds
}
I found pieces of this code at a couple different places. None of it was directly attributed to any one, so it was a little difficult for me to obtain any guiding info. I did manage to get the above code to work. Each time the ESP8266 is started an email is sent from my website to my mail address.
My question is; would someone mind explaining to me how I can send the 2 required integers (paramOne & paramTwo) from the Arduino Mega to the ESP8266? Then how would I trigger the ESP code to cause the email to be sent? A small amount of example code would be great. I am learning steadily, but at my age this Wifi stuff has still got me a little confused.
Thanks!

