What is the minimalistic way of establishing proper communication between MEGA and ESP8266 modules of this board MEGA and ESP8266? I'm fighting with addressing board pins from ESP8266. Thank you.
//Arduino MEGA+WiFi ATmega2560+ESP8266 4Mb CH340G
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/* Set these to your desired credentials. */
const char *ssid = "XXX"; //Enter your WIFI ssid
const char *password = "PPP"; //Enter your WIFI password
int myLED = 14;
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/html", "<form action=\"/myLED_on\" method=\"get\" id=\"form1\"></form><button type=\"submit\" form=\"form1\" value=\"On\">On</button><form action=\"/myLED_off\" method=\"get\" id=\"form2\"></form><button type=\"submit\" form=\"form2\" value=\"Off\">Off</button>");
}
void handleSave() {
if (server.arg("pass") != "") {
Serial.println(server.arg("pass"));
}
}
void setup() {
pinMode(myLED, OUTPUT);
delay(3000);
Serial.begin(115200); //74880 , 115200
Serial.println();
Serial.print("Configuring access point...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.on ( "/", handleRoot );
server.on ("/save", handleSave);
server.begin();
Serial.println ( "HTTP server started" );
server.on("/myLED_on", []() {
digitalWrite(myLED, HIGH);
delay(300);
Serial.println("on");
handleRoot();
});
server.on("/myLED_off", []() {
digitalWrite(myLED, LOW);
delay(300);
Serial.println("off");
handleRoot();
});
}
void loop() {
server.handleClient();
}