feature/esp_http_client:Changes to make esp_http_client compatible with ESP8266.

Changes:
Added rom/md5_hash.h.
Example code & sdkconfig.defaults changed for compatibility.
Changed component.mk to enable compilation only for mbedtls.
This commit is contained in:
Supreet Deshpande
2019-02-14 15:15:19 +05:30
parent ee32bd51a1
commit 32785a182f
5 changed files with 67 additions and 72 deletions

View File

@ -0,0 +1,38 @@
/*
* MD5 internal definitions
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#ifndef _ROM_MD5_HASH_H_
#define _ROM_MD5_HASH_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct MD5Context {
uint32_t buf[4];
uint32_t bits[2];
uint8_t in[64];
};
void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
#ifdef __cplusplus
}
#endif
#endif /* _ROM_MD5_HASH_H_ */

View File

@ -2,5 +2,11 @@
# Component Makefile
#
COMPONENT_SRCDIRS :=
COMPONENT_ADD_INCLUDEDIRS :=
ifdef CONFIG_SSL_USING_MBEDTLS
COMPONENT_SRCDIRS := . lib
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_PRIV_INCLUDEDIRS := lib/include
endif

View File

@ -1,52 +0,0 @@
import re
import os
import sys
# this is a test case write with tiny-test-fw.
# to run test cases outside tiny-test-fw,
# we need to set environment variable `TEST_FW_PATH`,
# then get and insert `TEST_FW_PATH` to sys path before import FW module
test_fw_path = os.getenv("TEST_FW_PATH")
if test_fw_path and test_fw_path not in sys.path:
sys.path.insert(0, test_fw_path)
import TinyFW
import IDF
@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True)
def test_examples_protocol_esp_http_client(env, extra_data):
"""
steps: |
1. join AP
2. Send HTTP request to httpbin.org
"""
dut1 = env.get_dut("esp_http_client", "examples/protocols/esp_http_client")
# check and log bin size
binary_file = os.path.join(dut1.app.binary_path, "esp-http-client-example.bin")
bin_size = os.path.getsize(binary_file)
IDF.log_performance("esp_http_client_bin_size", "{}KB".format(bin_size//1024))
IDF.check_performance("esp_http_client_bin_size", bin_size//1024)
# start test
dut1.start_app()
dut1.expect("Connected to AP, begin http example", timeout=30)
dut1.expect(re.compile(r"HTTP GET Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP POST Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Relative path redirect Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Absolute path redirect Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP redirect to HTTPS Status = 200, content_length = (\d)"), timeout=10)
dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = -1"))
dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)"))
dut1.expect("Finish http example")
if __name__ == '__main__':
test_examples_protocol_esp_http_client()

View File

@ -82,7 +82,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP GET request failed: %d", err);
}
// POST
@ -96,7 +96,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP POST request failed: %d", err);
}
//PUT
@ -108,7 +108,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP PUT request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP PUT request failed: %d", err);
}
//PATCH
@ -121,7 +121,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP PATCH request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP PATCH request failed: %d", err);
}
//DELETE
@ -133,7 +133,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP DELETE request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP DELETE request failed: %d", err);
}
//HEAD
@ -145,7 +145,7 @@ static void http_rest()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP HEAD request failed: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "HTTP HEAD request failed: %d", err);
}
esp_http_client_cleanup(client);
@ -166,7 +166,7 @@ static void http_auth_basic()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -179,14 +179,14 @@ static void http_auth_basic_redirect()
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Basic Auth redirect Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -198,13 +198,12 @@ static void http_auth_digest()
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP Digest Auth Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -224,7 +223,7 @@ static void https()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -243,7 +242,7 @@ static void http_relative_redirect()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -262,7 +261,7 @@ static void http_absolute_redirect()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -281,7 +280,7 @@ static void http_redirect_to_https()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -301,7 +300,7 @@ static void http_download_chunk()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -320,7 +319,7 @@ static void http_perform_as_stream_reader()
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err;
if ((err = esp_http_client_open(client, 0)) != ESP_OK) {
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Failed to open HTTP connection: %d", err);
free(buffer);
return;
}
@ -369,7 +368,7 @@ static void https_async()
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
ESP_LOGE(TAG, "Error perform http request %d", err);
}
esp_http_client_cleanup(client);
}
@ -396,7 +395,7 @@ static void http_test_task(void *pvParameters)
void app_main()
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}

View File

@ -0,0 +1,4 @@
CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y
CONFIG_SSL_USING_MBEDTLS=y
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=1024
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384