🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    On M5Core2 I am not getting a working https request (WiFiClient). What do I wrong?

    Scheduled Pinned Locked Moved Arduino
    6 Posts 4 Posters 8.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      Mickey95
      last edited by

      Good day,

      The following example for a https request is not working for my M5Core2. I don't see what I am doing wrong.

      Has anybody a clue why the example is not working?

      Added:

      • source and
      • Serial log. The last line printed is 'DEBUG 001' followed by 'DEBUG 002'.
      #include <WiFi.h>
      
      char ssid[]     = "<SSID_var>";
      char password[] = "XXXXX";
      
      char server[] = "www.google.com";
      WiFiClient client;
      
      int status = WL_IDLE_STATUS;
      
      void setup() {
        //Initialize serial and wait for port to open:
        Serial.begin(115200);
        delay(1000);
      }
      
      void loop() {
        WiFi.begin(ssid, password);
      
        // Attempt to connect to Wifi network:
        while (WiFi.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:
          delay(1000);
          Serial.print(".");
        }
      
        Serial.println("Connected to wifi");
        printWifiStatus();
        Serial.println("\nStarting connection to server...");
      
        // if you get a connection, report back via serial:
        if (client.connect(server, 443)) {
          Serial.println("connected to server");
          // Make a HTTP request:
          client.println("GET /search?q=arduino HTTP/1.1");
          client.println("Host: www.google.com");
          client.println("Connection: close");
          client.println();
          Serial.println("DEBUG 001");
        }
        Serial.println("DEBUG 002");
        
        // if there are incoming bytes available
        // from the server, read them and print them:
        while (client.available()) {
          char c = client.read();
          Serial.write(c);
        }
      
        // if the server's disconnected, stop the client:
        if (!client.connected()) {
          Serial.println();
          Serial.println("disconnecting from server.");
          client.stop();
        }
        // do nothing forevermore:
        while (true);
      }
      
      void printWifiStatus() {
        // print the SSID of the network you're attached to:
        Serial.print("SSID: ");
        Serial.println(WiFi.SSID());
        // print your WiFi shield'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 log

      20:32:29.120 -> .Attempting to connect to SSID: <SSID_var>
      20:32:30.107 -> .Connected to wifi
      20:32:30.154 -> SSID: Lumierestraat24
      20:32:30.154 -> IP Address: 192.168.50.220
      20:32:30.154 -> signal strength (RSSI): -50 dBm
      20:32:30.154 -> 
      20:32:30.154 -> Starting connection to server...
      20:32:30.154 -> connected to server
      20:32:30.154 -> DEBUG 001
      20:32:30.154 -> DEBUG 002
      
      1 Reply Last reply Reply Quote 0
      • felmueF Offline
        felmue
        last edited by

        Hello @Mickey95

        I don't think WiFiClient can handle HTTPS requests. I think you need to use WiFiClientSecure for that.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        M 1 Reply Last reply Reply Quote 1
        • M Offline
          Mickey95 @felmue
          last edited by

          @felmue Thank you for the answer. This is working! Meanwhile my own example is working using an updated PEM certificate :-)

          ajb2k3A AsmodevA 2 Replies Last reply Reply Quote 0
          • AsmodevA Offline
            Asmodev
            last edited by

            Can we see the code?

            1 Reply Last reply Reply Quote 0
            • ajb2k3A Offline
              ajb2k3 @Mickey95
              last edited by

              @mickey95 said in On M5Core2 I am not getting a working https request (WiFiClient). What do I wrong?:

              @felmue Thank you for the answer. This is working! Meanwhile my own example is working using an updated PEM certificate :-)

              So It was the PEM certificate that was the cause?
              How did you discover that?

              UIFlow, so easy an adult can learn it!
              If I don't know it, be patient!
              I've ether not learned it or am too drunk to remember it!
              Author of the WIP UIFlow Handbook!
              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

              1 Reply Last reply Reply Quote 0
              • AsmodevA Offline
                Asmodev @Mickey95
                last edited by

                @mickey95 dude?

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post