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



  • 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
    


  • Hello @Mickey95

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

    Thanks
    Felix



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



  • Can we see the code?



  • @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?



  • @mickey95 dude?