My problem is that, this Esp8266 functionality is meant to be added to a large sketch on an Arduino Mega 2560. When a particular error occurs on the Mega, the code on the ESP should be executed after 2 string params are passed for inclusion in the email.
Can someone tell me if this is possible? If yes, perhaps a short explanation? BTW: I did do a lot of searching for an answer but, all I could find was a lot about using AT commands and I don't think that can be used for my problem.
Thanks.
// Code taken from various examples online
// Resides on NodeMCU V.1
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "MYSSID";
const char* password = "MYPWD";
void setup () {
Serial.begin(9600);
WiFi.begin(ssid, password);
delay(2000);
if (WiFi.status() != WL_CONNECTED) {
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
String dataline = "http://www.MYSITE.com/alarm_email.php?errnum=069&error=Bad Error";
bool httpResult = http.begin(dataline);
int httpCode = http.GET();
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
}
}