-->
Page 1 of 1

Help integrating ESP8266 functionality into Arduino sketch

PostPosted: Mon Aug 06, 2018 2:04 pm
by glassreef
I have the code shown below, on a SP8266 NodeMCU V.1E The code works very well. It just passes a request to my website and passes 2 parameters to a .php file. The .php file sends me an email.

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: Select all// 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
    }
 }

Re: Help integrating ESP8266 functionality into Arduino sket

PostPosted: Thu Aug 09, 2018 5:40 am
by schufti
since Mega2560 (Atmel AVR) is not esp8266 based it won't understand/support WiFi commands...