Can’t connect to Gmail

Viewing 1 reply thread
  • Author
    Posts
    • #15748
      Sergio

        Hi, i use this code to check if i have wifi at home.
        I will change the purpose later.
        For the moment i want
        -Have one wifi connection (this part works)
        Turn on a led wen i have internet connection and turn off when I don’t have. (this work too)
        The idea was to send a email when i have internet connection again.
        So i use this code to send the email, but he don’t work.

        The code

        ———————————————-

        #include <WiFiNINA.h>
        #include <SPI.h>
        #include “Arduino.h”
        #include <EMailSender.h>

         

        char ssid[] = “ma-maison”; // your network SSID (name)
        char pass[] = “4445555SSSSEER???”; // your network password (use for WPA, or use as key for WEP)
        int keyIndex = 0; // your network key Index number (needed only for WEP)
        int status = WL_IDLE_STATUS; //connection status
        WiFiServer server(80); //server socket
        //mod ping
        String hostName = “www.google.fr”;
        int pingResult;
        // fin mod ping
        // mod mail

        //EMailSender emailSend(“sergio”, “dddd1111?”, “sergio@gmail.com”, “smtp.gmail.com”, 465);  i have tried this combination too

        EMailSender emailSend(“sergio”, “dddd1111?”);

        // fin mod mail

        WiFiClient client = server.available();

        int ledPin = 2;

        void setup() {
        Serial.begin(9600);
        pinMode(ledPin, OUTPUT);
        while (!Serial);

        enable_WiFi();
        connect_WiFi();

        server.begin();
        printWifiStatus();

        // mod mail

        EMailSender::EMailMessage message;
        message.subject = “teste”;
        message.message = “finalemente”;

        EMailSender::Response resp = emailSend.send(“sergio@laposte.net”, message);

        Serial.println(“Sending status: “);
        Serial.println(resp.code);
        Serial.println(resp.desc);
        Serial.println(resp.status);

        // fin mod mail

        }

        void loop() {

        sergio();

        }

        void printWifiStatus() {
        // print the SSID of the network you’re attached to:
        Serial.print(“SSID: “);
        Serial.println(WiFi.SSID());

        // print your board’s IP address:
        IPAddress ip = WiFi.localIP();
        Serial.print(“IP Address: “);
        Serial.println(ip);

        // print the received signal strength:
        long rssi = WiFi.RSSI();
        Serial.print(“signal strength (RSSI):”);
        Serial.print(rssi);
        Serial.println(” dBm”);

        Serial.print(“To see this page in action, open a browser to http://&#8221;);
        Serial.println(ip);
        }

        void enable_WiFi() {
        // check for the WiFi module:
        if (WiFi.status() == WL_NO_MODULE) {
        Serial.println(“Communication with WiFi module failed!”);
        // don’t continue
        while (true);
        }

        String fv = WiFi.firmwareVersion();
        if (fv < “1.0.0”) {
        Serial.println(“Please upgrade the firmware”);
        }
        }

        void connect_WiFi() {
        // attempt to connect to Wifi network:
        while (status != WL_CONNECTED) {
        Serial.print(“Attempting to connect to SSID: “);
        Serial.println(ssid);
        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
        status = WiFi.begin(ssid, pass);

        // wait 10 seconds for connection:
        delay(10000);
        }
        }
        void sergio(){
        // mod ping
        Serial.print(“Pinging “);

        Serial.print(hostName);

        Serial.print(“: “);

        pingResult = WiFi.ping(hostName);

        if (pingResult >= 0) {

        Serial.print(“SUCCESS! RTT = “);

        Serial.print(pingResult);

        Serial.println(” ms”);

        digitalWrite(ledPin, HIGH);

        } else {

        Serial.print(“FAILED! Error code: “);

        Serial.println(pingResult);

        digitalWrite(ledPin, LOW);

        }

        delay(5000);

        }

        ——————————- end code——————–

        I have this result

         

        Attempting to connect to SSID: ma-maison
        SSID: ma-maison
        IP Address: 002.01.0.30
        signal strength (RSSI):-37 dBm
        Sending status:
        2
        Could not connect to mail server
        0

         

        Thanks for any help

         

         

      • #15749
        Renzo Mischianti
        Keymaster

          Hi Sergio,
          you can refer this topic.
          Nano 33 iot not sending basic gmail example
          Probably you must add the certificate.

          Bye Renzo

          • #15750
            serpih
            Participant

              Thanks,
              I have done this before but the first time didn’t work.
              I made all the updates again and this time all works.
              Thank you very much.

        Viewing 1 reply thread
        • You must be logged in to reply to this topic.
        Exit mobile version