So you're a Noob? Post your questions here until you graduate! Don't be shy.
User avatar
By Ryo Saeba
#76443 my sketch is as below, Please help me ! Always failed on connect(ip, port) line here.

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid     = "ssid";
const char* password = "pwd";


const char*  server  = "192.168.1.210";  // Server URL
const int    sslPort = 443;


unsigned char test_root_ca[] = "-----BEGIN CERTIFICATE-----\n " \
<my root ca>
"-----END CERTIFICATE-----\n ";

const unsigned char *root_ca = test_root_ca;

WiFiClientSecure client;

void setup()
{
  Serial.begin(115200);
  delay(100);

  Serial.print("Attempting to connect to SSID: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

  // attempt to connect to Wifi network:
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(1000);
  }

  Serial.print("\n\nConnected to ");
  Serial.println(ssid);
  client.setCACert(root_ca, sizeof(root_ca));
 
  Serial.println("Starting connection to "+ String(server) + ":" + String(sslPort));
 [b] if (!client.connect(server, sslPort)) <== ALWAYS failed on this line !![/b]
  {
    Serial.println("Connection failed! Wrong certificat?\n");
  }   
  else
  {
    Serial.println("Connect w/Certificate success");
  }
  client.stop();
}

void loop() { }