Board: ESP8266MOD module from AI Thinker.

Using ArduinoHttpClient I am unable to send a post message to an Azure IOT Hub endpoint. The endpoint is listening on 443 and expects a shared key passed via a custom header.

The error I get is "Connection Timed Out"

Here is the brief sketch

char serverAddress[] = "myapp.azure-devices.net";
int port = 443;
string sig = "Azure shared access signature";
HttpClient client = HttpClient(wifiClient, serverAddress, port);
  String jsonPayload = payload; // passed into this function
  String contentType = "application/json";
  client.sendHeader(HTTP_HEADER_CONTENT_TYPE, contentType);
  client.sendHeader("Authorization", sig);
  client.sendHeader(HTTP_HEADER_CONTENT_LENGTH, jsonPayload.length());

  statusCode = client.responseStatusCode();
  response = client.responseBody();

The Status Code is -3 indicating a Timeout

I then created a simple REST API that accepts the JSON. Hosted it as an Azure website on port 80.

The board is able to connect to this HTTP endpoint

Question(s): 1. Is the board underpowered to handle HTTPS? 2. Is creating an HTTP proxy the only option? 3. Am I not using the right library?


2 Answers 2


You are only making an HTTP request to an HTTPS server. It's not going to work.

AFAIK there is no direct support for HTTPS in the ESP8266 libraries, but there is support for SSL, and you can then manually create an HTTP request over that - as detailed in the HTTPSRequest.ino example.

  • Thanks for responding. When you say "You are only making an HTTP request to an HTTPS Server", do you mean the library constructs the URL as http:// even though the port specified is 443? If I change char serverAddress[] = "myapp.azure-devices.net"; to char serverAddress[] = "myapp.azure-devices.net"; it does not work either.
    – rams
    Sep 26, 2017 at 14:45
  • 1
    Yes, I mean that the library doesn't know that 443 corresponds to HTTPS, since you can run HTTP on any port, not just 80. Also it doesn't know what HTTPS is. It only talks HTTP.
    – Majenko
    Sep 26, 2017 at 14:49

Thanks to @Majenko I was able to find the right solution.

The resolution is here

Essentially, a secure WiFiClient needs to be created and used in the HttpClient constructor

  1. Paste the HTTPS URL You are trying to connect to, in a browser window and grab the SHA1 Fingerprint of the certificate
  2. Create aninstance of WifiClientSecure
  3. Call Connect on WifiClientSecure passing in the HTTPS URL and Port number
  4. Upon successful connection, call the Verify method of WifiClientSecure to verify the fingerprint.
  5. Pass the fingerprint from setp1 and URL to this method
  6. Use the WifiClientSecure instance when creating an instance of HttpClient.

Hope this helps.

  • Your link doesn't contain any resolution.
    – m12lrpv
    Mar 18, 2019 at 0:45
  • @m12lrpv check out sandeepmistry's comment in the thread. I added the steps in an attempt to clarify the comments.
    – rams
    Mar 18, 2019 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.