Hi,
I have this code and I am trying to send an email through my router. But it seem like it try to send it via my 192.168.4.1 and not through my router at 192.168.0.1 or ????
#include <ESP8266WiFi.h>
#include "Arduino.h"
#include "src/EMailSender.h"
EMailSender emailSend("*******", "********");
WiFiServer server(88);
IPAddress IP(192,168,4,1);
IPAddress mask = (255, 255, 255, 0);
byte ledPin = 2;
// Internet router credentials - IPAddress 192.168.0.1
const char* ssid = "*******";
const char* password = "******";
#define ONE_HOUR 3600000UL
void setup() {
Serial.begin(9600);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("*");
}
Serial.println("WiFi connection Successful");
Serial.print("The IP Address of ESP8266 Module is: ");
Serial.print(WiFi.localIP());// Print the IP address
WiFi.softAP("server_1", "Server1");
WiFi.softAPConfig(IP, IP, mask);
server.begin();
pinMode(ledPin, OUTPUT);
Serial.println();
Serial.println("Server started.");
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
Serial.print("MAC:"); Serial.println(WiFi.softAPmacAddress());
Serial.print("");
Serial.print("Sender setup Email");
sendEmail("Test Setup","OK");
delay(1000);
}
void loop() {
WiFiClient client = server.available();
if (!client) {return;}
digitalWrite(ledPin, LOW);
String request = client.readStringUntil('\r');
sendEmail("Test request: ", request);
Serial.println(request);
// client.flush();
digitalWrite(ledPin, HIGH);
}
void sendEmail(String subj, String reqst){
EMailSender::EMailMessage message;
message.subject = subj;
message.message = reqst;
EMailSender::Response resp = emailSend.send("*******", message);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
}
Can you see the problem?
⸮txyR,(]⸮4C8I⸮********WiFi connection Successful
The IP Address of ESP8266 Module is: 192.168.0.165
master_server_1_AP.ino
Server started.
IP: 192.168.4.1
MAC:5E:CF:7F:88:20:25
Sender setup EmailSending status:
0
2
Could not connect to mail server
zoomkat
February 12, 2020, 5:54am
3
Why is the below in your code? Have you tried the bottom example code to see if it works?
IPAddress IP(192,168,4,1);
IPAddress mask = (255, 255, 255, 0);
#include "Arduino.h"
#include <EMailSender.h>
#include <ESP8266WiFi.h>
uint8_t connection_state = 0;
uint16_t reconnect_interval = 10000;
EMailSender emailSend("smtp.account@gmail.com", "password");
uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
{
static uint16_t attempt = 0;
Serial.print("Connecting to ");
if(nSSID) {
WiFi.begin(nSSID, nPassword);
Serial.println(nSSID);
}
uint8_t i = 0;
while(WiFi.status()!= WL_CONNECTED && i++ < 50)
{
delay(200);
Serial.print(".");
}
++attempt;
Serial.println("");
if(i == 51) {
Serial.print("Connection: TIMEOUT on attempt: ");
Serial.println(attempt);
if(attempt % 2 == 0)
Serial.println("Check if access point available or SSID and Password\r\n");
return false;
}
Serial.println("Connection: ESTABLISHED");
Serial.print("Got IP address: ");
Serial.println(WiFi.localIP());
return true;
}
void Awaits()
{
uint32_t ts = millis();
while(!connection_state)
{
delay(50);
if(millis() > (ts + reconnect_interval) && !connection_state){
connection_state = WiFiConnect();
ts = millis();
}
}
}
//The setup function is called once at startup of the sketch
void setup()
{
Serial.begin(115200);
const char* ssid = "ssid of your AP";
const char* password = "password of your AP";
connection_state = WiFiConnect(ssid, password);
if(!connection_state) // if not connected to WIFI
Awaits(); // constantly trying to connect
EMailSender::EMailMessage message;
message.subject = "Soggetto";
message.message = "Ciao come stai
io bene.";
EMailSender::Response resp = emailSend.send("account_to_send@gmail.com", message);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
}
// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
}
Yes, It works. The EmailsenderTest.ino
That why I ask - Would I be able to make it work with AP and Station/Client (I think it is here I am)
But I won it to be able to let other sheilds connect to it for sending emails.
Like a call to 192.168.4.1:80 as an AP so it have local network without access to the internet.
Only the emailSender should be able to connect for sending emails, with request from my other sheilds.
hope it make sense...
My emailsender.ino
My client1 send a string like "Client1, got fire, alarm_in_room" to AP:192.168.4.1 there send it through my Internet router
My client2 send a string like "Client2, temperature, data_alarm_in_room" to AP:192.168.4.1 there send it through my Internet router
and so on....
No clients access to the internet... only through emailsender.ino
zoomkat
February 12, 2020, 6:01pm
5
"Look like it works...."
Did you receive the email in your account? That is the real proof that it works. One thing to be aware of is that when testing sending email, you can flood your email in box if your code goes into a loop,