Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "Upload To Blob" feature (CA-19) #68

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
156 changes: 156 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#
# Component Makefile
#

set (AZURE_IOT_SDK "${CMAKE_CURRENT_LIST_DIR}/azure-iot-sdk-c")

set (COMPONENT_ADD_INCLUDEDIRS
"port/inc"
"${AZURE_IOT_SDK}/certs"
"${AZURE_IOT_SDK}/c-utility/inc"
"${AZURE_IOT_SDK}/c-utility/deps/azure-macro-utils-c/inc"
"${AZURE_IOT_SDK}/c-utility/deps/umock-c/inc"
"${AZURE_IOT_SDK}/c-utility/pal/inc"
"${AZURE_IOT_SDK}/c-utility/pal/freertos"
"${AZURE_IOT_SDK}/c-utility/pal/generic"
"${AZURE_IOT_SDK}/iothub_client/inc"
"${AZURE_IOT_SDK}/serializer/inc"
"${AZURE_IOT_SDK}/umqtt/inc"
"${AZURE_IOT_SDK}/umqtt/inc/azure_umqtt_c"
"${AZURE_IOT_SDK}/deps/parson"
"${AZURE_IOT_SDK}/deps/umock-c/inc"
"${AZURE_IOT_SDK}/provisioning_client/inc"
"${AZURE_IOT_SDK}/provisioning_client/adapters"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/inc"
)

set (COMPONENT_SRCS
"port/src/agenttime_esp.c"
"port/src/platform_esp.c"
"port/src/tlsio_esp_tls.c"
"port/src/socketio_esp.c"
"${AZURE_IOT_SDK}/certs/certs.c" # UNUSED
"${AZURE_IOT_SDK}/c-utility/pal/freertos/lock.c"
"${AZURE_IOT_SDK}/c-utility/pal/socket_async.c"
"${AZURE_IOT_SDK}/c-utility/pal/freertos/threadapi.c"
"${AZURE_IOT_SDK}/c-utility/pal/freertos/tickcounter.c"
"${AZURE_IOT_SDK}/c-utility/pal/tlsio_options.c"
"${AZURE_IOT_SDK}/c-utility/src/xlogging.c"
"${AZURE_IOT_SDK}/c-utility/src/singlylinkedlist.c"
"${AZURE_IOT_SDK}/c-utility/src/buffer.c"
"${AZURE_IOT_SDK}/c-utility/src/consolelogger.c"
"${AZURE_IOT_SDK}/c-utility/src/constbuffer.c"
"${AZURE_IOT_SDK}/c-utility/src/constmap.c"
"${AZURE_IOT_SDK}/c-utility/src/crt_abstractions.c"
"${AZURE_IOT_SDK}/c-utility/src/doublylinkedlist.c"
"${AZURE_IOT_SDK}/c-utility/src/gballoc.c"
"${AZURE_IOT_SDK}/c-utility/src/gb_rand.c"
"${AZURE_IOT_SDK}/c-utility/src/gb_stdio.c"
"${AZURE_IOT_SDK}/c-utility/src/gb_time.c"
"${AZURE_IOT_SDK}/c-utility/src/hmac.c"
"${AZURE_IOT_SDK}/c-utility/src/hmacsha256.c"
"${AZURE_IOT_SDK}/c-utility/src/httpapiex.c"
"${AZURE_IOT_SDK}/c-utility/src/httpapiexsas.c"
"${AZURE_IOT_SDK}/c-utility/src/httpheaders.c"
"${AZURE_IOT_SDK}/c-utility/src/map.c"
"${AZURE_IOT_SDK}/c-utility/src/optionhandler.c"
"${AZURE_IOT_SDK}/c-utility/src/sastoken.c"
"${AZURE_IOT_SDK}/c-utility/src/sha1.c"
"${AZURE_IOT_SDK}/c-utility/src/sha224.c"
"${AZURE_IOT_SDK}/c-utility/src/sha384-512.c"
"${AZURE_IOT_SDK}/c-utility/src/strings.c"
"${AZURE_IOT_SDK}/c-utility/src/string_tokenizer.c"
"${AZURE_IOT_SDK}/c-utility/src/urlencode.c"
"${AZURE_IOT_SDK}/c-utility/src/usha.c"
"${AZURE_IOT_SDK}/c-utility/src/utf8_checker.c"
"${AZURE_IOT_SDK}/c-utility/src/vector.c"
"${AZURE_IOT_SDK}/c-utility/src/xio.c"
"${AZURE_IOT_SDK}/c-utility/src/wsio.c"
"${AZURE_IOT_SDK}/c-utility/src/azure_base64.c"
"${AZURE_IOT_SDK}/c-utility/src/uws_frame_encoder.c"
"${AZURE_IOT_SDK}/c-utility/src/uws_client.c"
"${AZURE_IOT_SDK}/c-utility/adapters/httpapi_compact.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_device_client_ll.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_ll.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_core_ll.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_ll_uploadtoblob.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_authorization.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_retry_control.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_client_diagnostic.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_message.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothubtransport.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothubtransportmqtt.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothubtransport_mqtt_common.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothubtransportmqtt_websockets.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub_transport_ll_private.c"
"${AZURE_IOT_SDK}/iothub_client/src/version.c"
"${AZURE_IOT_SDK}/iothub_client/src/blob.c"
"${AZURE_IOT_SDK}/umqtt/src/mqtt_client.c"
"${AZURE_IOT_SDK}/umqtt/src/mqtt_codec.c"
"${AZURE_IOT_SDK}/umqtt/src/mqtt_message.c"
"${AZURE_IOT_SDK}/deps/parson/parson.c"
"${AZURE_IOT_SDK}/serializer/src/codefirst.c"
"${AZURE_IOT_SDK}/serializer/src/agenttypesystem.c"
"${AZURE_IOT_SDK}/serializer/src/commanddecoder.c"
"${AZURE_IOT_SDK}/serializer/src/datamarshaller.c"
"${AZURE_IOT_SDK}/serializer/src/datapublisher.c"
"${AZURE_IOT_SDK}/serializer/src/dataserializer.c"
"${AZURE_IOT_SDK}/serializer/src/iotdevice.c"
"${AZURE_IOT_SDK}/serializer/src/jsondecoder.c"
"${AZURE_IOT_SDK}/serializer/src/jsonencoder.c"
"${AZURE_IOT_SDK}/serializer/src/methodreturn.c"
"${AZURE_IOT_SDK}/serializer/src/multitree.c"
"${AZURE_IOT_SDK}/serializer/src/schema.c"
"${AZURE_IOT_SDK}/serializer/src/schemalib.c"
"${AZURE_IOT_SDK}/serializer/src/schemaserializer.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_device_client.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_transport_mqtt_client.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_transport_mqtt_common.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_transport_mqtt_ws_client.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_security_factory.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_device_ll_client.c"
"${AZURE_IOT_SDK}/provisioning_client/src/iothub_security_factory.c"
"${AZURE_IOT_SDK}/provisioning_client/src/iothub_auth_client.c"
"${AZURE_IOT_SDK}/provisioning_client/adapters/hsm_client_data.c"
"${AZURE_IOT_SDK}/provisioning_client/adapters/hsm_client_tpm.c"
"${AZURE_IOT_SDK}/provisioning_client/src/prov_auth_client.c"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/src/tpm_codec.c"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/src/Marshal.c"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/src/tpm_comm_emulator.c"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/src/Memory.c"
"${AZURE_IOT_SDK}/provisioning_client/deps/utpm/src/tpm_socket_comm.c"
"${AZURE_IOT_SDK}/iothub_client/src/iothub.c"
"${AZURE_IOT_SDK}/c-utility/src/http_proxy_io.c"
"${AZURE_IOT_SDK}/c-utility/src/azure_base32.c"
)

set (COMPONENT_SUBMODULES "${AZURE_IOT_SDK}")

#set(COMPONENT_PRIV_REQUIRES "mbedtls esp-tls main")
set(COMPONENT_PRIV_REQUIRES "mbedtls esp-tls")

register_component()

set_source_files_properties(
${AZURE_IOT_SDK}/iothub_client/src/iothubtransport_mqtt_common.c
PROPERTIES COMPILE_FLAGS
-Wno-maybe-uninitialized
)

component_compile_options (
-Wno-unused-function
-Wno-missing-braces
-Wno-missing-field-initializers
-Wno-unknown-pragmas
-Wno-error=format=
-Wno-error=char-subscripts
)

component_compile_definitions (
LOGGER_DISABLE_PAL
USE_LWIP_SOCKET_FOR_AZURE_IOT
HSM_TYPE_X509
HSM_TYPE_SAS_TOKEN
HSM_TYPE_SYMM_KEY
USE_PROV_MODULE
)
17 changes: 15 additions & 2 deletions component.mk
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#
# Component Makefile
#

# Component configuration in preprocessor defines
CFLAGS += -DUSE_LWIP_SOCKET_FOR_AZURE_IOT

COMPONENT_ADD_INCLUDEDIRS := \
azure-iot-sdk-c/c-utility/inc \
azure-iot-sdk-c/c-utility/inc/azure_c_shared_utility \
azure-iot-sdk-c/c-utility/deps/azure-macro-utils-c/inc \
azure-iot-sdk-c/c-utility/deps/umock-c/inc \
azure-iot-sdk-c/iothub_client/inc \
azure-iot-sdk-c/serializer/inc \
azure-iot-sdk-c/umqtt/inc \
azure-iot-sdk-c/umqtt/inc/azure_umqtt_c \
azure-iot-sdk-c/deps/parson \
azure-iot-sdk-c/deps/umock-c/inc \
azure-iot-sdk-c/provisioning_client/inc \
azure-iot-sdk-c/provisioning_client/adapters \
azure-iot-sdk-c/provisioning_client/deps/utpm/inc \
Expand All @@ -38,6 +40,7 @@ azure-iot-sdk-c/c-utility/pal/tlsio_options.o \
port/src/agenttime_esp.o \
port/src/platform_esp.o \
port/src/tlsio_esp_tls.o \
port/src/socketio_esp.o \
\
azure-iot-sdk-c/c-utility/src/xlogging.o \
azure-iot-sdk-c/c-utility/src/singlylinkedlist.o \
Expand All @@ -48,6 +51,7 @@ azure-iot-sdk-c/c-utility/src/constmap.o \
azure-iot-sdk-c/c-utility/src/crt_abstractions.o \
azure-iot-sdk-c/c-utility/src/doublylinkedlist.o \
azure-iot-sdk-c/c-utility/src/gballoc.o \
azure-iot-sdk-c/c-utility/src/gb_rand.o \
azure-iot-sdk-c/c-utility/src/gb_stdio.o \
azure-iot-sdk-c/c-utility/src/gb_time.o \
azure-iot-sdk-c/c-utility/src/hmac.o \
Expand All @@ -65,9 +69,14 @@ azure-iot-sdk-c/c-utility/src/strings.o \
azure-iot-sdk-c/c-utility/src/string_tokenizer.o \
azure-iot-sdk-c/c-utility/src/urlencode.o \
azure-iot-sdk-c/c-utility/src/usha.o \
azure-iot-sdk-c/c-utility/src/utf8_checker.o \
azure-iot-sdk-c/c-utility/src/vector.o \
azure-iot-sdk-c/c-utility/src/xio.o \
azure-iot-sdk-c/c-utility/src/wsio.o \
azure-iot-sdk-c/c-utility/src/azure_base64.o \
azure-iot-sdk-c/c-utility/src/uws_frame_encoder.o \
azure-iot-sdk-c/c-utility/src/uws_client.o \
azure-iot-sdk-c/c-utility/adapters/httpapi_compact.o \
\
\
azure-iot-sdk-c/iothub_client/src/iothub_device_client_ll.o \
Expand All @@ -81,8 +90,10 @@ azure-iot-sdk-c/iothub_client/src/iothub_message.o \
azure-iot-sdk-c/iothub_client/src/iothubtransport.o \
azure-iot-sdk-c/iothub_client/src/iothubtransportmqtt.o \
azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.o \
azure-iot-sdk-c/iothub_client/src/iothubtransportmqtt_websockets.o \
azure-iot-sdk-c/iothub_client/src/iothub_transport_ll_private.o \
azure-iot-sdk-c/iothub_client/src/version.o \
azure-iot-sdk-c/iothub_client/src/blob.o \
\
\
azure-iot-sdk-c/umqtt/src/mqtt_client.o \
Expand Down Expand Up @@ -111,6 +122,7 @@ azure-iot-sdk-c/serializer/src/schemaserializer.o \
azure-iot-sdk-c/provisioning_client/src/prov_device_client.o \
azure-iot-sdk-c/provisioning_client/src/prov_transport_mqtt_client.o \
azure-iot-sdk-c/provisioning_client/src/prov_transport_mqtt_common.o \
azure-iot-sdk-c/provisioning_client/src/prov_transport_mqtt_ws_client.o \
azure-iot-sdk-c/provisioning_client/src/prov_security_factory.o \
azure-iot-sdk-c/provisioning_client/src/prov_device_ll_client.o \
azure-iot-sdk-c/provisioning_client/src/iothub_security_factory.o \
Expand Down Expand Up @@ -160,7 +172,8 @@ ifndef CONFIG_TARGET_PLATFORM_ESP8266
COMPONENT_SRCDIRS += azure-iot-sdk-c/certs
endif

CFLAGS += -Wno-unused-function -Wno-missing-braces -Wno-missing-field-initializers -DHSM_TYPE_X509 -DHSM_TYPE_SAS_TOKEN -Wno-unknown-pragmas
CFLAGS += -Wno-unused-function -Wno-missing-braces -Wno-missing-field-initializers -DHSM_TYPE_X509 -DHSM_TYPE_SAS_TOKEN -DHSM_TYPE_SYMM_KEY
CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=char-subscripts -Wno-unknown-pragmas

ifdef CONFIG_DEVICE_COMMON_NAME
CFLAGS += -DUSE_PROV_MODULE
Expand Down
6 changes: 6 additions & 0 deletions examples/iothub_client_sample_mqtt/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ config MESSAGE_COUNT
messages. If the message count is set as 0 then this example
will send indefinite messages to the cloud.

config SAMPLE_MQTT_OVER_WEBSOCKET
bool "MQTT over WebSocket"
default n
help
This option enables MQTT over WebSocket protocol, instead of raw MQTT.

endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
#include "azure_c_shared_utility/crt_abstractions.h"
#include "azure_c_shared_utility/platform.h"
#include "azure_c_shared_utility/shared_util_options.h"
#include "iothubtransportmqtt.h"
#include "iothub_client_options.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#if CONFIG_SAMPLE_MQTT_OVER_WEBSOCKET
#include "iothubtransportmqtt_websockets.h"
#define PROTOCOL MQTT_WebSocket_Protocol
#else // CONFIG_SAMPLE_MQTT_OVER_WEBSOCKET
#include "iothubtransportmqtt.h"
#define PROTOCOL MQTT_Protocol
#endif // !CONFIG_SAMPLE_MQTT_OVER_WEBSOCKET

#ifdef MBED_BUILD_TIMESTAMP
#define SET_TRUSTED_CERT_IN_SAMPLES
#endif // MBED_BUILD_TIMESTAMP
Expand Down Expand Up @@ -148,7 +155,7 @@ void iothub_client_sample_mqtt_run(void)
}
else
{
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, MQTT_Protocol)) == NULL)
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, PROTOCOL)) == NULL)
{
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
}
Expand All @@ -157,6 +164,12 @@ void iothub_client_sample_mqtt_run(void)
bool traceOn = true;
IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_LOG_TRACE, &traceOn);

#if CONFIG_SAMPLE_MQTT_OVER_WEBSOCKET
// MQTT over WebSocket requires TLS renegociation
bool enable = 1;
IoTHubDeviceClient_LL_SetOption(iotHubClientHandle, OPTION_SET_TLS_RENEGOTIATION, &enable);
#endif // CONFIG_SAMPLE_MQTT_OVER_WEBSOCKET

IoTHubClient_LL_SetConnectionStatusCallback(iotHubClientHandle, connection_status_callback, NULL);
// Setting the Trusted Certificate. This is only necessary on system with without
// built in certificate stores.
Expand Down
10 changes: 6 additions & 4 deletions port/src/agenttime_esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

void initialize_sntp(void)
{
printf("Initializing SNTP\n");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_init();
if (!sntp_enabled()) {
printf("Initializing SNTP\n");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_init();
}
}

static void obtain_time(void)
Expand Down
11 changes: 11 additions & 0 deletions port/src/socketio_esp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#include <stdio.h>

#include "azure_c_shared_utility/socketio.h"

const IO_INTERFACE_DESCRIPTION* socketio_get_interface_description(void)
{
return NULL;
}
Loading