2

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
  client.beginRequest();
  String contentType = "application/json";
  client.post("/devices/deviceId/messages/events?api-version=2016-02-03");
  client.sendHeader(HTTP_HEADER_CONTENT_TYPE, contentType);
  client.sendHeader("Authorization", sig);
  client.sendHeader(HTTP_HEADER_CONTENT_LENGTH, jsonPayload.length());
  client.beginBody();
  client.print(jsonPayload);
  client.endRequest();

  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?

Thanks

rams
  • 179
  • 1
  • 1
  • 5

2 Answers2

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.

Majenko
  • 105,851
  • 5
  • 82
  • 139
2

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.

rams
  • 179
  • 1
  • 1
  • 5