Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no email sent with static IP (with dyn local IP fine though) #1

Open
dsyleixa opened this issue Jul 27, 2018 · 1 comment
Open

no email sent with static IP (with dyn local IP fine though) #1

dsyleixa opened this issue Jul 27, 2018 · 1 comment

Comments

@dsyleixa
Copy link

dsyleixa commented Jul 27, 2018

no email sent with static IP, although connection established (different local IPs tested);
but with dynamic IP ok:
(Arduino IDE 1.8.5, board: NodeMCU 1.0)

IPAddress this_ip(192, 168, 2, 200); // this_ip(192, 168, 2, 201); this_ip(192, 168, 2, 222);
IPAddress gateway(192, 168, 2, 1); // <<< LAN Gateway IP
IPAddress subnet(255, 255, 255, 0); // <<< LAN Subnet Mask

WiFi.begin(ssid, password);
//WiFi.config(this_ip, gateway, subnet); // <<< static IP, uncommented: no email sent;
// dyn IP, outcommented: email send works

#include <ESP8266WiFi.h>
#include "Gsender.h"

#pragma region Globals
const char* ssid = "dlink-4212";                           // WIFI network name
const char* password = "nhyyi53680";    // WIFI network password
uint8_t connection_state = 0;                    // Connected to WIFI or not
uint16_t reconnect_interval = 10000;             // If not connected wait time to try again
#pragma endregion Globals

uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
{
    IPAddress    this_ip(192, 168, 2, 222);
    IPAddress    gateway(192, 168, 2, 1);       // <<< LAN Gateway IP
    IPAddress    subnet(255, 255, 255, 0);      // <<< LAN Subnet Mask
    
    static uint16_t attempt = 0;
    Serial.print("Connecting to ");
    /*
    if(nSSID) {
        WiFi.begin(nSSID, nPassword);  
        Serial.println(nSSID);
    } else */
    {    
        WiFi.begin(ssid, password);
        //WiFi.config(this_ip, gateway, subnet);   // <<< uncommented: no email sent; 
                                                   //     outcommented: emailsend works
        delay(500);
        Serial.println(ssid);
    }

    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();
        }
    }
}

void setup()
{
    Serial.begin(115200);
    delay(500);
    Serial.println("starting...");
    connection_state = WiFiConnect();
    if(!connection_state)  // if not connected to WIFI
        Awaits();          // constantly trying to connect

    Gsender *gsender = Gsender::Instance();    // Getting pointer to class instance
    String subject = "Subject is optional!";
    if(gsender->Subject(subject)->Send("abcde@gmail.com", "Setup test")) { // <<< send email
        Serial.println("Message send.");
    } else {
        Serial.print("Error sending message: ");
        Serial.println(gsender->getError());
    }
}

void loop(){}
@dsyleixa
Copy link
Author

is this repo still maintained?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant