Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6b28ad

Browse files
Fixing WiFi code to allow HTTPS-GET instead of HTTP-GET (required for Arduino IoT Cloud OTA).
1 parent b86aaa7 commit a6b28ad

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

‎libraries/WiFi/src/WiFiHelpers.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "WiFi.h"
1818
#include "mbed.h"
1919
#include "utility/http_request.h"
20+
#include "utility/https_request.h"
2021

2122
static FILE* target;
2223

@@ -26,7 +27,13 @@ void body_callback(const char* data, uint32_t data_len) {
2627

2728
int WiFiClass::download(char* url, const char* target_file) {
2829
target = fopen(target_file, "wb");
29-
HttpRequest* req = new HttpRequest(getNetwork(), HTTP_GET, url, &body_callback);
30-
req->send(NULL, 0);
31-
fclose(target);
30+
HttpsRequest* req = new HttpsRequest(getNetwork(), nullptr, HTTP_GET, url, &body_callback);
31+
if (req->send(NULL, 0) == NULL)
32+
{
33+
fclose(target);
34+
return req->get_error();
35+
}
36+
int const size = ftell(target);
37+
fclose(target);
38+
return size;
3239
}

‎libraries/WiFi/src/utility/https_request.h‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ class HttpsRequest : public HttpRequestBase {
4949
const char* ssl_ca_pem,
5050
http_method method,
5151
const char* url,
52-
Callback<void(const char *at, uint32_t length)> body_callback = 0)
52+
mbed::Callback<void(const char *at, uint32_t length)> body_callback = 0)
5353
: HttpRequestBase(NULL, body_callback)
5454
{
55+
_error = 0;
56+
_network = network;
57+
5558
_parsed_url = new ParsedUrl(url);
5659
_request_builder = new HttpRequestBuilder(method, _parsed_url);
5760
_response = NULL;
5861

5962
_socket = new TLSSocket();
6063
((TLSSocket*)_socket)->open(network);
61-
((TLSSocket*)_socket)->set_root_ca_cert(ssl_ca_pem);
64+
//((TLSSocket*)_socket)->set_root_ca_cert(ssl_ca_pem);
65+
((TLSSocket*)_socket)->set_root_ca_cert("/wlan/", 0);
6266
_we_created_socket = true;
6367
}
6468

@@ -76,7 +80,7 @@ class HttpsRequest : public HttpRequestBase {
7680
HttpsRequest(TLSSocket* socket,
7781
http_method method,
7882
const char* url,
79-
Callback<void(const char *at, uint32_t length)> body_callback = 0)
83+
mbed::Callback<void(const char *at, uint32_t length)> body_callback = 0)
8084
: HttpRequestBase(socket, body_callback)
8185
{
8286
_parsed_url = new ParsedUrl(url);
@@ -91,7 +95,10 @@ class HttpsRequest : public HttpRequestBase {
9195

9296
protected:
9397
virtual nsapi_error_t connect_socket(char *host, uint16_t port) {
94-
return ((TLSSocket*)_socket)->connect(host, port);
98+
SocketAddress socketAddress = SocketAddress();
99+
socketAddress.set_port(port);
100+
_network->gethostbyname(host, &socketAddress);
101+
return ((TLSSocket*)_socket)->connect(socketAddress);
95102
}
96103
};
97104

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /