diff --git a/.gitmodules b/.gitmodules index b1335aba..b80e3fee 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "shared/lib/threadx"] path = shared/lib/threadx - url = https://github.com/azure-rtos/threadx.git + url = https://github.com/eclipse-threadx/threadx.git [submodule "shared/lib/netxduo"] path = shared/lib/netxduo - url = https://github.com/azure-rtos/netxduo.git -[submodule "shared/lib/jsmn/src"] - path = shared/lib/jsmn/src - url = https://github.com/zserge/jsmn + url = https://github.com/eclipse-threadx/netxduo.git diff --git a/MXChip/AZ3166/app/CMakeLists.txt b/MXChip/AZ3166/app/CMakeLists.txt index 71553b8a..0dec5588 100644 --- a/MXChip/AZ3166/app/CMakeLists.txt +++ b/MXChip/AZ3166/app/CMakeLists.txt @@ -6,7 +6,6 @@ set(SOURCES startup/startup_stm32f412rx.s startup/tx_initialize_low_level.S stm32cubef4/stm32f4xx_hal_msp.c - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -26,7 +25,6 @@ target_link_libraries(${PROJECT_NAME} mxchip_bsp wiced_sdk app_common - jsmn ) target_include_directories(${PROJECT_NAME} diff --git a/MXChip/AZ3166/app/legacy/mqtt.c b/MXChip/AZ3166/app/legacy/mqtt.c deleted file mode 100644 index b57c51b1..00000000 --- a/MXChip/AZ3166/app/legacy/mqtt.c +++ /dev/null @@ -1,226 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "screen.h" -#include "sensor.h" -#include "stm32f4xx_hal.h" - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - printf("LED is turned ON\r\n"); - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); - } - else - { - printf("LED is turned OFF\r\n"); - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); - } -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - lps22hb_t lps22hb_data; - hts221_data_t hts221_data; - lsm6dsl_data_t lsm6dsl_data; - lis2mdl_data_t lis2mdl_data; - - int telemetry_state = 0; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("Starting MQTT loop\r\n"); - screen_print("Azure IoT", L0); - - while (true) - { - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - - switch (telemetry_state) - { - case 0: - // Send the compensated temperature - lps22hb_data = lps22hb_data_read(); - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", lps22hb_data.temperature_degC); - break; - - case 1: - // Send the compensated pressure - lps22hb_data = lps22hb_data_read(); - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "pressure", lps22hb_data.pressure_hPa); - break; - - case 2: - // Send the compensated humidity - hts221_data = hts221_data_read(); - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "humidity", hts221_data.humidity_perc); - break; - - case 3: - // Send the compensated acceleration - lsm6dsl_data = lsm6dsl_data_read(); - azure_iot_mqtt_publish_float_telemetry( - &azure_iot_mqtt, "acceleration", lsm6dsl_data.acceleration_mg[0]); - break; - - case 4: - // Send the compensated magnetic - lis2mdl_data = lis2mdl_data_read(); - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "magnetic", lis2mdl_data.magnetic_mG[0]); - break; - } - - telemetry_state = (telemetry_state + 1) % 5; - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/MXChip/AZ3166/app/legacy/mqtt.h b/MXChip/AZ3166/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/MXChip/AZ3166/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/MXChip/AZ3166/app/main.c b/MXChip/AZ3166/app/main.c index a5aa5285..b54d6205 100644 --- a/MXChip/AZ3166/app/main.c +++ b/MXChip/AZ3166/app/main.c @@ -11,7 +11,6 @@ #include "sntp_client.h" #include "wwd_networking.h" -#include "legacy/mqtt.h" #include "nx_client.h" #include "azure_config.h" @@ -26,7 +25,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = wwd_network_init(WIFI_SSID, WIFI_PASSWORD, WIFI_MODE))) @@ -34,11 +33,7 @@ static void azure_thread_entry(ULONG parameter) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool[0], &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool[0], &nx_dns_client, sntp_time))) -#endif { printf("ERROR: Failed to run Azure IoT (0x%08x)\r\n", status); } @@ -48,7 +43,7 @@ void tx_application_define(void* first_unused_memory) { systick_interval_set(TX_TIMER_TICKS_PER_SECOND); - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/MXChip/AZ3166/azure-pipelines.yml b/MXChip/AZ3166/azure-pipelines.yml deleted file mode 100644 index b1f53ddb..00000000 --- a/MXChip/AZ3166/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) - -resources: - repositories: - - repository: Device-Lab - type: git - endpoint: Devicelab - name: Device-Lab/Device-Lab - -trigger: - batch: true - branches: - include: - - master - paths: - exclude: - - doc/* - -jobs: -- job: MXCHIP_Build - pool: - name: 'DDE' - demands: - - MXCHIPAZ3166 -equals true - steps: - - checkout: self - clean: true - submodules: recursive - - checkout: Device-Lab - clean: true - - # Azure CLI to start certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1' - arguments: '$(Build.SourcesDirectory)\getting-started\shared\model' - useGlobalConfig: true - displayName: "Start Certification" - - # modify config with credentials - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\update_config.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -ConfigFilePath '$(Build.SourcesDirectory)\getting-started\MXChip\AZ3166\app\azure_config.h' - displayName: 'Modify config file' - - # Build binary - - script: | - echo %PATH% - cd $(Build.SourcesDirectory)\getting-started\MXChip\AZ3166\tools - .\rebuild.bat - displayName: "Build Binary" - - # Flash binary to hardware - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\flashing_tools\flash-board.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -BinPath '$(Build.SourcesDirectory)\getting-started\MXChip\AZ3166\build\app\mxchip_azure_iot.hex' - displayName: 'Flash binary' - - # Monitor device for successful connection to Iot Hub - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\scan_serial.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -TestString 'SUCCESS: Connected to IoT Hub' - displayName: 'Scan serial port' - - # Azure CLI to run certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\run_certification.ps1' - arguments: $(TESTID) - useGlobalConfig: true - displayName: "Run Certification" diff --git a/MXChip/AZ3166/lib/CMakeLists.txt b/MXChip/AZ3166/lib/CMakeLists.txt index 558d9c6d..9fbeb9ff 100644 --- a/MXChip/AZ3166/lib/CMakeLists.txt +++ b/MXChip/AZ3166/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(stm32cubef4) add_subdirectory(mxchip_bsp) diff --git a/Microchip/ATSAME54-XPRO/app/CMakeLists.txt b/Microchip/ATSAME54-XPRO/app/CMakeLists.txt index 49d76609..8d2206e9 100644 --- a/Microchip/ATSAME54-XPRO/app/CMakeLists.txt +++ b/Microchip/ATSAME54-XPRO/app/CMakeLists.txt @@ -4,7 +4,6 @@ set(SOURCES startup/${THREADX_TOOLCHAIN}/tx_initialize_low_level.S startup/${THREADX_TOOLCHAIN}/startup_same54.c - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -17,10 +16,8 @@ target_link_libraries(${PROJECT_NAME} PUBLIC azrtos::threadx azrtos::netxduo - atmel_start app_common - jsmn netxdriver bme280 ) diff --git a/Microchip/ATSAME54-XPRO/app/legacy/mqtt.c b/Microchip/ATSAME54-XPRO/app/legacy/mqtt.c deleted file mode 100644 index af436f42..00000000 --- a/Microchip/ATSAME54-XPRO/app/legacy/mqtt.c +++ /dev/null @@ -1,199 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "atmel_start.h" -#include "weather_click.h" - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - // Pin level set to "low" state - printf("LED is turned ON\r\n"); - } - else - { - // Pin level set to "high" state - printf("LED is turned OFF\r\n"); - } - - gpio_set_pin_level(PC18, !level); -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - float temperature; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("Starting MQTT loop\r\n"); - while (true) - { - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - -#if __SENSOR_BME280__ == 1 - // Print the compensated temperature readings - struct bme280_data data; - if (read_bme280(&data) != BME280_OK) - { - printf("FAILED to read weather click sensor\r\n"); - } - temperature = data.temperature; -#else - temperature = 23.5; -#endif - - // Send the temperature as a telemetry event - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", temperature); - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/Microchip/ATSAME54-XPRO/app/legacy/mqtt.h b/Microchip/ATSAME54-XPRO/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/Microchip/ATSAME54-XPRO/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/Microchip/ATSAME54-XPRO/app/main.c b/Microchip/ATSAME54-XPRO/app/main.c index c8519401..39ca8733 100644 --- a/Microchip/ATSAME54-XPRO/app/main.c +++ b/Microchip/ATSAME54-XPRO/app/main.c @@ -11,7 +11,6 @@ #include "networking.h" #include "sntp_client.h" -#include "legacy/mqtt.h" #include "nx_client.h" #define AZURE_THREAD_STACK_SIZE 4096 @@ -24,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = network_init(nx_driver_same54))) @@ -32,11 +31,7 @@ static void azure_thread_entry(ULONG parameter) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time))) -#endif { printf("Failed to run Azure IoT (0x%08x)\r\n", status); } @@ -44,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/Microchip/ATSAME54-XPRO/azure-pipelines.yml b/Microchip/ATSAME54-XPRO/azure-pipelines.yml deleted file mode 100644 index 7e14b328..00000000 --- a/Microchip/ATSAME54-XPRO/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) - -resources: - repositories: - - repository: Device-Lab - type: git - endpoint: Devicelab - name: Device-Lab/Device-Lab - -trigger: - batch: true - branches: - include: - - master - paths: - exclude: - - doc/* - -jobs: -- job: Microchip_Build - pool: - name: 'DDE' - demands: - - MICROCHIPATSAME54XPRO -equals true - steps: - - checkout: self - clean: true - submodules: recursive - - checkout: Device-Lab - clean: true - - # Azure CLI to start certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1' - arguments: '$(Build.SourcesDirectory)\getting-started\shared\model' - useGlobalConfig: true - displayName: "Start Certification" - - # modify config with credentials - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\update_config.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -ConfigFilePath '$(Build.SourcesDirectory)\getting-started\Microchip\ATSAME54-XPRO\app\azure_config.h' - displayName: 'Modify config file' - - # Build binary - - script: | - echo %PATH% - cd $(Build.SourcesDirectory)\getting-started\Microchip\ATSAME54-XPRO\tools - .\rebuild.bat - displayName: "Build Binary" - - # Flash binary to hardware - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\flashing_tools\flash-board.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -BinPath '$(Build.SourcesDirectory)\getting-started\Microchip\ATSAME54-XPRO\build\app\atsame54_azure_iot.bin' - displayName: 'Flash binary' - - # Monitor device for successful connection to Iot Hub - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\scan_serial.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -TestString 'SUCCESS: Connected to IoT Hub' - displayName: 'Scan serial port' - - # Azure CLI to run certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\run_certification.ps1' - arguments: $(TESTID) - useGlobalConfig: true - displayName: "Run Certification" diff --git a/Microchip/ATSAME54-XPRO/lib/CMakeLists.txt b/Microchip/ATSAME54-XPRO/lib/CMakeLists.txt index 7f452967..f9424859 100644 --- a/Microchip/ATSAME54-XPRO/lib/CMakeLists.txt +++ b/Microchip/ATSAME54-XPRO/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(netx_driver) add_subdirectory(atmel_start) diff --git a/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSE.txt b/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSE.txt deleted file mode 100644 index 76974a36..00000000 --- a/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSE.txt +++ /dev/null @@ -1,246 +0,0 @@ -MICROSOFT SOFTWARE LICENSE TERMS - -MICROSOFT AZURE RTOS - -Shape - -These license terms are an agreement between you and Microsoft Corporation (or -one of its affiliates). They apply to the software named above and any Microsoft -services or software updates (except to the extent such services or updates are -accompanied by new or additional terms, in which case those different terms -apply prospectively and do not alter your or Microsoft’s rights relating to -pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU -HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. - -INSTALLATION AND USE RIGHTS. - -General. You may install and use the software and the included Microsoft -applications solely for internal development, testing and evaluation purposes. -Any distribution or production use requires a separate license as set forth in -Section 2. - -Contributions. Microsoft welcomes contributions to this software. In the event -that you make a contribution to this software you will be required to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and -actually do, grant Microsoft the rights to use your contribution. For details, -visit https://cla.microsoft.com. - -Included Microsoft Applications. The software includes other Microsoft -applications which are governed by the licenses embedded in or made available -with those applications. - -Third Party Components. The software may include third party components with -separate legal notices or governed by other agreements, as may be described -within the software or in the ThirdPartyNotices file(s) accompanying the -software. - -Competitive Benchmarking. If you are a direct competitor, and you access or use -the software for purposes of competitive benchmarking, analysis, or intelligence -gathering, you waive as against Microsoft, its subsidiaries, and its affiliated -companies (including prospectively) any competitive use, access, and -benchmarking test restrictions in the terms governing your software to the -extent your terms of use are, or purport to be, more restrictive than -Microsoft’s terms. If you do not waive any such purported restrictions in the -terms governing your software, you are not allowed to access or use this -software, and will not do so. - -DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on -microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file -named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with -the software you have the following rights in and to the software solely when -used in combination with the hardware. In the event hardware is not listed in -the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2. - -Distribution and Production Use Rights. - -You may use the software in production (e.g. program the modified or unmodified -software to devices you own or control) and distribute (i.e. make available to -third parties) the modified or unmodified binary image produced from this code. - - -You may permit your device distributors or developers to copy and distribute the -binary image as programmed or to be programmed to your devices. - -You may redistribute the unmodified or modified source to your device -distributors or developers. Modifications must be clearly marked. Any -redistribution in source code form must contain this license and any other -licenses that accompany the software. - -Requirements. For any code you distribute, you must: - -when distributed in binary form, except as embedded in a device, include with -such distribution the terms of this agreement; - -when distributed in source code form to distributors or developers of your -devices, include with such distribution the terms of this agreement; and - -indemnify, defend and hold harmless Microsoft from any claims, including -attorneys’ fees, related to the distribution or use of your devices, except to -the extent that any claim is based solely on the unmodified software. - -Restrictions. You may not: - -use or modify the software to create a competing real time operating system -software; - -remove any copyright notices or licenses contained in the software; - -use Microsoft’s trademarks or trade dress in your application in any way that -suggests your device or application comes from or is endorsed by Microsoft; - -transfer individual components, specific libraries, classes, functions or code -fragments of the software separately for purposes unrelated to the software; or - -use or distribute the software in any way that would subject the software or -Microsoft’s intellectual property or technology to any other license terms. - -SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all -other rights. Unless applicable law gives you more rights despite this -limitation, you will not (and have no right to): - -remove, minimize, block, or modify any notices of Microsoft or its suppliers in -the software; - -use the software in any way that is against the law or to create or propagate -malware; or - -share, publish, distribute, or lease the software (except as permitted in -Section 2 above), or provide the software as a stand-alone offering for others -to use. - -DATA. This software may interact with other Microsoft products that collect data -that is transmitted to Microsoft. To learn more about how Microsoft processes -personal data we collect, please see the Microsoft Privacy Statement at -https://go.microsoft.com/fwlink/?LinkId=248681. - -EXPORT RESTRICTIONS. You must comply with all domestic and international export -laws and regulations that apply to the software, which include restrictions on -destinations, end users, and end use. For further information on export -restrictions, visit https://aka.ms/exporting. - -SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any -support services for the software. Any support provided is “as is”, “with all -faults”, and without warranty of any kind. - -UPDATES. Microsoft may periodically update the software. You may obtain updates -only from Microsoft or Microsoft-authorized sources. Updates may not include or -support all existing software features, services, or peripheral devices. - -TERMINATION. Without prejudice to any other rights, Microsoft may terminate this -agreement if you fail to comply with any of its terms or conditions. In such -event, you must destroy all copies of the software and all of its component -parts. - -ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for -supplements, updates, or third-party applications, is the entire agreement for -the software. To the extent you have entered into a separate agreement with -Microsoft relating specifically to the software, the terms in such agreement -shall control. - -APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in -the United States or Canada, the laws of the state or province where you live -(or, if a business, where your principal place of business is located) govern -the interpretation of this agreement, claims for its breach, and all other -claims (including consumer protection, unfair competition, and tort claims), -regardless of conflict of laws principles. If you acquired the software in any -other country, its laws apply. If U.S. federal jurisdiction exists, you and -Microsoft consent to exclusive jurisdiction and venue in the federal court in -King County, Washington for all disputes heard in court. If not, you and -Microsoft consent to exclusive jurisdiction and venue in the Superior Court of -King County, Washington for all disputes heard in court. - -CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal -rights. You may have other rights, including consumer rights, under the laws of -your state or country. Separate and apart from your relationship with Microsoft, -you may also have rights with respect to the party from which you acquired the -software. This agreement does not change those other rights if the laws of your -state or country do not permit it to do so. For example, if you acquired the -software in one of the below regions, or mandatory country law applies, then the -following provisions apply to you: - -Australia. You have statutory guarantees under the Australian Consumer Law and -nothing in this agreement is intended to affect those rights. - -Germany and Austria. - -i.Warranty. The properly licensed software will perform substantially as -described in any Microsoft materials that accompany the software. However, -Microsoft gives no contractual guarantee in relation to the licensed software. - -ii.Limitation of Liability. In case of intentional conduct, gross negligence, -claims based on the Product Liability Act, as well as, in case of death or -personal or physical injury, Microsoft is liable according to the statutory law. - - -Subject to the foregoing clause ii., Microsoft will only be liable for slight -negligence if Microsoft is in breach of such material contractual obligations, -the fulfillment of which facilitate the due performance of this agreement, the -breach of which would endanger the purpose of this agreement and the compliance -with which a party may constantly trust in (so-called "cardinal obligations"). -In other cases of slight negligence, Microsoft will not be liable for slight -negligence. - -DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF -USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO -THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED -WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND -NON-INFRINGEMENT. - -LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING -DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM -MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT -RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, -INDIRECT, OR INCIDENTAL DAMAGES. - -This limitation applies to (a) anything related to the software, services, -content (including code) on third party Internet sites, or third party -applications; and (b) claims for breach of contract, warranty, guarantee, or -condition; strict liability, negligence, or other tort; or any other claim; in -each case to the extent permitted by applicable law. - -It also applies even if Microsoft knew or should have known about the -possibility of the damages. The above limitation or exclusion may not apply to -you because your state, province, or country may not allow the exclusion or -limitation of incidental, consequential, or other damages. - - - -Please note: As this software is distributed in Canada, some of the clauses in -this agreement are provided below in French. - -Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce -contrat sont fournies ci-dessous en français. - -EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel -». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft -n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits -additionnels en vertu du droit local sur la protection des consommateurs, que ce -contrat ne peut modifier. La ou elles sont permises par le droit locale, les -garanties implicites de qualité marchande, d’adéquation à un usage particulier -et d’absence de contrefaçon sont exclues. - -LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES -DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une -indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous -ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris -les dommages spéciaux, indirects ou accessoires et pertes de bénéfices. - -Cette limitation concerne: - -•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le -code) figurant sur des sites Internet tiers ou dans des programmes tiers; et - -•les réclamations au titre de violation de contrat ou de garantie, ou au titre -de responsabilité stricte, de négligence ou d’une autre faute dans la limite -autorisée par la loi en vigueur. - -Elle s’applique également, même si Microsoft connaissait ou devrait connaître -l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la -limitation de responsabilité pour les dommages indirects, accessoires ou de -quelque nature que ce soit, il se peut que la limitation ou l’exclusion -ci-dessus ne s’appliquera pas à votre égard. - -EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous -pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent -contrat ne modifie pas les droits que vous confèrent les lois de votre pays si -celles-ci ne le permettent pas. \ No newline at end of file diff --git a/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSED-HARDWARE.txt b/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSED-HARDWARE.txt deleted file mode 100644 index 77dd1abf..00000000 --- a/Microchip/ATSAME54-XPRO/lib/netx_driver/LICENSED-HARDWARE.txt +++ /dev/null @@ -1,16 +0,0 @@ -LICENSED HARDWARE LIST - -Last Updated: 2020-05-08 - -Microsoft has entered into OEM Agreements with manufacturers of the following -microprocessors and microcontrollers (the “hardware”) to enable those -manufacturers to include and distribute Azure RTOS in certain hardware. If you -have obtained and/or are developing on microprocessor(s) and/or -microcontroller(s) (“hardware”) listed below you inherit the “Distribution and -Production Use” rights in Section 2 of the Microsoft Software License Terms for -Microsoft Azure RTOS. If hardware is not listed below, you do not have those -rights. - --------------------------------------------------------------------------------- - -More coming soon. Please check back frequently for updates. \ No newline at end of file diff --git a/NOTICE.txt b/NOTICE.txt index 570b6807..b2e5756d 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -28,256 +28,6 @@ bring it to our attention by posting an issue. The attached notices are provided for information only. ------------------------------------------------------------------------------- -* Azure RTOS - -MICROSOFT SOFTWARE LICENSE TERMS - -MICROSOFT AZURE RTOS - -Shape - -These license terms are an agreement between you and Microsoft Corporation (or -one of its affiliates). They apply to the software named above and any Microsoft -services or software updates (except to the extent such services or updates are -accompanied by new or additional terms, in which case those different terms -apply prospectively and do not alter your or Microsoft’s rights relating to -pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU -HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. - -INSTALLATION AND USE RIGHTS. - -General. You may install and use the software and the included Microsoft -applications solely for internal development, testing and evaluation purposes. -Any distribution or production use requires a separate license as set forth in -Section 2. - -Contributions. Microsoft welcomes contributions to this software. In the event -that you make a contribution to this software you will be required to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and -actually do, grant Microsoft the rights to use your contribution. For details, -visit https://cla.microsoft.com. - -Included Microsoft Applications. The software includes other Microsoft -applications which are governed by the licenses embedded in or made available -with those applications. - -Third Party Components. The software may include third party components with -separate legal notices or governed by other agreements, as may be described -within the software or in the ThirdPartyNotices file(s) accompanying the -software. - -Competitive Benchmarking. If you are a direct competitor, and you access or use -the software for purposes of competitive benchmarking, analysis, or intelligence -gathering, you waive as against Microsoft, its subsidiaries, and its affiliated -companies (including prospectively) any competitive use, access, and -benchmarking test restrictions in the terms governing your software to the -extent your terms of use are, or purport to be, more restrictive than -Microsoft’s terms. If you do not waive any such purported restrictions in the -terms governing your software, you are not allowed to access or use this -software, and will not do so. - -DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on -microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file -named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with -the software you have the following rights in and to the software solely when -used in combination with the hardware. In the event hardware is not listed in -the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2. - -Distribution and Production Use Rights. - -You may use the software in production (e.g. program the modified or unmodified -software to devices you own or control) and distribute (i.e. make available to -third parties) the modified or unmodified binary image produced from this code. - - -You may permit your device distributors or developers to copy and distribute the -binary image as programmed or to be programmed to your devices. - -You may redistribute the unmodified or modified source to your device -distributors or developers. Modifications must be clearly marked. Any -redistribution in source code form must contain this license and any other -licenses that accompany the software. - -Requirements. For any code you distribute, you must: - -when distributed in binary form, except as embedded in a device, include with -such distribution the terms of this agreement; - -when distributed in source code form to distributors or developers of your -devices, include with such distribution the terms of this agreement; and - -indemnify, defend and hold harmless Microsoft from any claims, including -attorneys’ fees, related to the distribution or use of your devices, except to -the extent that any claim is based solely on the unmodified software. - -Restrictions. You may not: - -use or modify the software to create a competing real time operating system -software; - -remove any copyright notices or licenses contained in the software; - -use Microsoft’s trademarks or trade dress in your application in any way that -suggests your device or application comes from or is endorsed by Microsoft; - -transfer individual components, specific libraries, classes, functions or code -fragments of the software separately for purposes unrelated to the software; or - -use or distribute the software in any way that would subject the software or -Microsoft’s intellectual property or technology to any other license terms. - -SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all -other rights. Unless applicable law gives you more rights despite this -limitation, you will not (and have no right to): - -remove, minimize, block, or modify any notices of Microsoft or its suppliers in -the software; - -use the software in any way that is against the law or to create or propagate -malware; or - -share, publish, distribute, or lease the software (except as permitted in -Section 2 above), or provide the software as a stand-alone offering for others -to use. - -DATA. This software may interact with other Microsoft products that collect data -that is transmitted to Microsoft. To learn more about how Microsoft processes -personal data we collect, please see the Microsoft Privacy Statement at -https://go.microsoft.com/fwlink/?LinkId=248681. - -EXPORT RESTRICTIONS. You must comply with all domestic and international export -laws and regulations that apply to the software, which include restrictions on -destinations, end users, and end use. For further information on export -restrictions, visit https://aka.ms/exporting. - -SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any -support services for the software. Any support provided is “as is”, “with all -faults”, and without warranty of any kind. - -UPDATES. Microsoft may periodically update the software. You may obtain updates -only from Microsoft or Microsoft-authorized sources. Updates may not include or -support all existing software features, services, or peripheral devices. - -TERMINATION. Without prejudice to any other rights, Microsoft may terminate this -agreement if you fail to comply with any of its terms or conditions. In such -event, you must destroy all copies of the software and all of its component -parts. - -ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for -supplements, updates, or third-party applications, is the entire agreement for -the software. To the extent you have entered into a separate agreement with -Microsoft relating specifically to the software, the terms in such agreement -shall control. - -APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in -the United States or Canada, the laws of the state or province where you live -(or, if a business, where your principal place of business is located) govern -the interpretation of this agreement, claims for its breach, and all other -claims (including consumer protection, unfair competition, and tort claims), -regardless of conflict of laws principles. If you acquired the software in any -other country, its laws apply. If U.S. federal jurisdiction exists, you and -Microsoft consent to exclusive jurisdiction and venue in the federal court in -King County, Washington for all disputes heard in court. If not, you and -Microsoft consent to exclusive jurisdiction and venue in the Superior Court of -King County, Washington for all disputes heard in court. - -CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal -rights. You may have other rights, including consumer rights, under the laws of -your state or country. Separate and apart from your relationship with Microsoft, -you may also have rights with respect to the party from which you acquired the -software. This agreement does not change those other rights if the laws of your -state or country do not permit it to do so. For example, if you acquired the -software in one of the below regions, or mandatory country law applies, then the -following provisions apply to you: - -Australia. You have statutory guarantees under the Australian Consumer Law and -nothing in this agreement is intended to affect those rights. - -Germany and Austria. - -i.Warranty. The properly licensed software will perform substantially as -described in any Microsoft materials that accompany the software. However, -Microsoft gives no contractual guarantee in relation to the licensed software. - -ii.Limitation of Liability. In case of intentional conduct, gross negligence, -claims based on the Product Liability Act, as well as, in case of death or -personal or physical injury, Microsoft is liable according to the statutory law. - - -Subject to the foregoing clause ii., Microsoft will only be liable for slight -negligence if Microsoft is in breach of such material contractual obligations, -the fulfillment of which facilitate the due performance of this agreement, the -breach of which would endanger the purpose of this agreement and the compliance -with which a party may constantly trust in (so-called "cardinal obligations"). -In other cases of slight negligence, Microsoft will not be liable for slight -negligence. - -DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF -USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO -THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED -WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND -NON-INFRINGEMENT. - -LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING -DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM -MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT -RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, -INDIRECT, OR INCIDENTAL DAMAGES. - -This limitation applies to (a) anything related to the software, services, -content (including code) on third party Internet sites, or third party -applications; and (b) claims for breach of contract, warranty, guarantee, or -condition; strict liability, negligence, or other tort; or any other claim; in -each case to the extent permitted by applicable law. - -It also applies even if Microsoft knew or should have known about the -possibility of the damages. The above limitation or exclusion may not apply to -you because your state, province, or country may not allow the exclusion or -limitation of incidental, consequential, or other damages. - - - -Please note: As this software is distributed in Canada, some of the clauses in -this agreement are provided below in French. - -Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce -contrat sont fournies ci-dessous en français. - -EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel -». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft -n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits -additionnels en vertu du droit local sur la protection des consommateurs, que ce -contrat ne peut modifier. La ou elles sont permises par le droit locale, les -garanties implicites de qualité marchande, d’adéquation à un usage particulier -et d’absence de contrefaçon sont exclues. - -LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES -DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une -indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous -ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris -les dommages spéciaux, indirects ou accessoires et pertes de bénéfices. - -Cette limitation concerne: - -•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le -code) figurant sur des sites Internet tiers ou dans des programmes tiers; et - -•les réclamations au titre de violation de contrat ou de garantie, ou au titre -de responsabilité stricte, de négligence ou d’une autre faute dans la limite -autorisée par la loi en vigueur. - -Elle s’applique également, même si Microsoft connaissait ou devrait connaître -l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la -limitation de responsabilité pour les dommages indirects, accessoires ou de -quelque nature que ce soit, il se peut que la limitation ou l’exclusion -ci-dessus ne s’appliquera pas à votre égard. - -EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous -pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent -contrat ne modifie pas les droits que vous confèrent les lois de votre pays si -celles-ci ne le permettent pas. - ------------------------------------------------------------------------------ * CMSIS @@ -484,29 +234,6 @@ celles-ci ne le permettent pas. limitations under the License. ------------------------------------------------------------------------------- -* JSMN - -Copyright (c) 2010 Serge A. Zaitsev - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - ------------------------------------------------------------------------------ * Microchip: Atmel Start diff --git a/NXP/MIMXRT1050-EVKB/app/CMakeLists.txt b/NXP/MIMXRT1050-EVKB/app/CMakeLists.txt index b8df0e7a..e6b8ae93 100644 --- a/NXP/MIMXRT1050-EVKB/app/CMakeLists.txt +++ b/NXP/MIMXRT1050-EVKB/app/CMakeLists.txt @@ -4,7 +4,6 @@ set(SOURCES startup/${THREADX_TOOLCHAIN}/startup_MIMXRT1052.S startup/${THREADX_TOOLCHAIN}/tx_initialize_low_level.S - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -20,7 +19,6 @@ target_link_libraries(${PROJECT_NAME} azrtos::netxduo app_common - jsmn MIMXRT1050-evk netx_driver ) diff --git a/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.c b/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.c deleted file mode 100644 index f9c38c40..00000000 --- a/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.c +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - printf("LED is turned ON\r\n"); - // The User LED on the board shares the same pin as ENET RST so is unusable - // USER_LED_ON(); - } - else - { - printf("LED is turned OFF\r\n"); - // The User LED on the board shares the same pin as ENET RST so is unusable - // USER_LED_OFF(); - } -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - float temperature; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("\r\nStarting MQTT loop\r\n"); - while (true) - { - temperature = 28.5; - - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - - // Send the temperature as a telemetry event - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", temperature); - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.h b/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/NXP/MIMXRT1050-EVKB/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/NXP/MIMXRT1050-EVKB/app/main.c b/NXP/MIMXRT1050-EVKB/app/main.c index 42eb8a81..4308236b 100644 --- a/NXP/MIMXRT1050-EVKB/app/main.c +++ b/NXP/MIMXRT1050-EVKB/app/main.c @@ -11,7 +11,6 @@ #include "networking.h" #include "sntp_client.h" -#include "legacy/mqtt.h" #include "nx_client.h" #define AZURE_THREAD_STACK_SIZE 4096 @@ -24,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = network_init(nx_driver_imx))) @@ -32,11 +31,7 @@ static void azure_thread_entry(ULONG parameter) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time))) -#endif { printf("Failed to run Azure IoT (0x%04x)\r\n", status); } @@ -44,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/NXP/MIMXRT1050-EVKB/lib/CMakeLists.txt b/NXP/MIMXRT1050-EVKB/lib/CMakeLists.txt index 92c41aac..1124072a 100644 --- a/NXP/MIMXRT1050-EVKB/lib/CMakeLists.txt +++ b/NXP/MIMXRT1050-EVKB/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(netx_driver) add_subdirectory(MIMXRT1050-evk) diff --git a/NXP/MIMXRT1060-EVK/app/CMakeLists.txt b/NXP/MIMXRT1060-EVK/app/CMakeLists.txt index b08cec99..0eb3d5f2 100644 --- a/NXP/MIMXRT1060-EVK/app/CMakeLists.txt +++ b/NXP/MIMXRT1060-EVK/app/CMakeLists.txt @@ -4,7 +4,6 @@ set(SOURCES startup/${THREADX_TOOLCHAIN}/startup_MIMXRT1062.S startup/${THREADX_TOOLCHAIN}/tx_initialize_low_level.S - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -20,7 +19,6 @@ target_link_libraries(${PROJECT_NAME} azrtos::netxduo app_common - jsmn MIMXRT1060-evk netx_driver ) diff --git a/NXP/MIMXRT1060-EVK/app/legacy/mqtt.c b/NXP/MIMXRT1060-EVK/app/legacy/mqtt.c deleted file mode 100644 index f9c38c40..00000000 --- a/NXP/MIMXRT1060-EVK/app/legacy/mqtt.c +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - printf("LED is turned ON\r\n"); - // The User LED on the board shares the same pin as ENET RST so is unusable - // USER_LED_ON(); - } - else - { - printf("LED is turned OFF\r\n"); - // The User LED on the board shares the same pin as ENET RST so is unusable - // USER_LED_OFF(); - } -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - float temperature; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("\r\nStarting MQTT loop\r\n"); - while (true) - { - temperature = 28.5; - - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - - // Send the temperature as a telemetry event - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", temperature); - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/NXP/MIMXRT1060-EVK/app/legacy/mqtt.h b/NXP/MIMXRT1060-EVK/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/NXP/MIMXRT1060-EVK/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/NXP/MIMXRT1060-EVK/app/main.c b/NXP/MIMXRT1060-EVK/app/main.c index 4495db2e..41feb1da 100644 --- a/NXP/MIMXRT1060-EVK/app/main.c +++ b/NXP/MIMXRT1060-EVK/app/main.c @@ -11,7 +11,6 @@ #include "networking.h" #include "sntp_client.h" -#include "legacy/mqtt.h" #include "nx_client.h" #define AZURE_THREAD_STACK_SIZE 4096 @@ -24,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = network_init(nx_driver_imx))) @@ -32,11 +31,7 @@ static void azure_thread_entry(ULONG parameter) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time))) -#endif { printf("Failed to run Azure IoT (0x%08x)\r\n", status); } @@ -44,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/NXP/MIMXRT1060-EVK/azure-pipelines.yml b/NXP/MIMXRT1060-EVK/azure-pipelines.yml deleted file mode 100644 index 3953dd1c..00000000 --- a/NXP/MIMXRT1060-EVK/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) - -resources: - repositories: - - repository: Device-Lab - type: git - endpoint: Devicelab - name: Device-Lab/Device-Lab - -trigger: - batch: true - branches: - include: - - master - paths: - exclude: - - doc/* - -jobs: -- job: NXP_Build - pool: - name: 'DDE' - demands: - - NXPMIMXRT1060EVK-jlink -equals true - steps: - - checkout: self - clean: true - submodules: recursive - - checkout: Device-Lab - clean: true - - # Azure CLI to start certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1' - arguments: '$(Build.SourcesDirectory)\getting-started\shared\model' - useGlobalConfig: true - displayName: "Start Certification" - - # modify config with credentials - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\update_config.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -ConfigFilePath '$(Build.SourcesDirectory)\getting-started\NXP\MIMXRT1060-EVK\app\azure_config.h' - displayName: 'Modify config file' - - # Build binary - - script: | - echo %PATH% - cd $(Build.SourcesDirectory)\getting-started\NXP\MIMXRT1060-EVK\tools - .\rebuild.bat - displayName: "Build Binary" - - # Flash binary to hardware - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\flashing_tools\flash-board.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -BinPath '$(Build.SourcesDirectory)\getting-started\NXP\MIMXRT1060-EVK\build\app\mimxrt1060_azure_iot.hex' - displayName: 'Flash binary' - - # Monitor device for successful connection to Iot Hub - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\scan_serial.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -TestString 'SUCCESS: Connected to IoT Hub' - displayName: 'Scan serial port' - - # Azure CLI to run certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\run_certification.ps1' - arguments: $(TESTID) - useGlobalConfig: true - displayName: "Run Certification" diff --git a/NXP/MIMXRT1060-EVK/lib/CMakeLists.txt b/NXP/MIMXRT1060-EVK/lib/CMakeLists.txt index c782d811..a2f649d2 100644 --- a/NXP/MIMXRT1060-EVK/lib/CMakeLists.txt +++ b/NXP/MIMXRT1060-EVK/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(netx_driver) add_subdirectory(MIMXRT1060-evk) diff --git a/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSE.txt b/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSE.txt deleted file mode 100644 index 76974a36..00000000 --- a/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSE.txt +++ /dev/null @@ -1,246 +0,0 @@ -MICROSOFT SOFTWARE LICENSE TERMS - -MICROSOFT AZURE RTOS - -Shape - -These license terms are an agreement between you and Microsoft Corporation (or -one of its affiliates). They apply to the software named above and any Microsoft -services or software updates (except to the extent such services or updates are -accompanied by new or additional terms, in which case those different terms -apply prospectively and do not alter your or Microsoft’s rights relating to -pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU -HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. - -INSTALLATION AND USE RIGHTS. - -General. You may install and use the software and the included Microsoft -applications solely for internal development, testing and evaluation purposes. -Any distribution or production use requires a separate license as set forth in -Section 2. - -Contributions. Microsoft welcomes contributions to this software. In the event -that you make a contribution to this software you will be required to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and -actually do, grant Microsoft the rights to use your contribution. For details, -visit https://cla.microsoft.com. - -Included Microsoft Applications. The software includes other Microsoft -applications which are governed by the licenses embedded in or made available -with those applications. - -Third Party Components. The software may include third party components with -separate legal notices or governed by other agreements, as may be described -within the software or in the ThirdPartyNotices file(s) accompanying the -software. - -Competitive Benchmarking. If you are a direct competitor, and you access or use -the software for purposes of competitive benchmarking, analysis, or intelligence -gathering, you waive as against Microsoft, its subsidiaries, and its affiliated -companies (including prospectively) any competitive use, access, and -benchmarking test restrictions in the terms governing your software to the -extent your terms of use are, or purport to be, more restrictive than -Microsoft’s terms. If you do not waive any such purported restrictions in the -terms governing your software, you are not allowed to access or use this -software, and will not do so. - -DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on -microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file -named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with -the software you have the following rights in and to the software solely when -used in combination with the hardware. In the event hardware is not listed in -the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2. - -Distribution and Production Use Rights. - -You may use the software in production (e.g. program the modified or unmodified -software to devices you own or control) and distribute (i.e. make available to -third parties) the modified or unmodified binary image produced from this code. - - -You may permit your device distributors or developers to copy and distribute the -binary image as programmed or to be programmed to your devices. - -You may redistribute the unmodified or modified source to your device -distributors or developers. Modifications must be clearly marked. Any -redistribution in source code form must contain this license and any other -licenses that accompany the software. - -Requirements. For any code you distribute, you must: - -when distributed in binary form, except as embedded in a device, include with -such distribution the terms of this agreement; - -when distributed in source code form to distributors or developers of your -devices, include with such distribution the terms of this agreement; and - -indemnify, defend and hold harmless Microsoft from any claims, including -attorneys’ fees, related to the distribution or use of your devices, except to -the extent that any claim is based solely on the unmodified software. - -Restrictions. You may not: - -use or modify the software to create a competing real time operating system -software; - -remove any copyright notices or licenses contained in the software; - -use Microsoft’s trademarks or trade dress in your application in any way that -suggests your device or application comes from or is endorsed by Microsoft; - -transfer individual components, specific libraries, classes, functions or code -fragments of the software separately for purposes unrelated to the software; or - -use or distribute the software in any way that would subject the software or -Microsoft’s intellectual property or technology to any other license terms. - -SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all -other rights. Unless applicable law gives you more rights despite this -limitation, you will not (and have no right to): - -remove, minimize, block, or modify any notices of Microsoft or its suppliers in -the software; - -use the software in any way that is against the law or to create or propagate -malware; or - -share, publish, distribute, or lease the software (except as permitted in -Section 2 above), or provide the software as a stand-alone offering for others -to use. - -DATA. This software may interact with other Microsoft products that collect data -that is transmitted to Microsoft. To learn more about how Microsoft processes -personal data we collect, please see the Microsoft Privacy Statement at -https://go.microsoft.com/fwlink/?LinkId=248681. - -EXPORT RESTRICTIONS. You must comply with all domestic and international export -laws and regulations that apply to the software, which include restrictions on -destinations, end users, and end use. For further information on export -restrictions, visit https://aka.ms/exporting. - -SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any -support services for the software. Any support provided is “as is”, “with all -faults”, and without warranty of any kind. - -UPDATES. Microsoft may periodically update the software. You may obtain updates -only from Microsoft or Microsoft-authorized sources. Updates may not include or -support all existing software features, services, or peripheral devices. - -TERMINATION. Without prejudice to any other rights, Microsoft may terminate this -agreement if you fail to comply with any of its terms or conditions. In such -event, you must destroy all copies of the software and all of its component -parts. - -ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for -supplements, updates, or third-party applications, is the entire agreement for -the software. To the extent you have entered into a separate agreement with -Microsoft relating specifically to the software, the terms in such agreement -shall control. - -APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in -the United States or Canada, the laws of the state or province where you live -(or, if a business, where your principal place of business is located) govern -the interpretation of this agreement, claims for its breach, and all other -claims (including consumer protection, unfair competition, and tort claims), -regardless of conflict of laws principles. If you acquired the software in any -other country, its laws apply. If U.S. federal jurisdiction exists, you and -Microsoft consent to exclusive jurisdiction and venue in the federal court in -King County, Washington for all disputes heard in court. If not, you and -Microsoft consent to exclusive jurisdiction and venue in the Superior Court of -King County, Washington for all disputes heard in court. - -CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal -rights. You may have other rights, including consumer rights, under the laws of -your state or country. Separate and apart from your relationship with Microsoft, -you may also have rights with respect to the party from which you acquired the -software. This agreement does not change those other rights if the laws of your -state or country do not permit it to do so. For example, if you acquired the -software in one of the below regions, or mandatory country law applies, then the -following provisions apply to you: - -Australia. You have statutory guarantees under the Australian Consumer Law and -nothing in this agreement is intended to affect those rights. - -Germany and Austria. - -i.Warranty. The properly licensed software will perform substantially as -described in any Microsoft materials that accompany the software. However, -Microsoft gives no contractual guarantee in relation to the licensed software. - -ii.Limitation of Liability. In case of intentional conduct, gross negligence, -claims based on the Product Liability Act, as well as, in case of death or -personal or physical injury, Microsoft is liable according to the statutory law. - - -Subject to the foregoing clause ii., Microsoft will only be liable for slight -negligence if Microsoft is in breach of such material contractual obligations, -the fulfillment of which facilitate the due performance of this agreement, the -breach of which would endanger the purpose of this agreement and the compliance -with which a party may constantly trust in (so-called "cardinal obligations"). -In other cases of slight negligence, Microsoft will not be liable for slight -negligence. - -DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF -USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO -THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED -WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND -NON-INFRINGEMENT. - -LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING -DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM -MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT -RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, -INDIRECT, OR INCIDENTAL DAMAGES. - -This limitation applies to (a) anything related to the software, services, -content (including code) on third party Internet sites, or third party -applications; and (b) claims for breach of contract, warranty, guarantee, or -condition; strict liability, negligence, or other tort; or any other claim; in -each case to the extent permitted by applicable law. - -It also applies even if Microsoft knew or should have known about the -possibility of the damages. The above limitation or exclusion may not apply to -you because your state, province, or country may not allow the exclusion or -limitation of incidental, consequential, or other damages. - - - -Please note: As this software is distributed in Canada, some of the clauses in -this agreement are provided below in French. - -Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce -contrat sont fournies ci-dessous en français. - -EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel -». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft -n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits -additionnels en vertu du droit local sur la protection des consommateurs, que ce -contrat ne peut modifier. La ou elles sont permises par le droit locale, les -garanties implicites de qualité marchande, d’adéquation à un usage particulier -et d’absence de contrefaçon sont exclues. - -LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES -DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une -indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous -ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris -les dommages spéciaux, indirects ou accessoires et pertes de bénéfices. - -Cette limitation concerne: - -•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le -code) figurant sur des sites Internet tiers ou dans des programmes tiers; et - -•les réclamations au titre de violation de contrat ou de garantie, ou au titre -de responsabilité stricte, de négligence ou d’une autre faute dans la limite -autorisée par la loi en vigueur. - -Elle s’applique également, même si Microsoft connaissait ou devrait connaître -l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la -limitation de responsabilité pour les dommages indirects, accessoires ou de -quelque nature que ce soit, il se peut que la limitation ou l’exclusion -ci-dessus ne s’appliquera pas à votre égard. - -EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous -pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent -contrat ne modifie pas les droits que vous confèrent les lois de votre pays si -celles-ci ne le permettent pas. \ No newline at end of file diff --git a/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSED-HARDWARE.txt b/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSED-HARDWARE.txt deleted file mode 100644 index 77dd1abf..00000000 --- a/NXP/MIMXRT1060-EVK/lib/netx_driver/LICENSED-HARDWARE.txt +++ /dev/null @@ -1,16 +0,0 @@ -LICENSED HARDWARE LIST - -Last Updated: 2020-05-08 - -Microsoft has entered into OEM Agreements with manufacturers of the following -microprocessors and microcontrollers (the “hardware”) to enable those -manufacturers to include and distribute Azure RTOS in certain hardware. If you -have obtained and/or are developing on microprocessor(s) and/or -microcontroller(s) (“hardware”) listed below you inherit the “Distribution and -Production Use” rights in Section 2 of the Microsoft Software License Terms for -Microsoft Azure RTOS. If hardware is not listed below, you do not have those -rights. - --------------------------------------------------------------------------------- - -More coming soon. Please check back frequently for updates. \ No newline at end of file diff --git a/Renesas/RSK_RX65N_2MB/app/CMakeLists.txt b/Renesas/RSK_RX65N_2MB/app/CMakeLists.txt index d34bd7e6..48ed33a0 100644 --- a/Renesas/RSK_RX65N_2MB/app/CMakeLists.txt +++ b/Renesas/RSK_RX65N_2MB/app/CMakeLists.txt @@ -6,7 +6,6 @@ set(SOURCES startup/${THREADX_TOOLCHAIN}/tx_initialize_low_level.S - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -22,7 +21,6 @@ target_link_libraries(${PROJECT_NAME} azrtos::netxduo app_common - jsmn rx_driver_package netx_driver ) diff --git a/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.c b/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.c deleted file mode 100644 index 2cd4fbdc..00000000 --- a/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.c +++ /dev/null @@ -1,199 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#include "platform.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -#define LED_ON 0 -#define LED_OFF 1 -#define LED0 PORT7.PODR.BIT.B3 -#define LED1 PORTG.PODR.BIT.B7 -#define LED2 PORTG.PODR.BIT.B6 -#define LED3 PORTG.PODR.BIT.B5 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - printf("LED is turned ON\r\n"); - LED0 = LED_ON; - LED1 = LED_ON; - LED2 = LED_ON; - LED3 = LED_ON; - } - else - { - printf("LED is turned OFF\r\n"); - LED0 = LED_OFF; - LED1 = LED_OFF; - LED2 = LED_OFF; - LED3 = LED_OFF; - } -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - float temperature; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("\r\nStarting MQTT loop\r\n"); - while (true) - { - temperature = 28.5; - - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - - // Send the temperature as a telemetry event - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", temperature); - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.h b/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/Renesas/RSK_RX65N_2MB/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/Renesas/RSK_RX65N_2MB/app/main.c b/Renesas/RSK_RX65N_2MB/app/main.c index 7eaa5b21..a418eeec 100644 --- a/Renesas/RSK_RX65N_2MB/app/main.c +++ b/Renesas/RSK_RX65N_2MB/app/main.c @@ -11,7 +11,6 @@ #include "networking.h" #include "sntp_client.h" -#include "legacy/mqtt.h" #include "nx_client.h" #include "azure_config.h" @@ -26,7 +25,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = network_init(nx_driver_rx_fit))) @@ -34,11 +33,7 @@ static void azure_thread_entry(ULONG parameter) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time))) -#endif { printf("Failed to run Azure IoT (0x%04x)\r\n", status); } @@ -46,7 +41,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/Renesas/RSK_RX65N_2MB/lib/CMakeLists.txt b/Renesas/RSK_RX65N_2MB/lib/CMakeLists.txt index b0028bed..14d2900d 100644 --- a/Renesas/RSK_RX65N_2MB/lib/CMakeLists.txt +++ b/Renesas/RSK_RX65N_2MB/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(netx_driver) add_subdirectory(rx_driver_package) diff --git a/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSE.txt b/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSE.txt deleted file mode 100644 index 76974a36..00000000 --- a/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSE.txt +++ /dev/null @@ -1,246 +0,0 @@ -MICROSOFT SOFTWARE LICENSE TERMS - -MICROSOFT AZURE RTOS - -Shape - -These license terms are an agreement between you and Microsoft Corporation (or -one of its affiliates). They apply to the software named above and any Microsoft -services or software updates (except to the extent such services or updates are -accompanied by new or additional terms, in which case those different terms -apply prospectively and do not alter your or Microsoft’s rights relating to -pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU -HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. - -INSTALLATION AND USE RIGHTS. - -General. You may install and use the software and the included Microsoft -applications solely for internal development, testing and evaluation purposes. -Any distribution or production use requires a separate license as set forth in -Section 2. - -Contributions. Microsoft welcomes contributions to this software. In the event -that you make a contribution to this software you will be required to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and -actually do, grant Microsoft the rights to use your contribution. For details, -visit https://cla.microsoft.com. - -Included Microsoft Applications. The software includes other Microsoft -applications which are governed by the licenses embedded in or made available -with those applications. - -Third Party Components. The software may include third party components with -separate legal notices or governed by other agreements, as may be described -within the software or in the ThirdPartyNotices file(s) accompanying the -software. - -Competitive Benchmarking. If you are a direct competitor, and you access or use -the software for purposes of competitive benchmarking, analysis, or intelligence -gathering, you waive as against Microsoft, its subsidiaries, and its affiliated -companies (including prospectively) any competitive use, access, and -benchmarking test restrictions in the terms governing your software to the -extent your terms of use are, or purport to be, more restrictive than -Microsoft’s terms. If you do not waive any such purported restrictions in the -terms governing your software, you are not allowed to access or use this -software, and will not do so. - -DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on -microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file -named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with -the software you have the following rights in and to the software solely when -used in combination with the hardware. In the event hardware is not listed in -the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2. - -Distribution and Production Use Rights. - -You may use the software in production (e.g. program the modified or unmodified -software to devices you own or control) and distribute (i.e. make available to -third parties) the modified or unmodified binary image produced from this code. - - -You may permit your device distributors or developers to copy and distribute the -binary image as programmed or to be programmed to your devices. - -You may redistribute the unmodified or modified source to your device -distributors or developers. Modifications must be clearly marked. Any -redistribution in source code form must contain this license and any other -licenses that accompany the software. - -Requirements. For any code you distribute, you must: - -when distributed in binary form, except as embedded in a device, include with -such distribution the terms of this agreement; - -when distributed in source code form to distributors or developers of your -devices, include with such distribution the terms of this agreement; and - -indemnify, defend and hold harmless Microsoft from any claims, including -attorneys’ fees, related to the distribution or use of your devices, except to -the extent that any claim is based solely on the unmodified software. - -Restrictions. You may not: - -use or modify the software to create a competing real time operating system -software; - -remove any copyright notices or licenses contained in the software; - -use Microsoft’s trademarks or trade dress in your application in any way that -suggests your device or application comes from or is endorsed by Microsoft; - -transfer individual components, specific libraries, classes, functions or code -fragments of the software separately for purposes unrelated to the software; or - -use or distribute the software in any way that would subject the software or -Microsoft’s intellectual property or technology to any other license terms. - -SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all -other rights. Unless applicable law gives you more rights despite this -limitation, you will not (and have no right to): - -remove, minimize, block, or modify any notices of Microsoft or its suppliers in -the software; - -use the software in any way that is against the law or to create or propagate -malware; or - -share, publish, distribute, or lease the software (except as permitted in -Section 2 above), or provide the software as a stand-alone offering for others -to use. - -DATA. This software may interact with other Microsoft products that collect data -that is transmitted to Microsoft. To learn more about how Microsoft processes -personal data we collect, please see the Microsoft Privacy Statement at -https://go.microsoft.com/fwlink/?LinkId=248681. - -EXPORT RESTRICTIONS. You must comply with all domestic and international export -laws and regulations that apply to the software, which include restrictions on -destinations, end users, and end use. For further information on export -restrictions, visit https://aka.ms/exporting. - -SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any -support services for the software. Any support provided is “as is”, “with all -faults”, and without warranty of any kind. - -UPDATES. Microsoft may periodically update the software. You may obtain updates -only from Microsoft or Microsoft-authorized sources. Updates may not include or -support all existing software features, services, or peripheral devices. - -TERMINATION. Without prejudice to any other rights, Microsoft may terminate this -agreement if you fail to comply with any of its terms or conditions. In such -event, you must destroy all copies of the software and all of its component -parts. - -ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for -supplements, updates, or third-party applications, is the entire agreement for -the software. To the extent you have entered into a separate agreement with -Microsoft relating specifically to the software, the terms in such agreement -shall control. - -APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in -the United States or Canada, the laws of the state or province where you live -(or, if a business, where your principal place of business is located) govern -the interpretation of this agreement, claims for its breach, and all other -claims (including consumer protection, unfair competition, and tort claims), -regardless of conflict of laws principles. If you acquired the software in any -other country, its laws apply. If U.S. federal jurisdiction exists, you and -Microsoft consent to exclusive jurisdiction and venue in the federal court in -King County, Washington for all disputes heard in court. If not, you and -Microsoft consent to exclusive jurisdiction and venue in the Superior Court of -King County, Washington for all disputes heard in court. - -CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal -rights. You may have other rights, including consumer rights, under the laws of -your state or country. Separate and apart from your relationship with Microsoft, -you may also have rights with respect to the party from which you acquired the -software. This agreement does not change those other rights if the laws of your -state or country do not permit it to do so. For example, if you acquired the -software in one of the below regions, or mandatory country law applies, then the -following provisions apply to you: - -Australia. You have statutory guarantees under the Australian Consumer Law and -nothing in this agreement is intended to affect those rights. - -Germany and Austria. - -i.Warranty. The properly licensed software will perform substantially as -described in any Microsoft materials that accompany the software. However, -Microsoft gives no contractual guarantee in relation to the licensed software. - -ii.Limitation of Liability. In case of intentional conduct, gross negligence, -claims based on the Product Liability Act, as well as, in case of death or -personal or physical injury, Microsoft is liable according to the statutory law. - - -Subject to the foregoing clause ii., Microsoft will only be liable for slight -negligence if Microsoft is in breach of such material contractual obligations, -the fulfillment of which facilitate the due performance of this agreement, the -breach of which would endanger the purpose of this agreement and the compliance -with which a party may constantly trust in (so-called "cardinal obligations"). -In other cases of slight negligence, Microsoft will not be liable for slight -negligence. - -DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF -USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO -THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED -WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND -NON-INFRINGEMENT. - -LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING -DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM -MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT -RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, -INDIRECT, OR INCIDENTAL DAMAGES. - -This limitation applies to (a) anything related to the software, services, -content (including code) on third party Internet sites, or third party -applications; and (b) claims for breach of contract, warranty, guarantee, or -condition; strict liability, negligence, or other tort; or any other claim; in -each case to the extent permitted by applicable law. - -It also applies even if Microsoft knew or should have known about the -possibility of the damages. The above limitation or exclusion may not apply to -you because your state, province, or country may not allow the exclusion or -limitation of incidental, consequential, or other damages. - - - -Please note: As this software is distributed in Canada, some of the clauses in -this agreement are provided below in French. - -Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce -contrat sont fournies ci-dessous en français. - -EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel -». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft -n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits -additionnels en vertu du droit local sur la protection des consommateurs, que ce -contrat ne peut modifier. La ou elles sont permises par le droit locale, les -garanties implicites de qualité marchande, d’adéquation à un usage particulier -et d’absence de contrefaçon sont exclues. - -LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES -DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une -indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous -ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris -les dommages spéciaux, indirects ou accessoires et pertes de bénéfices. - -Cette limitation concerne: - -•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le -code) figurant sur des sites Internet tiers ou dans des programmes tiers; et - -•les réclamations au titre de violation de contrat ou de garantie, ou au titre -de responsabilité stricte, de négligence ou d’une autre faute dans la limite -autorisée par la loi en vigueur. - -Elle s’applique également, même si Microsoft connaissait ou devrait connaître -l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la -limitation de responsabilité pour les dommages indirects, accessoires ou de -quelque nature que ce soit, il se peut que la limitation ou l’exclusion -ci-dessus ne s’appliquera pas à votre égard. - -EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous -pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent -contrat ne modifie pas les droits que vous confèrent les lois de votre pays si -celles-ci ne le permettent pas. \ No newline at end of file diff --git a/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSED-HARDWARE.txt b/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSED-HARDWARE.txt deleted file mode 100644 index 77dd1abf..00000000 --- a/Renesas/RSK_RX65N_2MB/lib/netx_driver/LICENSED-HARDWARE.txt +++ /dev/null @@ -1,16 +0,0 @@ -LICENSED HARDWARE LIST - -Last Updated: 2020-05-08 - -Microsoft has entered into OEM Agreements with manufacturers of the following -microprocessors and microcontrollers (the “hardware”) to enable those -manufacturers to include and distribute Azure RTOS in certain hardware. If you -have obtained and/or are developing on microprocessor(s) and/or -microcontroller(s) (“hardware”) listed below you inherit the “Distribution and -Production Use” rights in Section 2 of the Microsoft Software License Terms for -Microsoft Azure RTOS. If hardware is not listed below, you do not have those -rights. - --------------------------------------------------------------------------------- - -More coming soon. Please check back frequently for updates. \ No newline at end of file diff --git a/Renesas/RX65N_Cloud_Kit/app/CMakeLists.txt b/Renesas/RX65N_Cloud_Kit/app/CMakeLists.txt index c8469a94..873bd216 100644 --- a/Renesas/RX65N_Cloud_Kit/app/CMakeLists.txt +++ b/Renesas/RX65N_Cloud_Kit/app/CMakeLists.txt @@ -4,7 +4,6 @@ set(SOURCES startup/${THREADX_TOOLCHAIN}/tx_initialize_low_level.S - legacy/mqtt.c azure_config.h nx_client.c board_init.c @@ -21,7 +20,6 @@ target_link_libraries(${PROJECT_NAME} azrtos::netxduo app_common - jsmn rx_driver_package sensorlib netx_driver diff --git a/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.c b/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.c deleted file mode 100644 index 51eac977..00000000 --- a/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.c +++ /dev/null @@ -1,193 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "mqtt.h" - -#include - -#include "azure_iot_mqtt.h" -#include "json_utils.h" -#include "sntp_client.h" - -#include "azure_config.h" - -#include "platform.h" - -#define IOT_MODEL_ID "dtmi:com:example:azurertos:gsg;1" - -#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval" -#define LED_STATE_PROPERTY "ledState" - -#define TELEMETRY_INTERVAL_EVENT 1 - -#define LED_ON 0 -#define LED_OFF 1 -#define LED0 PORTB.PODR.BIT.B0 -#define LED1 PORTB.PODR.BIT.B2 - -static AZURE_IOT_MQTT azure_iot_mqtt; -static TX_EVENT_FLAGS_GROUP azure_iot_flags; - -static INT telemetry_interval = 10; - -static void set_led_state(bool level) -{ - if (level) - { - printf("LED is turned ON\r\n"); - LED0 = LED_ON; - LED1 = LED_ON; - } - else - { - printf("LED is turned OFF\r\n"); - LED0 = LED_OFF; - LED1 = LED_OFF; - } -} - -static void mqtt_direct_method(AZURE_IOT_MQTT* iot_mqtt, CHAR* direct_method_name, CHAR* message) -{ - if (strcmp(direct_method_name, "setLedState") == 0) - { - printf("Direct method=%s invoked\r\n", direct_method_name); - - // 'false' - turn LED off - // 'true' - turn LED on - bool arg = (strcmp(message, "true") == 0); - - set_led_state(arg); - - // Return success - azure_iot_mqtt_respond_direct_method(iot_mqtt, 200); - - // Update device twin property - azure_iot_mqtt_publish_bool_property(iot_mqtt, LED_STATE_PROPERTY, arg); - } - else - { - printf("Received direct method=%s is unknown\r\n", direct_method_name); - azure_iot_mqtt_respond_direct_method(iot_mqtt, 501); - } -} - -static void mqtt_c2d_message(AZURE_IOT_MQTT* iot_mqtt, CHAR* properties, CHAR* message) -{ - printf("Received C2D message, properties='%s', message='%s'\r\n", properties, message); -} - -static void mqtt_device_twin_desired_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - - // Confirm reception back to hub - azure_iot_mqtt_respond_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200); - } -} - -static void mqtt_device_twin_prop(AZURE_IOT_MQTT* iot_mqtt, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - token_count = jsmn_parse(&parser, message, strlen(message), tokens, 64); - - if (findJsonInt(message, tokens, token_count, TELEMETRY_INTERVAL_PROPERTY, &telemetry_interval)) - { - // Set a telemetry event so we pick up the change immediately - tx_event_flags_set(&azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR); - } - - // Report writeable properties to the Hub - azure_iot_mqtt_publish_int_writeable_property(iot_mqtt, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval); -} - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*time_get)(VOID)) -{ - UINT status; - ULONG events; - float temperature; - - if ((status = tx_event_flags_create(&azure_iot_flags, "Azure IoT flags"))) - { - printf("FAIL: Unable to create nx_client event flags (0x%02x)\r\n", status); - return status; - } - -#ifdef ENABLE_DPS - // Create Azure MQTT for Hub via DPS - status = azure_iot_mqtt_create_with_dps(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_DPS_ID_SCOPE, - IOT_DPS_REGISTRATION_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#else - // Create Azure MQTT for Hub - status = azure_iot_mqtt_create(&azure_iot_mqtt, - ip_ptr, - pool_ptr, - dns_ptr, - time_get, - IOT_HUB_HOSTNAME, - IOT_HUB_DEVICE_ID, - IOT_DEVICE_SAS_KEY, - IOT_MODEL_ID); -#endif - - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure IoT MQTT (0x%04x)\r\n", status); - return status; - } - - // Register callbacks - azure_iot_mqtt_register_direct_method_callback(&azure_iot_mqtt, mqtt_direct_method); - azure_iot_mqtt_register_c2d_message_callback(&azure_iot_mqtt, mqtt_c2d_message); - azure_iot_mqtt_register_device_twin_desired_prop_callback(&azure_iot_mqtt, mqtt_device_twin_desired_prop); - azure_iot_mqtt_register_device_twin_prop_callback(&azure_iot_mqtt, mqtt_device_twin_prop); - - // Connect the Azure MQTT client - status = azure_iot_mqtt_connect(&azure_iot_mqtt); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Failed to create Azure MQTT (0x%02x)\r\n", status); - return status; - } - - // Update ledState property - azure_iot_mqtt_publish_bool_property(&azure_iot_mqtt, LED_STATE_PROPERTY, false); - - // Request the device twin - azure_iot_mqtt_device_twin_request(&azure_iot_mqtt); - - printf("\r\nStarting MQTT loop\r\n"); - while (true) - { - temperature = 28.5; - - // Sleep - tx_event_flags_get( - &azure_iot_flags, TELEMETRY_INTERVAL_EVENT, TX_OR_CLEAR, &events, telemetry_interval * NX_IP_PERIODIC_RATE); - - // Send the temperature as a telemetry event - azure_iot_mqtt_publish_float_telemetry(&azure_iot_mqtt, "temperature", temperature); - } - - return NXD_MQTT_SUCCESS; -} \ No newline at end of file diff --git a/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.h b/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.h deleted file mode 100644 index d8e4570d..00000000 --- a/Renesas/RX65N_Cloud_Kit/app/legacy/mqtt.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _MQTT_H -#define _MQTT_H - -#include "tx_api.h" -#include "nx_api.h" -#include "nxd_dns.h" - -UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_ptr, ULONG (*sntp_time_get)(VOID)); - -#endif // _MQTT_H diff --git a/Renesas/RX65N_Cloud_Kit/app/main.c b/Renesas/RX65N_Cloud_Kit/app/main.c index e18705dd..e2800d7c 100644 --- a/Renesas/RX65N_Cloud_Kit/app/main.c +++ b/Renesas/RX65N_Cloud_Kit/app/main.c @@ -9,7 +9,6 @@ #include "rx_networking.h" #include "sntp_client.h" -#include "legacy/mqtt.h" #include "nx_client.h" #include "azure_config.h" @@ -26,7 +25,7 @@ static void azure_thread_entry(ULONG thread_input) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = rx_network_init(WIFI_SSID, WIFI_PASSWORD, WIFI_MODE))) @@ -34,11 +33,7 @@ static void azure_thread_entry(ULONG thread_input) printf("ERROR: Failed to initialize the network (0x%08x)\r\n", status); } -#ifdef ENABLE_LEGACY_MQTT - else if ((status = azure_iot_mqtt_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time_get))) -#else else if ((status = azure_iot_nx_client_entry(&nx_ip, &nx_pool, &nx_dns_client, sntp_time))) -#endif { printf("ERROR: Failed to run Azure IoT (0x%08x)\r\n", status); } @@ -46,7 +41,7 @@ static void azure_thread_entry(ULONG thread_input) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/Renesas/RX65N_Cloud_Kit/lib/CMakeLists.txt b/Renesas/RX65N_Cloud_Kit/lib/CMakeLists.txt index f85b9126..ea5cdaa3 100644 --- a/Renesas/RX65N_Cloud_Kit/lib/CMakeLists.txt +++ b/Renesas/RX65N_Cloud_Kit/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(netx_driver) add_subdirectory(rx_driver_package) diff --git a/STMicroelectronics/B-L475E-IOT01A/app/CMakeLists.txt b/STMicroelectronics/B-L475E-IOT01A/app/CMakeLists.txt index c3221a16..ffa5601a 100644 --- a/STMicroelectronics/B-L475E-IOT01A/app/CMakeLists.txt +++ b/STMicroelectronics/B-L475E-IOT01A/app/CMakeLists.txt @@ -24,7 +24,6 @@ target_link_libraries(${PROJECT_NAME} stm32cubel4 netx_driver app_common - jsmn ) target_include_directories(${PROJECT_NAME} diff --git a/STMicroelectronics/B-L475E-IOT01A/app/main.c b/STMicroelectronics/B-L475E-IOT01A/app/main.c index 1d77fc44..96fd1e23 100644 --- a/STMicroelectronics/B-L475E-IOT01A/app/main.c +++ b/STMicroelectronics/B-L475E-IOT01A/app/main.c @@ -23,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = stm_network_init(WIFI_SSID, WIFI_PASSWORD, WIFI_MODE))) @@ -39,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/STMicroelectronics/B-L475E-IOT01A/azure-pipelines.yml b/STMicroelectronics/B-L475E-IOT01A/azure-pipelines.yml deleted file mode 100644 index d7be431e..00000000 --- a/STMicroelectronics/B-L475E-IOT01A/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) - -resources: - repositories: - - repository: Device-Lab - type: git - endpoint: Devicelab - name: Device-Lab/Device-Lab - -trigger: - batch: true - branches: - include: - - master - paths: - exclude: - - doc/* - -jobs: -- job: STM_Build - pool: - name: 'DDE' - demands: - - STMBL475EIOT01A -equals true - steps: - - checkout: self - clean: true - submodules: recursive - - checkout: Device-Lab - clean: true - - # Azure CLI to start certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1' - arguments: '$(Build.SourcesDirectory)\getting-started\shared\model' - useGlobalConfig: true - displayName: "Start Certification" - - # modify config with credentials - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\update_config.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -ConfigFilePath '$(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L475E-IOT01A\app\azure_config.h' - displayName: 'Modify config file' - - # Build binary - - script: | - echo %PATH% - cd $(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L475E-IOT01A\tools - .\rebuild.bat - displayName: "Build Binary" - - # Flash binary to hardware - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\flashing_tools\flash-board.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -BinPath '$(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L475E-IOT01A\build\app\stm32l475_azure_iot.hex' - displayName: 'Flash binary' - - # Monitor device for successful connection to Iot Hub - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\scan_serial.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -TestString 'SUCCESS: Connected to IoT Hub' - displayName: 'Scan serial port' - - # Azure CLI to run certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\run_certification.ps1' - arguments: $(TESTID) - useGlobalConfig: true - displayName: "Run Certification" diff --git a/STMicroelectronics/B-L475E-IOT01A/lib/CMakeLists.txt b/STMicroelectronics/B-L475E-IOT01A/lib/CMakeLists.txt index 0370c2a7..1ee909e3 100644 --- a/STMicroelectronics/B-L475E-IOT01A/lib/CMakeLists.txt +++ b/STMicroelectronics/B-L475E-IOT01A/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Center") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(stm32cubel4) add_subdirectory(netx_driver) diff --git a/STMicroelectronics/B-L4S5I-IOT01A/app/CMakeLists.txt b/STMicroelectronics/B-L4S5I-IOT01A/app/CMakeLists.txt index 45839ebb..03ea0ae0 100644 --- a/STMicroelectronics/B-L4S5I-IOT01A/app/CMakeLists.txt +++ b/STMicroelectronics/B-L4S5I-IOT01A/app/CMakeLists.txt @@ -24,7 +24,6 @@ target_link_libraries(${PROJECT_NAME} stm32cubel4 netx_driver app_common - jsmn ) target_include_directories(${PROJECT_NAME} diff --git a/STMicroelectronics/B-L4S5I-IOT01A/app/main.c b/STMicroelectronics/B-L4S5I-IOT01A/app/main.c index 1d77fc44..96fd1e23 100644 --- a/STMicroelectronics/B-L4S5I-IOT01A/app/main.c +++ b/STMicroelectronics/B-L4S5I-IOT01A/app/main.c @@ -23,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = stm_network_init(WIFI_SSID, WIFI_PASSWORD, WIFI_MODE))) @@ -39,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/STMicroelectronics/B-L4S5I-IOT01A/azure-pipelines.yml b/STMicroelectronics/B-L4S5I-IOT01A/azure-pipelines.yml deleted file mode 100644 index 4bd7732f..00000000 --- a/STMicroelectronics/B-L4S5I-IOT01A/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) - -resources: - repositories: - - repository: Device-Lab - type: git - endpoint: Devicelab - name: Device-Lab/Device-Lab - -trigger: - batch: true - branches: - include: - - master - paths: - exclude: - - doc/* - -jobs: -- job: STM_Build - pool: - name: 'DDE' - demands: - - STMBL4S5IIOT01A -equals true - steps: - - checkout: self - clean: true - submodules: recursive - - checkout: Device-Lab - clean: true - - # Azure CLI to start certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1' - arguments: '$(Build.SourcesDirectory)\getting-started\shared\model' - useGlobalConfig: true - displayName: "Start Certification" - - # modify config with credentials - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\update_config.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -ConfigFilePath '$(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L4S5I-IOT01A\app\azure_config.h' - displayName: 'Modify config file' - - # Build binary - - script: | - echo %PATH% - cd $(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L4S5I-IOT01A\tools - .\rebuild.bat - displayName: "Build Binary" - - # Flash binary to hardware - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\flashing_tools\flash-board.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -BinPath '$(Build.SourcesDirectory)\getting-started\STMicroelectronics\B-L4S5I-IOT01A\build\app\stm32l4S5_azure_iot.hex' - displayName: 'Flash binary' - - # Monitor device for successful connection to Iot Hub - - task: PowerShell@2 - inputs: - targetType: 'filePath' - filePath: '$(Build.SourcesDirectory)\Device-Lab\scan_serial.ps1' - arguments: > # Use this to avoid newline characters in multiline string - -TestString 'SUCCESS: Connected to IoT Hub' - displayName: 'Scan serial port' - - # Azure CLI to run certification - - task: AzureCLI@2 - inputs: - azureSubscription: 'ExpressLogicDeviceLabResourceManagerSC' - scriptType: 'ps' - scriptLocation: 'scriptPath' - scriptPath: '$(Build.SourcesDirectory)\Device-Lab\run_certification.ps1' - arguments: $(TESTID) - useGlobalConfig: true - displayName: "Run Certification" diff --git a/STMicroelectronics/B-L4S5I-IOT01A/lib/CMakeLists.txt b/STMicroelectronics/B-L4S5I-IOT01A/lib/CMakeLists.txt index 0370c2a7..1ee909e3 100644 --- a/STMicroelectronics/B-L4S5I-IOT01A/lib/CMakeLists.txt +++ b/STMicroelectronics/B-L4S5I-IOT01A/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Center") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(stm32cubel4) add_subdirectory(netx_driver) diff --git a/STMicroelectronics/B-U585I-IOT02A/app/CMakeLists.txt b/STMicroelectronics/B-U585I-IOT02A/app/CMakeLists.txt index 985e3293..4088d175 100644 --- a/STMicroelectronics/B-U585I-IOT02A/app/CMakeLists.txt +++ b/STMicroelectronics/B-U585I-IOT02A/app/CMakeLists.txt @@ -22,7 +22,6 @@ target_link_libraries(${PROJECT_NAME} stm32cubeu5 app_common - jsmn ) target_include_directories(${PROJECT_NAME} diff --git a/STMicroelectronics/B-U585I-IOT02A/app/main.c b/STMicroelectronics/B-U585I-IOT02A/app/main.c index d8a67730..81c38266 100644 --- a/STMicroelectronics/B-U585I-IOT02A/app/main.c +++ b/STMicroelectronics/B-U585I-IOT02A/app/main.c @@ -23,7 +23,7 @@ static void azure_thread_entry(ULONG parameter) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Initialize the network if ((status = stm_network_init(WIFI_SSID, WIFI_PASSWORD, WIFI_MODE))) @@ -39,7 +39,7 @@ static void azure_thread_entry(ULONG parameter) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/STMicroelectronics/B-U585I-IOT02A/lib/CMakeLists.txt b/STMicroelectronics/B-U585I-IOT02A/lib/CMakeLists.txt index 75f4b29e..729857e0 100644 --- a/STMicroelectronics/B-U585I-IOT02A/lib/CMakeLists.txt +++ b/STMicroelectronics/B-U585I-IOT02A/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE ON CACHE BOOL "Disable Security Center" # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) add_subdirectory(stm32cubeu5) diff --git a/SiliconLabs/EFR32MG12/app/CMakeLists.txt b/SiliconLabs/EFR32MG12/app/CMakeLists.txt index aeff47dd..de0dcea3 100644 --- a/SiliconLabs/EFR32MG12/app/CMakeLists.txt +++ b/SiliconLabs/EFR32MG12/app/CMakeLists.txt @@ -24,7 +24,6 @@ target_link_libraries(${PROJECT_NAME} azrtos::netxduo app_common - jsmn gecko_sdk_3.0.0_efr32mg12 netx_driver ) diff --git a/SiliconLabs/EFR32MG12/app/main.c b/SiliconLabs/EFR32MG12/app/main.c index c6e9131e..06d1c7ca 100644 --- a/SiliconLabs/EFR32MG12/app/main.c +++ b/SiliconLabs/EFR32MG12/app/main.c @@ -52,7 +52,7 @@ void azure_thread_entry(ULONG thread_input) { UINT status; - printf("Starting Azure thread\r\n\r\n"); + printf("Starting thread\r\n\r\n"); // Set wifi network information if ((status = wifi_init())) @@ -74,7 +74,7 @@ void azure_thread_entry(ULONG thread_input) void tx_application_define(void* first_unused_memory) { - // Create Azure thread + // Create thread UINT status = tx_thread_create(&azure_thread, "Azure Thread", azure_thread_entry, diff --git a/SiliconLabs/EFR32MG12/lib/CMakeLists.txt b/SiliconLabs/EFR32MG12/lib/CMakeLists.txt index e317ca5a..c03d8345 100644 --- a/SiliconLabs/EFR32MG12/lib/CMakeLists.txt +++ b/SiliconLabs/EFR32MG12/lib/CMakeLists.txt @@ -15,7 +15,6 @@ set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE ON CACHE BOOL "Disable ASC") # Core libraries add_subdirectory(${SHARED_LIB_DIR}/threadx threadx) add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo) -add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn) # Gecko SDK & WFX200 network driver add_subdirectory(gecko_sdk_3.0.0_efr32mg12) diff --git a/SiliconLabs/EFR32MG12/readme.md b/SiliconLabs/EFR32MG12/readme.md index f0c8ade6..2116072b 100644 --- a/SiliconLabs/EFR32MG12/readme.md +++ b/SiliconLabs/EFR32MG12/readme.md @@ -194,7 +194,7 @@ You can use the **Termite** utility to monitor communication and confirm that yo 1. In the **Termite** console, check the following checkpoint values to confirm that the device is initialized and connected to Azure IoT. ```output - Starting Azure thread + Starting thread WF200 Firmware version 3.7.0 WF200 initialization successful Connecting to SSID: *** diff --git a/shared/lib/netxduo b/shared/lib/netxduo index 2973652d..18704ffa 160000 --- a/shared/lib/netxduo +++ b/shared/lib/netxduo @@ -1 +1 @@ -Subproject commit 2973652d801e92615caa285ad9ee13db19a26cb9 +Subproject commit 18704ffa7383071ce1b335730fbde131f27be045 diff --git a/shared/lib/threadx b/shared/lib/threadx index 37f6d0b3..07eac307 160000 --- a/shared/lib/threadx +++ b/shared/lib/threadx @@ -1 +1 @@ -Subproject commit 37f6d0b39c970b297c263cbb8388b9060b92e5c9 +Subproject commit 07eac307405dbf09d409844e31c37b0649d6c074 diff --git a/shared/src/CMakeLists.txt b/shared/src/CMakeLists.txt index 20903ccf..474a593c 100644 --- a/shared/src/CMakeLists.txt +++ b/shared/src/CMakeLists.txt @@ -4,13 +4,6 @@ set(TARGET app_common) set(SOURCES - azure_iot_mqtt/azure_iot_mqtt.c - azure_iot_mqtt/azure_iot_dps_mqtt.c - azure_iot_mqtt/hmac_sha256.c - azure_iot_mqtt/sas_token.c - azure_iot_mqtt/sha256.c - azure_iot_mqtt/json_utils.c - azure_iot_nx_client.c azure_iot_connect.c azure_iot_cert.c @@ -45,5 +38,4 @@ target_include_directories(${TARGET} target_link_libraries(${TARGET} azrtos::threadx azrtos::netxduo - jsmn ) \ No newline at end of file diff --git a/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.c b/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.c deleted file mode 100644 index c4266cf0..00000000 --- a/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.c +++ /dev/null @@ -1,342 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -// https://docs.microsoft.com/azure/iot-dps/iot-dps-mqtt-support - -#include - -#include "azure_iot_cert.h" -#include "azure_iot_dps_mqtt.h" - -#include "azure_iot_mqtt/sas_token.h" - -#include "json_utils.h" - -#define AZURE_IOT_DPS_ENDPOINT "global.azure-devices-provisioning.net" - -#define USERNAME "%s/registrations/%s/api-version=2019-03-31" -#define DPS_REGISTER_BASE "$dps/registrations/res" -#define DPS_REGISTER_SUBSCRIBE "$dps/registrations/res/#" -#define DPS_REGISTER_TOPIC "$dps/registrations/PUT/iotdps-register/?$rid=1" -#define DPS_STATUS_TOPIC "$dps/registrations/GET/iotdps-get-operationstatus/?$rid=1&operationId=" - -#define MQTT_PRIORITY 2 -#define MQTT_TIMEOUT (10 * TX_TIMER_TICKS_PER_SECOND) -#define MQTT_KEEP_ALIVE 240 - -#define EVENT_FLAGS_SUCCESS 1 - -extern CHAR* azure_iot_x509_hostname; - -static VOID process_retry(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - UINT status; - - jsmn_parser parser; - jsmntok_t tokens[12]; - INT token_count; - - INT retry_interval; - CHAR mqtt_publish_topic[256]; - - CHAR* find = strstr(topic, "retry-after="); - if (find == 0) - { - printf("Error: Unknown retry-after\r\n"); - return; - } - - // extract retry interval - retry_interval = atoi(find + 12); - - jsmn_init(&parser); - - token_count = jsmn_parse(&parser, - azure_iot_mqtt->mqtt_receive_message_buffer, - strlen(azure_iot_mqtt->mqtt_receive_message_buffer), - tokens, - 12); - - strncpy(mqtt_publish_topic, DPS_STATUS_TOPIC, sizeof(mqtt_publish_topic)); - if (!findJsonString(azure_iot_mqtt->mqtt_receive_message_buffer, - tokens, - token_count, - "operationId", - mqtt_publish_topic + sizeof(DPS_STATUS_TOPIC) - 1)) - { - printf("ERROR: Failed to parse DPS operationId\r\n"); - } - - tx_thread_sleep(retry_interval * TX_TIMER_TICKS_PER_SECOND); - - status = mqtt_publish(azure_iot_mqtt, mqtt_publish_topic, "{}"); - if (status != NX_SUCCESS) - { - printf("ERROR: Failed to poll for DPS status (0x%04x)\r\n", status); - } -} - -static VOID process_success(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - jsmn_parser parser; - jsmntok_t tokens[64]; - INT token_count; - - jsmn_init(&parser); - - token_count = jsmn_parse(&parser, - azure_iot_mqtt->mqtt_receive_message_buffer, - strlen(azure_iot_mqtt->mqtt_receive_message_buffer), - tokens, - 64); - - if (!findJsonString(azure_iot_mqtt->mqtt_receive_message_buffer, - tokens, - token_count, - "assignedHub", - azure_iot_mqtt->mqtt_hub_hostname)) - { - printf("ERROR: DPS failed to parse hub hostname\r\n"); - } - - if (!findJsonString(azure_iot_mqtt->mqtt_receive_message_buffer, - tokens, - token_count, - "deviceId", - azure_iot_mqtt->mqtt_device_id)) - { - printf("ERROR: DPS failed to parse device id\r\n"); - } -} - -static VOID mqtt_notify_cb(NXD_MQTT_CLIENT* client_ptr, UINT number_of_messages) -{ - UINT actual_topic_length; - UINT actual_message_length; - UINT status; - - AZURE_IOT_MQTT* azure_iot_mqtt = (AZURE_IOT_MQTT*)client_ptr->nxd_mqtt_packet_receive_context; - - for (UINT count = 0; count < number_of_messages; ++count) - { - // Get the mqtt client message - status = nxd_mqtt_client_message_get(client_ptr, - (UCHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, - AZURE_IOT_MQTT_TOPIC_NAME_LENGTH, - &actual_topic_length, - (UCHAR*)azure_iot_mqtt->mqtt_receive_message_buffer, - AZURE_IOT_MQTT_MESSAGE_LENGTH, - &actual_message_length); - if (status != NXD_MQTT_SUCCESS) - { - printf("ERROR: nxd_mqtt_client_message_get failed (0x%02x)\r\n", status); - continue; - } - - // Append null string terminators - azure_iot_mqtt->mqtt_receive_topic_buffer[actual_topic_length] = 0; - azure_iot_mqtt->mqtt_receive_message_buffer[actual_message_length] = 0; - - if (strstr((CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, DPS_REGISTER_BASE) == 0) - { - printf("ERROR: Unknown incoming DPS topic %s\r\n", (CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer); - continue; - } - - // Parse the response status - CHAR* location = azure_iot_mqtt->mqtt_receive_topic_buffer + sizeof(DPS_REGISTER_BASE); - INT msg_status = atoi(location); - - switch (msg_status) - { - case 202: - process_retry(azure_iot_mqtt, - azure_iot_mqtt->mqtt_receive_topic_buffer, - azure_iot_mqtt->mqtt_receive_message_buffer); - break; - - case 200: - process_success(azure_iot_mqtt, - azure_iot_mqtt->mqtt_receive_topic_buffer, - azure_iot_mqtt->mqtt_receive_message_buffer); - tx_event_flags_set(&azure_iot_mqtt->mqtt_event_flags, EVENT_FLAGS_SUCCESS, TX_OR); - break; - - default: - printf("ERROR: Unknown incoming DPS topic status %d\r\n", msg_status); - break; - } - } - - return; -} - -UINT azure_iot_dps_create(AZURE_IOT_MQTT* azure_iot_mqtt, NX_IP* nx_ip, NX_PACKET_POOL* nx_pool) -{ - UINT status; - - status = tx_event_flags_create(&azure_iot_mqtt->mqtt_event_flags, "DPS event flags"); - if (status != TX_SUCCESS) - { - printf("FAIL: Unable to create DPS event flags (0x%02x)\r\n", status); - return false; - } - - status = nxd_mqtt_client_create(&azure_iot_mqtt->nxd_mqtt_client, - "MQTT DPS client", - azure_iot_mqtt->mqtt_dps_registration_id, - strlen(azure_iot_mqtt->mqtt_dps_registration_id), - nx_ip, - nx_pool, - azure_iot_mqtt->mqtt_client_stack, - AZURE_IOT_MQTT_CLIENT_STACK_SIZE, - MQTT_PRIORITY, - NX_NULL, - 0); - if (status) - { - printf("Failed to create MQTT Client (0x%02x)\r\n", status); - tx_event_flags_delete(&azure_iot_mqtt->mqtt_event_flags); - return status; - } - - status = nxd_mqtt_client_receive_notify_set(&azure_iot_mqtt->nxd_mqtt_client, mqtt_notify_cb); - if (status) - { - printf("Error in setting receive notify (0x%02x)\r\n", status); - tx_event_flags_delete(&azure_iot_mqtt->mqtt_event_flags); - nxd_mqtt_client_delete(&azure_iot_mqtt->nxd_mqtt_client); - return status; - } - - // Set the receive context (highjacking the packet_receive_context) for callbacks - azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_packet_receive_context = azure_iot_mqtt; - - return NX_SUCCESS; -} - -UINT azure_iot_dps_delete(AZURE_IOT_MQTT* azure_iot_mqtt) -{ - if (azure_iot_mqtt == NX_NULL) - { - printf("Fail to delete DPS, null pointer\r\n"); - return NX_PTR_ERROR; - } - - tx_event_flags_delete(&azure_iot_mqtt->mqtt_event_flags); - nxd_mqtt_client_disconnect(&azure_iot_mqtt->nxd_mqtt_client); - nxd_mqtt_client_delete(&azure_iot_mqtt->nxd_mqtt_client); - - return NX_SUCCESS; -} - -UINT azure_iot_dps_register(AZURE_IOT_MQTT* azure_iot_mqtt, UINT wait) -{ - UINT status; - NXD_ADDRESS server_ip; - CHAR mqtt_publish_payload[100]; - - printf("\tEndpoint: %s\r\n", AZURE_IOT_DPS_ENDPOINT); - printf("\tId scope: %s\r\n", azure_iot_mqtt->mqtt_dps_id_scope); - printf("\tRegistration id: %s\r\n", azure_iot_mqtt->mqtt_dps_registration_id); - - // Create the nxd_mqtt_client_secure_connect & password - snprintf(azure_iot_mqtt->mqtt_username, - AZURE_IOT_MQTT_USERNAME_SIZE, - USERNAME, - azure_iot_mqtt->mqtt_dps_id_scope, - azure_iot_mqtt->mqtt_dps_registration_id); - - if (!create_dps_sas_token(azure_iot_mqtt->mqtt_sas_key, - strlen(azure_iot_mqtt->mqtt_sas_key), - azure_iot_mqtt->mqtt_dps_id_scope, - azure_iot_mqtt->mqtt_dps_registration_id, - azure_iot_mqtt->unix_time_get(), - azure_iot_mqtt->mqtt_password, - AZURE_IOT_MQTT_PASSWORD_SIZE)) - { - printf("ERROR: Unable to generate DPS SAS token\r\n"); - return NX_PTR_ERROR; - } - - status = nxd_mqtt_client_login_set(&azure_iot_mqtt->nxd_mqtt_client, - azure_iot_mqtt->mqtt_username, - strlen(azure_iot_mqtt->mqtt_username), - azure_iot_mqtt->mqtt_password, - strlen(azure_iot_mqtt->mqtt_password)); - if (status != NXD_MQTT_SUCCESS) - { - printf("Could not set client login (0x%04x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Resolve the MQTT server IP address - status = nxd_dns_host_by_name_get(azure_iot_mqtt->nx_dns, - (UCHAR*)AZURE_IOT_DPS_ENDPOINT, - &server_ip, - 5 * NX_IP_PERIODIC_RATE, - NX_IP_VERSION_V4); - if (status != NX_SUCCESS) - { - printf("Error: Unable to resolve DNS for DPS MQTT Server %s (0x%04x)\r\n", - AZURE_IOT_DPS_ENDPOINT, - status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Stash the hostname so we can verify the cert at connect - azure_iot_x509_hostname = AZURE_IOT_DPS_ENDPOINT; - - status = nxd_mqtt_client_secure_connect(&azure_iot_mqtt->nxd_mqtt_client, - &server_ip, - NXD_MQTT_TLS_PORT, - tls_setup, - MQTT_KEEP_ALIVE, - NX_TRUE, - MQTT_TIMEOUT); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Could not connect to DPS MQTT server (0x%04x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Subscribe to the registration status topic - status = nxd_mqtt_client_subscribe( - &azure_iot_mqtt->nxd_mqtt_client, DPS_REGISTER_SUBSCRIBE, strlen(DPS_REGISTER_SUBSCRIBE), MQTT_QOS_0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error: Error in DPS registration subscription (0x%04x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Create the payload - snprintf(mqtt_publish_payload, - sizeof(mqtt_publish_payload), - "{\"registrationId\":\"%s\",\"payload\":{\"modelId\":\"%s\"}}", - azure_iot_mqtt->mqtt_dps_registration_id, - azure_iot_mqtt->mqtt_model_id); - - // Register the device - status = mqtt_publish(azure_iot_mqtt, DPS_REGISTER_TOPIC, mqtt_publish_payload); - if (status != NX_SUCCESS) - { - printf("ERROR: Failed to publish DPS registration (0x%04x)\r\n", status); - } - - // Wait for an event - ULONG events = 0; - tx_event_flags_get( - &azure_iot_mqtt->mqtt_event_flags, EVENT_FLAGS_SUCCESS, TX_OR_CLEAR, &events, 30 * NX_IP_PERIODIC_RATE); - - if (events != EVENT_FLAGS_SUCCESS) - { - printf("ERROR: Failed to resolve device from DPS\r\n"); - return NX_NOT_SUCCESSFUL; - } - - return NXD_MQTT_SUCCESS; -} diff --git a/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.h b/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.h deleted file mode 100644 index c3a25a1d..00000000 --- a/shared/src/azure_iot_mqtt/azure_iot_dps_mqtt.h +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _AZURE_IOT_DPS_MQTT_H -#define _AZURE_IOT_DPS_MQTT_H - -#include "tx_api.h" -#include "nx_api.h" - -#include "azure_iot_mqtt.h" - -UINT azure_iot_dps_create(AZURE_IOT_MQTT* azure_iot_mqtt, NX_IP* nx_ip, NX_PACKET_POOL* nx_pool); -UINT azure_iot_dps_delete(AZURE_IOT_MQTT* azure_iot_mqtt); -UINT azure_iot_dps_register(AZURE_IOT_MQTT* azure_iot_mqtt, UINT wait); - -#endif \ No newline at end of file diff --git a/shared/src/azure_iot_mqtt/azure_iot_mqtt.c b/shared/src/azure_iot_mqtt/azure_iot_mqtt.c deleted file mode 100644 index 63848f17..00000000 --- a/shared/src/azure_iot_mqtt/azure_iot_mqtt.c +++ /dev/null @@ -1,802 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "azure_iot_mqtt.h" - -#include -#include - -#include "tx_api.h" - -#include "nx_api.h" -#include "nxd_mqtt_client.h" - -#include "azure_iot_cert.h" -#include "azure_iot_mqtt/azure_iot_dps_mqtt.h" -#include "azure_iot_mqtt/sas_token.h" - -#define USERNAME "%s/%s/?api-version=2020-09-30&model-id=%s" -#define PUBLISH_TELEMETRY_TOPIC "devices/%s/messages/events/" - -#define DEVICE_MESSAGE_BASE "messages/devicebound/" -#define DEVICE_MESSAGE_TOPIC "devices/%s/messages/devicebound/#" - -#define DEVICE_TWIN_PUBLISH_TOPIC "$iothub/twin/PATCH/properties/reported/?$rid=%d" -#define DEVICE_TWIN_REQUEST_TOPIC "$iothub/twin/GET/?$rid=%d" -#define DEVICE_TWIN_RES_BASE "$iothub/twin/res/" -#define DEVICE_TWIN_RES_TOPIC "$iothub/twin/res/#" -#define DEVICE_TWIN_DESIRED_PROP_RES_BASE "$iothub/twin/PATCH/properties/desired/" -#define DEVICE_TWIN_DESIRED_PROP_RES_TOPIC "$iothub/twin/PATCH/properties/desired/#" - -#define DIRECT_METHOD_RECEIVE "$iothub/methods/POST/" -#define DIRECT_METHOD_TOPIC "$iothub/methods/POST/#" -#define DIRECT_METHOD_RESPONSE "$iothub/methods/res/%d/?$rid=%s" - -#define MQTT_CLIENT_PRIORITY 2 -#define MQTT_TIMEOUT (10 * TX_TIMER_TICKS_PER_SECOND) -#define MQTT_KEEP_ALIVE 240 - -CHAR* azure_iot_x509_hostname; - -static ULONG azure_iot_certificate_verify(NX_SECURE_TLS_SESSION* session, NX_SECURE_X509_CERT* certificate) -{ - UINT status; - - // Check certicate matches the correct address - status = nx_secure_x509_common_name_dns_check( - certificate, (UCHAR*)azure_iot_x509_hostname, strlen(azure_iot_x509_hostname)); - if (status) - { - printf("Error in certificate verification: DNS name did not match CN\r\n"); - } - - return status; -} - -UINT azure_iot_mqtt_register_direct_method_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_direct_method mqtt_direct_method_callback) -{ - if (azure_iot_mqtt == NULL || azure_iot_mqtt->cb_ptr_mqtt_invoke_direct_method != NULL) - { - return NX_PTR_ERROR; - } - - azure_iot_mqtt->cb_ptr_mqtt_invoke_direct_method = mqtt_direct_method_callback; - return NX_SUCCESS; -} - -UINT azure_iot_mqtt_register_c2d_message_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_c2d_message mqtt_c2d_message_callback) -{ - if (azure_iot_mqtt == NULL || azure_iot_mqtt->cb_ptr_mqtt_c2d_message != NULL) - { - return NX_PTR_ERROR; - } - - azure_iot_mqtt->cb_ptr_mqtt_c2d_message = mqtt_c2d_message_callback; - return NX_SUCCESS; -} - -UINT azure_iot_mqtt_register_device_twin_desired_prop_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_device_twin_desired_prop mqtt_device_twin_desired_prop_callback) -{ - if (azure_iot_mqtt == NULL || azure_iot_mqtt->cb_ptr_mqtt_device_twin_desired_prop_callback != NULL) - { - return NX_PTR_ERROR; - } - - azure_iot_mqtt->cb_ptr_mqtt_device_twin_desired_prop_callback = mqtt_device_twin_desired_prop_callback; - return NX_SUCCESS; -} - -UINT azure_iot_mqtt_register_device_twin_prop_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_device_twin_prop mqtt_device_twin_prop_callback) -{ - if (azure_iot_mqtt == NULL || azure_iot_mqtt->cb_ptr_mqtt_device_twin_prop_callback != NULL) - { - return NX_PTR_ERROR; - } - - azure_iot_mqtt->cb_ptr_mqtt_device_twin_prop_callback = mqtt_device_twin_prop_callback; - return NX_SUCCESS; -} - -UINT tls_setup(NXD_MQTT_CLIENT* client, - NX_SECURE_TLS_SESSION* tls_session, - NX_SECURE_X509_CERT* cert, - NX_SECURE_X509_CERT* trusted_cert) -{ - UINT status; - - AZURE_IOT_MQTT* azure_iot_mqtt = (AZURE_IOT_MQTT*)client->nxd_mqtt_packet_receive_context; - - // Create TLS session. - status = _nx_secure_tls_session_create_ext(tls_session, - _nx_azure_iot_tls_supported_crypto, - _nx_azure_iot_tls_supported_crypto_size, - _nx_azure_iot_tls_ciphersuite_map, - _nx_azure_iot_tls_ciphersuite_map_size, - azure_iot_mqtt->tls_metadata_buffer, - sizeof(azure_iot_mqtt->tls_metadata_buffer)); - if (status != NX_SUCCESS) - { - printf("Failed to create TLS session status (0x%04x)\r\n", status); - return status; - } - - status = nx_secure_tls_remote_certificate_allocate(tls_session, - &azure_iot_mqtt->mqtt_remote_certificate, - azure_iot_mqtt->mqtt_remote_cert_buffer, - sizeof(azure_iot_mqtt->mqtt_remote_cert_buffer)); - if (status != NX_SUCCESS) - { - printf("Failed to create remote certificate buffer (0x%04x)\r\n", status); - return status; - } - - // Add a CA Certificate to our trusted store for verifying incoming server certificates - status = nx_secure_x509_certificate_initialize(trusted_cert, - (UCHAR*)azure_iot_root_cert, - azure_iot_root_cert_size, - NX_NULL, - 0, - NX_NULL, - 0, - NX_SECURE_X509_KEY_TYPE_NONE); - if (status != NX_SUCCESS) - { - printf("Unable to initialize CA certificate (0x%04x)\r\n", status); - return status; - } - - status = nx_secure_tls_trusted_certificate_add(tls_session, trusted_cert); - if (status != NX_SUCCESS) - { - printf("Unable to add CA certificate to trusted store (0x%04x)\r\n", status); - return status; - } - - status = nx_secure_tls_session_packet_buffer_set( - tls_session, azure_iot_mqtt->tls_packet_buffer, sizeof(azure_iot_mqtt->tls_packet_buffer)); - if (status != NX_SUCCESS) - { - printf("Could not set TLS session packet buffer (0x%02x)\r\n", status); - return status; - } - - // Setup the callback invoked when TLS has a certificate it wants to verify so we can - // do additional checks not done automatically by TLS. - status = nx_secure_tls_session_certificate_callback_set(tls_session, azure_iot_certificate_verify); - if (status) - { - printf("Failed to set the session certificate callback: status: %d", status); - return status; - } - - // Add a timestamp function for time checking and timestamps in the TLS handshake - nx_secure_tls_session_time_function_set(tls_session, azure_iot_mqtt->unix_time_get); - - return NX_SUCCESS; -} - -UINT mqtt_publish(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - UINT status = nxd_mqtt_client_publish(&azure_iot_mqtt->nxd_mqtt_client, - topic, - strlen(topic), - message, - strlen(message), - NX_FALSE, - MQTT_QOS_1, - NX_WAIT_FOREVER); - if (status != NX_SUCCESS) - { - printf("Failed to publish %s (0x%02x)\r\n", message, status); - } - - return status; -} - -static UINT mqtt_publish_float(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* label, float value) -{ - CHAR mqtt_message[100]; - - int decvalue = value; - int fracvalue = abs(100 * (value - (long)value)); - - snprintf(mqtt_message, sizeof(mqtt_message), "{\"%s\":%d.%02d}", label, decvalue, fracvalue); - printf("Sending message %s\r\n", mqtt_message); - - return mqtt_publish(azure_iot_mqtt, topic, mqtt_message); -} - -static UINT mqtt_publish_bool(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* label, bool value) -{ - CHAR mqtt_message[200]; - - snprintf(mqtt_message, sizeof(mqtt_message), "{\"%s\":%s}", label, (value ? "true" : "false")); - printf("Sending message %s\r\n", mqtt_message); - - return mqtt_publish(azure_iot_mqtt, topic, mqtt_message); -} - -static VOID process_direct_method(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - INT direct_method_receive_size = sizeof(DIRECT_METHOD_RECEIVE) - 1; - CHAR direct_method_name[64] = {0}; - - CHAR* location = topic + direct_method_receive_size; - CHAR* find; - - find = strchr(location, '/'); - if (find == 0) - { - return; - } - - strncpy(direct_method_name, location, find - location); - - location = find; - - find = strstr(location, "$rid="); - if (find == 0) - { - printf("Error: failed to parse direct method rid\r\n"); - return; - } - - location = find + 5; - strncpy(azure_iot_mqtt->direct_command_request_id, location, AZURE_IOT_MQTT_DIRECT_COMMAND_RID_SIZE); - - printf("Received direct method=%s, rid=%s, message=%s\r\n", - direct_method_name, - azure_iot_mqtt->direct_command_request_id, - message); - - if (azure_iot_mqtt->cb_ptr_mqtt_invoke_direct_method == NULL) - { - printf("No callback is registered for MQTT direct method invoke\r\n"); - return; - } - - azure_iot_mqtt->cb_ptr_mqtt_invoke_direct_method(azure_iot_mqtt, direct_method_name, message); -} - -static VOID process_c2d_message(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - CHAR* properties; - - // Get to parameters list - if ((properties = strstr(topic, ".to")) == 0) - { - printf("Received C2D message has no parameter list\r\n"); - return; - } - - // Find the properties - if ((properties = strstr(properties, "&")) == 0) - { - // No properties, point at the null terminator - properties = topic + strlen(topic); - } - else - { - // Skip over the '&' - properties++; - } - - if (azure_iot_mqtt->cb_ptr_mqtt_c2d_message == NULL) - { - printf("No callback is registered for MQTT cloud to device message processing\r\n"); - return; - } - - azure_iot_mqtt->cb_ptr_mqtt_c2d_message(azure_iot_mqtt, properties, message); -} - -static VOID process_device_twin_response(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - INT response_status; - - // Parse the device twin response status - CHAR* location = topic + sizeof(DEVICE_TWIN_RES_BASE) - 1; - CHAR* find; - - find = strchr(location, '/'); - if (find == 0) - { - return; - } - - response_status = atoi(location); - - printf("Processed device twin update response with status=%d\r\n", response_status); - - if (response_status == 200) - { - azure_iot_mqtt->cb_ptr_mqtt_device_twin_prop_callback(azure_iot_mqtt, message); - } -} - -static VOID process_device_twin_desired_prop_update(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message) -{ - printf("Received device twin desired property\r\n"); - - // Parse the device twin version - CHAR* location = topic + sizeof(DEVICE_TWIN_DESIRED_PROP_RES_BASE) - 1; - - location = strstr(location, "$version="); - if (location == 0) - { - printf("Error: Failed to parse version from desired property update\r\n"); - return; - } - - azure_iot_mqtt->desired_property_version = atoi(location + 9); - - azure_iot_mqtt->cb_ptr_mqtt_device_twin_desired_prop_callback(azure_iot_mqtt, message); -} - -static VOID mqtt_disconnect_cb(NXD_MQTT_CLIENT* client_ptr) -{ - printf("ERROR: MQTT disconnected, reconnecting...\r\n"); - - AZURE_IOT_MQTT* azure_iot_mqtt = (AZURE_IOT_MQTT*)client_ptr; - - // Try and reconnect forever - while (azure_iot_mqtt_connect(azure_iot_mqtt) != NX_SUCCESS) - { - tx_thread_sleep(10 * TX_TIMER_TICKS_PER_SECOND); - } -} - -static VOID mqtt_notify_cb(NXD_MQTT_CLIENT* client_ptr, UINT number_of_messages) -{ - UINT actual_topic_length; - UINT actual_message_length; - UINT status; - - AZURE_IOT_MQTT* azure_iot_mqtt = (AZURE_IOT_MQTT*)client_ptr->nxd_mqtt_packet_receive_context; - - for (UINT count = 0; count < number_of_messages; ++count) - { - // Get the mqtt client message - status = nxd_mqtt_client_message_get(client_ptr, - (UCHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, - AZURE_IOT_MQTT_TOPIC_NAME_LENGTH, - &actual_topic_length, - (UCHAR*)azure_iot_mqtt->mqtt_receive_message_buffer, - AZURE_IOT_MQTT_MESSAGE_LENGTH, - &actual_message_length); - if (status != NXD_MQTT_SUCCESS) - { - printf("ERROR: nxd_mqtt_client_message_get failed (0x%02x)\r\n", status); - continue; - } - - // Append null string terminators - azure_iot_mqtt->mqtt_receive_topic_buffer[actual_topic_length] = 0; - azure_iot_mqtt->mqtt_receive_message_buffer[actual_message_length] = 0; - - if (strstr((CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, DIRECT_METHOD_RECEIVE)) - { - process_direct_method( - azure_iot_mqtt, azure_iot_mqtt->mqtt_receive_topic_buffer, azure_iot_mqtt->mqtt_receive_message_buffer); - } - else if (strstr((CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, DEVICE_MESSAGE_BASE)) - { - process_c2d_message( - azure_iot_mqtt, azure_iot_mqtt->mqtt_receive_topic_buffer, azure_iot_mqtt->mqtt_receive_message_buffer); - } - else if (strstr((CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, DEVICE_TWIN_RES_BASE)) - { - process_device_twin_response( - azure_iot_mqtt, azure_iot_mqtt->mqtt_receive_topic_buffer, azure_iot_mqtt->mqtt_receive_message_buffer); - } - else if (strstr((CHAR*)azure_iot_mqtt->mqtt_receive_topic_buffer, DEVICE_TWIN_DESIRED_PROP_RES_BASE)) - { - process_device_twin_desired_prop_update( - azure_iot_mqtt, azure_iot_mqtt->mqtt_receive_topic_buffer, azure_iot_mqtt->mqtt_receive_message_buffer); - } - else - { - printf("Unknown topic received, no custom processing specified\r\n"); - } - } -} - -static UINT azure_iot_mqtt_create_common(AZURE_IOT_MQTT* azure_iot_mqtt, NX_IP* nx_ip, NX_PACKET_POOL* nx_pool) -{ - UINT status; - - printf("\r\nInitializing MQTT Hub client\r\n"); - - status = nxd_mqtt_client_create(&azure_iot_mqtt->nxd_mqtt_client, - "MQTT client", - azure_iot_mqtt->mqtt_device_id, - strlen(azure_iot_mqtt->mqtt_device_id), - nx_ip, - nx_pool, - azure_iot_mqtt->mqtt_client_stack, - AZURE_IOT_MQTT_CLIENT_STACK_SIZE, - MQTT_CLIENT_PRIORITY, - NX_NULL, - 0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Failed to create MQTT Client (0x%02x)\r\n", status); - return status; - } - - status = nxd_mqtt_client_receive_notify_set(&azure_iot_mqtt->nxd_mqtt_client, mqtt_notify_cb); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in setting receive notify (0x%02x)\r\n", status); - nxd_mqtt_client_delete(&azure_iot_mqtt->nxd_mqtt_client); - return status; - } - - status = nxd_mqtt_client_disconnect_notify_set(&azure_iot_mqtt->nxd_mqtt_client, mqtt_disconnect_cb); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in seting disconnect notification (0x%02x)\r\n", status); - nxd_mqtt_client_delete(&azure_iot_mqtt->nxd_mqtt_client); - return status; - } - - // Set the receive context (highjacking the packet_receive_context) for callbacks - azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_packet_receive_context = azure_iot_mqtt; - - return NXD_MQTT_SUCCESS; -} - -// Interact with Azure MQTT -UINT azure_iot_mqtt_publish_float_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, float value) -{ - CHAR mqtt_publish_topic[100]; - UINT status; - - printf("Sending device twin update with float value\r\n"); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - DEVICE_TWIN_PUBLISH_TOPIC, - azure_iot_mqtt->reported_property_version++); - - status = mqtt_publish_float(azure_iot_mqtt, mqtt_publish_topic, label, value); - - return status; -} - -UINT azure_iot_mqtt_publish_bool_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, bool value) -{ - CHAR mqtt_publish_topic[100]; - - printf("Sending device twin update with bool value\r\n"); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - DEVICE_TWIN_PUBLISH_TOPIC, - azure_iot_mqtt->reported_property_version++); - - return mqtt_publish_bool(azure_iot_mqtt, mqtt_publish_topic, label, value); -} - -UINT azure_iot_mqtt_publish_float_telemetry(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, float value) -{ - CHAR mqtt_publish_topic[100]; - - printf("Sending telemetry with float value\r\n"); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - PUBLISH_TELEMETRY_TOPIC, - azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_client_id); - - return mqtt_publish_float(azure_iot_mqtt, mqtt_publish_topic, label, value); -} - -UINT azure_iot_mqtt_publish_int_writeable_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, int value) -{ - CHAR mqtt_publish_topic[100]; - CHAR mqtt_publish_message[100]; - - printf("Reporting writeable property %s as %d\r\n", label, value); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - DEVICE_TWIN_PUBLISH_TOPIC, - azure_iot_mqtt->reported_property_version++); - - snprintf(mqtt_publish_message, - sizeof(mqtt_publish_message), - "{\"%s\":{\"value\":%d,\"ac\":200,\"av\":1}}", - label, - value); - - return mqtt_publish(azure_iot_mqtt, mqtt_publish_topic, mqtt_publish_message); -} - -UINT azure_iot_mqtt_respond_int_writeable_property( - AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, int value, int http_status) -{ - CHAR mqtt_publish_topic[100]; - CHAR mqtt_publish_message[100]; - - printf("Responding to writeable property %s = %d\r\n", label, value); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - DEVICE_TWIN_PUBLISH_TOPIC, - azure_iot_mqtt->reported_property_version++); - - snprintf(mqtt_publish_message, - sizeof(mqtt_publish_message), - "{\"%s\":{\"value\":%d,\"ac\":%d,\"av\":%d}}", - label, - value, - http_status, - azure_iot_mqtt->desired_property_version); - - return mqtt_publish(azure_iot_mqtt, mqtt_publish_topic, mqtt_publish_message); -} - -UINT azure_iot_mqtt_respond_direct_method(AZURE_IOT_MQTT* azure_iot_mqtt, UINT response) -{ - CHAR mqtt_publish_topic[100]; - - printf("Responding to direct command property with status:%d, rid:%s\r\n", - response, - azure_iot_mqtt->direct_command_request_id); - - snprintf(mqtt_publish_topic, - sizeof(mqtt_publish_topic), - DIRECT_METHOD_RESPONSE, - response, - azure_iot_mqtt->direct_command_request_id); - - return mqtt_publish(azure_iot_mqtt, mqtt_publish_topic, "{}"); -} - -UINT azure_iot_mqtt_device_twin_request(AZURE_IOT_MQTT* azure_iot_mqtt) -{ - CHAR mqtt_publish_topic[100]; - - printf("Requesting device twin model\r\n"); - - snprintf(mqtt_publish_topic, sizeof(mqtt_publish_topic), DEVICE_TWIN_REQUEST_TOPIC, 0); - - // Publish an empty message to request the device twin - return mqtt_publish(azure_iot_mqtt, mqtt_publish_topic, "{}"); -} - -UINT azure_iot_mqtt_create(AZURE_IOT_MQTT* azure_iot_mqtt, - NX_IP* nx_ip, - NX_PACKET_POOL* nx_pool, - NX_DNS* nx_dns, - func_ptr_unix_time_get unix_time_get, - CHAR* iot_hub_hostname, - CHAR* iot_device_id, - CHAR* iot_sas_key, - CHAR* iot_model_id) -{ - if (azure_iot_mqtt == NULL) - { - printf("ERROR: azure_iot_mqtt is NULL\r\n"); - return NX_PTR_ERROR; - } - - if (iot_hub_hostname[0] == 0 || iot_device_id[0] == 0 || iot_sas_key[0] == 0) - { - printf("ERROR: IoT Hub connection configuration is empty\r\n"); - return NX_PTR_ERROR; - } - - memset(azure_iot_mqtt, 0, sizeof(*azure_iot_mqtt)); - - // Stash the connection information - azure_iot_mqtt->nx_dns = nx_dns; - azure_iot_mqtt->unix_time_get = unix_time_get; - strncpy(azure_iot_mqtt->mqtt_hub_hostname, iot_hub_hostname, AZURE_IOT_MQTT_HOSTNAME_SIZE); - strncpy(azure_iot_mqtt->mqtt_device_id, iot_device_id, AZURE_IOT_MQTT_DEVICE_ID_SIZE); - azure_iot_mqtt->mqtt_sas_key = iot_sas_key; - azure_iot_mqtt->mqtt_model_id = iot_model_id; - - // call into common code - return azure_iot_mqtt_create_common(azure_iot_mqtt, nx_ip, nx_pool); -} - -UINT azure_iot_mqtt_create_with_dps(AZURE_IOT_MQTT* azure_iot_mqtt, - NX_IP* nx_ip, - NX_PACKET_POOL* nx_pool, - NX_DNS* nx_dns, - func_ptr_unix_time_get unix_time_get, - CHAR* iot_dps_id_scope, - CHAR* iot_registration_id, - CHAR* iot_sas_key, - CHAR* iot_model_id) -{ - UINT status; - - printf("\r\nInitializing MQTT DPS client\r\n"); - - if (azure_iot_mqtt == NULL) - { - printf("ERROR: azure_iot_mqtt is NULL\r\n"); - return NX_PTR_ERROR; - } - - if (iot_dps_id_scope[0] == 0 || iot_registration_id[0] == 0 || iot_sas_key[0] == 0) - { - printf("ERROR: IoT DPS connection configuration is empty\r\n"); - return NX_PTR_ERROR; - } - - memset(azure_iot_mqtt, 0, sizeof(*azure_iot_mqtt)); - - // Stash the connection information - azure_iot_mqtt->nx_dns = nx_dns; - azure_iot_mqtt->unix_time_get = unix_time_get; - azure_iot_mqtt->mqtt_dps_id_scope = iot_dps_id_scope; - azure_iot_mqtt->mqtt_dps_registration_id = iot_registration_id; - azure_iot_mqtt->mqtt_sas_key = iot_sas_key; - azure_iot_mqtt->mqtt_model_id = iot_model_id; - - // Setup DPS - status = azure_iot_dps_create(azure_iot_mqtt, nx_ip, nx_pool); - if (status != NX_SUCCESS) - { - printf("ERROR: Failed to create DPS client (0x%04x)\r\n", status); - return status; - } - - status = azure_iot_dps_register(azure_iot_mqtt, NX_WAIT_FOREVER); - if (status != NX_SUCCESS) - { - printf("ERROR: Failed to register DPS device (0x%04x)\r\n", status); - azure_iot_dps_delete(azure_iot_mqtt); - return status; - } - - status = azure_iot_dps_delete(azure_iot_mqtt); - if (status != NX_SUCCESS) - { - printf("ERROR: Failed to delete DPS client (0x%04x)\r\n", status); - return status; - } - - printf("SUCCESS: MQTT DPS client initialized\r\n"); - - // call into common code - return azure_iot_mqtt_create_common(azure_iot_mqtt, nx_ip, nx_pool); -} - -UINT azure_iot_mqtt_delete(AZURE_IOT_MQTT* azure_iot_mqtt) -{ - nxd_mqtt_client_disconnect(&azure_iot_mqtt->nxd_mqtt_client); - nxd_mqtt_client_delete(&azure_iot_mqtt->nxd_mqtt_client); - - return NXD_MQTT_SUCCESS; -} - -UINT azure_iot_mqtt_connect(AZURE_IOT_MQTT* azure_iot_mqtt) -{ - UINT status; - CHAR mqtt_subscribe_topic[100]; - NXD_ADDRESS server_ip; - - printf("\tHub hostname: %s\r\n", azure_iot_mqtt->mqtt_hub_hostname); - printf("\tDevice id: %s\r\n", azure_iot_mqtt->mqtt_device_id); - printf("\tModel id: %s\r\n", azure_iot_mqtt->mqtt_model_id); - - // Create the username & password - snprintf(azure_iot_mqtt->mqtt_username, - AZURE_IOT_MQTT_USERNAME_SIZE, - USERNAME, - azure_iot_mqtt->mqtt_hub_hostname, - azure_iot_mqtt->mqtt_device_id, - azure_iot_mqtt->mqtt_model_id); - - if (!create_sas_token(azure_iot_mqtt->mqtt_sas_key, - strlen(azure_iot_mqtt->mqtt_sas_key), - azure_iot_mqtt->mqtt_hub_hostname, - azure_iot_mqtt->mqtt_device_id, - azure_iot_mqtt->unix_time_get(), - azure_iot_mqtt->mqtt_password, - AZURE_IOT_MQTT_PASSWORD_SIZE)) - { - printf("ERROR: Unable to generate SAS token\r\n"); - return NX_PTR_ERROR; - } - - status = nxd_mqtt_client_login_set(&azure_iot_mqtt->nxd_mqtt_client, - azure_iot_mqtt->mqtt_username, - strlen(azure_iot_mqtt->mqtt_username), - azure_iot_mqtt->mqtt_password, - strlen(azure_iot_mqtt->mqtt_password)); - if (status != NXD_MQTT_SUCCESS) - { - printf("Could not create Login Set (0x%02x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Resolve the MQTT server IP address - status = nxd_dns_host_by_name_get(azure_iot_mqtt->nx_dns, - (UCHAR*)azure_iot_mqtt->mqtt_hub_hostname, - &server_ip, - NX_IP_PERIODIC_RATE, - NX_IP_VERSION_V4); - if (status != NX_SUCCESS) - { - printf("Unable to resolve DNS for MQTT Server %s (0x%02x)\r\n", azure_iot_mqtt->mqtt_hub_hostname, status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - // Stash the hostname in a global variable so we can verify the cert at connect - azure_iot_x509_hostname = azure_iot_mqtt->mqtt_hub_hostname; - - status = nxd_mqtt_client_secure_connect(&azure_iot_mqtt->nxd_mqtt_client, - &server_ip, - NXD_MQTT_TLS_PORT, - tls_setup, - MQTT_KEEP_ALIVE, - NX_TRUE, - MQTT_TIMEOUT); - if (status != NXD_MQTT_SUCCESS) - { - printf("Could not connect to MQTT server (0x%02x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - snprintf(mqtt_subscribe_topic, sizeof(mqtt_subscribe_topic), DEVICE_MESSAGE_TOPIC, azure_iot_mqtt->mqtt_device_id); - status = nxd_mqtt_client_subscribe( - &azure_iot_mqtt->nxd_mqtt_client, mqtt_subscribe_topic, strlen(mqtt_subscribe_topic), MQTT_QOS_0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in subscribing to server (0x%02x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - status = nxd_mqtt_client_subscribe( - &azure_iot_mqtt->nxd_mqtt_client, DIRECT_METHOD_TOPIC, strlen(DIRECT_METHOD_TOPIC), MQTT_QOS_0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in direct method subscribing to server (0x%02x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - status = nxd_mqtt_client_subscribe( - &azure_iot_mqtt->nxd_mqtt_client, DEVICE_TWIN_RES_TOPIC, strlen(DEVICE_TWIN_RES_TOPIC), MQTT_QOS_0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in device twin response subscribing to server (0x%02x)\r\n", status); - nx_secure_tls_session_delete(&azure_iot_mqtt->nxd_mqtt_client.nxd_mqtt_tls_session); - return status; - } - - status = nxd_mqtt_client_subscribe(&azure_iot_mqtt->nxd_mqtt_client, - DEVICE_TWIN_DESIRED_PROP_RES_TOPIC, - strlen(DEVICE_TWIN_DESIRED_PROP_RES_TOPIC), - MQTT_QOS_0); - if (status != NXD_MQTT_SUCCESS) - { - printf("Error in device twin desired properties response subscribing to server (0x%02x)\r\n", status); - return status; - } - - printf("SUCCESS: MQTT Hub client initialized\r\n\r\n"); - - return NXD_MQTT_SUCCESS; -} - -UINT azure_iot_mqtt_disconnect(AZURE_IOT_MQTT* azure_iot_mqtt) -{ - UINT status = nxd_mqtt_client_disconnect(&azure_iot_mqtt->nxd_mqtt_client); - - return status; -} diff --git a/shared/src/azure_iot_mqtt/azure_iot_mqtt.h b/shared/src/azure_iot_mqtt/azure_iot_mqtt.h deleted file mode 100644 index 8cbc85bc..00000000 --- a/shared/src/azure_iot_mqtt/azure_iot_mqtt.h +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _AZURE_IOT_MQTT_H -#define _AZURE_IOT_MQTT_H - -#include - -#include "tx_api.h" - -#include "nx_api.h" -#include "nxd_dns.h" -#include "nxd_mqtt_client.h" - -#include "azure_iot_ciphersuites.h" - -#define AZURE_IOT_MQTT_HOSTNAME_SIZE 100 -#define AZURE_IOT_MQTT_DEVICE_ID_SIZE 64 -#define AZURE_IOT_MQTT_USERNAME_SIZE 256 -#define AZURE_IOT_MQTT_PASSWORD_SIZE 256 -#define AZURE_IOT_MQTT_TOPIC_NAME_LENGTH 256 -#define AZURE_IOT_MQTT_MESSAGE_LENGTH 1024 -#define AZURE_IOT_MQTT_DIRECT_COMMAND_RID_SIZE 6 - -#define AZURE_IOT_MQTT_CLIENT_STACK_SIZE 4096 -#define AZURE_IOT_MQTT_CERT_BUFFER_SIZE 4096 - -#define TLS_PACKET_BUFFER 4096 - -#define MQTT_QOS_0 0 // QoS 0 - Deliver at most once -#define MQTT_QOS_1 1 // QoS 1 - Deliver at least once -#define MQTT_QOS_2 2 // QoS 2 - Deliver exactly once - -typedef struct AZURE_IOT_MQTT_STRUCT AZURE_IOT_MQTT; - -typedef void (*func_ptr_direct_method)(AZURE_IOT_MQTT*, CHAR*, CHAR*); -typedef void (*func_ptr_c2d_message)(AZURE_IOT_MQTT*, CHAR*, CHAR*); -typedef void (*func_ptr_device_twin_desired_prop)(AZURE_IOT_MQTT*, CHAR*); -typedef void (*func_ptr_device_twin_prop)(AZURE_IOT_MQTT*, CHAR*); -typedef ULONG (*func_ptr_unix_time_get)(VOID); - -struct AZURE_IOT_MQTT_STRUCT -{ - NXD_MQTT_CLIENT nxd_mqtt_client; - NX_DNS* nx_dns; - - // TX_MUTEX mqtt_mutex; - TX_EVENT_FLAGS_GROUP mqtt_event_flags; - UINT mqtt_dps_status; - - // Hub config - CHAR mqtt_hub_hostname[AZURE_IOT_MQTT_HOSTNAME_SIZE]; - - // DPS config - CHAR* mqtt_dps_id_scope; - CHAR* mqtt_dps_registration_id; - - // Device config - CHAR mqtt_device_id[AZURE_IOT_MQTT_DEVICE_ID_SIZE]; - CHAR* mqtt_sas_key; - CHAR* mqtt_model_id; - - UINT dps_retry_interval; - - UINT reported_property_version; - UINT desired_property_version; - CHAR direct_command_request_id[AZURE_IOT_MQTT_DIRECT_COMMAND_RID_SIZE]; - - CHAR mqtt_username[AZURE_IOT_MQTT_USERNAME_SIZE]; - CHAR mqtt_password[AZURE_IOT_MQTT_PASSWORD_SIZE]; - - CHAR mqtt_receive_topic_buffer[AZURE_IOT_MQTT_TOPIC_NAME_LENGTH]; - CHAR mqtt_receive_message_buffer[AZURE_IOT_MQTT_MESSAGE_LENGTH]; - - ULONG mqtt_client_stack[AZURE_IOT_MQTT_CLIENT_STACK_SIZE / sizeof(ULONG)]; - - ULONG tls_metadata_buffer[NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE / sizeof(ULONG)]; - UCHAR tls_packet_buffer[TLS_PACKET_BUFFER]; - - NX_SECURE_X509_CERT mqtt_remote_certificate; - UCHAR mqtt_remote_cert_buffer[AZURE_IOT_MQTT_CERT_BUFFER_SIZE]; - - func_ptr_direct_method cb_ptr_mqtt_invoke_direct_method; - func_ptr_c2d_message cb_ptr_mqtt_c2d_message; - func_ptr_device_twin_desired_prop cb_ptr_mqtt_device_twin_desired_prop_callback; - func_ptr_device_twin_prop cb_ptr_mqtt_device_twin_prop_callback; - - func_ptr_unix_time_get unix_time_get; -}; - -UINT azure_iot_mqtt_register_direct_method_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_direct_method mqtt_direct_method_callback); -UINT azure_iot_mqtt_register_c2d_message_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_c2d_message mqtt_c2d_message_callback); -UINT azure_iot_mqtt_register_device_twin_desired_prop_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_device_twin_desired_prop mqtt_device_twin_desired_prop_update_callback); -UINT azure_iot_mqtt_register_device_twin_prop_callback( - AZURE_IOT_MQTT* azure_iot_mqtt, func_ptr_device_twin_prop mqtt_device_twin_prop_callback); - -UINT tls_setup(NXD_MQTT_CLIENT* client, - NX_SECURE_TLS_SESSION* tls_session, - NX_SECURE_X509_CERT* cert, - NX_SECURE_X509_CERT* trusted_cert); - -UINT mqtt_publish(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* topic, CHAR* message); - -UINT azure_iot_mqtt_publish_float_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, float value); -UINT azure_iot_mqtt_publish_bool_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, bool value); -UINT azure_iot_mqtt_publish_float_telemetry(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, float value); -UINT azure_iot_mqtt_publish_int_writeable_property(AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, int value); -UINT azure_iot_mqtt_respond_int_writeable_property( - AZURE_IOT_MQTT* azure_iot_mqtt, CHAR* label, int value, int http_status); -UINT azure_iot_mqtt_respond_direct_method(AZURE_IOT_MQTT* azure_iot_mqtt, UINT response); -UINT azure_iot_mqtt_device_twin_request(AZURE_IOT_MQTT* azure_iot_mqtt); - -UINT azure_iot_mqtt_create(AZURE_IOT_MQTT* azure_iot_mqtt, - NX_IP* nx_ip, - NX_PACKET_POOL* nx_pool, - NX_DNS* nx_dns, - func_ptr_unix_time_get unix_time_get, - CHAR* iot_hub_hostname, - CHAR* iot_device_id, - CHAR* iot_sas_key, - CHAR* iot_model_id); -UINT azure_iot_mqtt_create_with_dps(AZURE_IOT_MQTT* azure_iot_mqtt, - NX_IP* nx_ip, - NX_PACKET_POOL* nx_pool, - NX_DNS* nx_dns, - func_ptr_unix_time_get unix_time_get, - CHAR* iot_dps_id_scope, - CHAR* iot_device_id, - CHAR* iot_sas_key, - CHAR* iot_model_id); -UINT azure_iot_mqtt_delete(AZURE_IOT_MQTT* azure_iot_mqtt); - -UINT azure_iot_mqtt_connect(AZURE_IOT_MQTT* azure_iot_mqtt); -UINT azure_iot_mqtt_disconnect(AZURE_IOT_MQTT* azure_iot_mqtt); - -#endif // _AZURE_IOT_MQTT_H \ No newline at end of file diff --git a/shared/src/azure_iot_mqtt/hmac_sha256.c b/shared/src/azure_iot_mqtt/hmac_sha256.c deleted file mode 100644 index c229ab6c..00000000 --- a/shared/src/azure_iot_mqtt/hmac_sha256.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "hmac_sha256.h" - -#include "sha256.h" - -#define B 64 -#define L (SHA256_DIGEST_SIZE) -#define K (SHA256_DIGEST_SIZE * 2) - -#define I_PAD 0x36 -#define O_PAD 0x5C - -void hmac_sha256( - uint8_t out[HMAC_SHA256_DIGEST_SIZE], - const uint8_t* data, size_t data_len, - const uint8_t* key, size_t key_len) -{ - sha256_t ss; - uint8_t kh[SHA256_DIGEST_SIZE]; - - if (key_len > B) - { - sha256_init(&ss); - sha256_update(&ss, key, key_len); - sha256_final(&ss, kh); - key_len = SHA256_DIGEST_SIZE; - key = kh; - } - - uint8_t kx[B]; - for (size_t i = 0; i < key_len; i++) kx[i] = I_PAD ^ key[i]; - for (size_t i = key_len; i < B; i++) kx[i] = I_PAD ^ 0; - - sha256_init(&ss); - sha256_update(&ss, kx, B); - sha256_update(&ss, data, data_len); - sha256_final(&ss, out); - - for (size_t i = 0; i < key_len; i++) kx[i] = O_PAD ^ key[i]; - for (size_t i = key_len; i < B; i++) kx[i] = O_PAD ^ 0; - - sha256_init(&ss); - sha256_update(&ss, kx, B); - sha256_update(&ss, out, SHA256_DIGEST_SIZE); - sha256_final(&ss, out); -} diff --git a/shared/src/azure_iot_mqtt/hmac_sha256.h b/shared/src/azure_iot_mqtt/hmac_sha256.h deleted file mode 100644 index 11c43c1d..00000000 --- a/shared/src/azure_iot_mqtt/hmac_sha256.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _HMAC_SHA256_H -#define _HMAC_SHA256_H - -#include -#include - -#define HMAC_SHA256_DIGEST_SIZE 32 - -void hmac_sha256( - uint8_t out[HMAC_SHA256_DIGEST_SIZE], - const uint8_t* data, size_t data_len, - const uint8_t* key, size_t key_len); - -#endif // _HMAC_SHA256_H diff --git a/shared/src/azure_iot_mqtt/json_utils.c b/shared/src/azure_iot_mqtt/json_utils.c deleted file mode 100644 index 16cf3221..00000000 --- a/shared/src/azure_iot_mqtt/json_utils.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include -#include -#include - -#include "json_utils.h" - -bool findJsonInt(const char* json, jsmntok_t* tokens, int tokens_count, const char* s, int* value) -{ - for (int i = 0; i < tokens_count - 1; i++) - { - if (tokens[i].type == JSMN_STRING && tokens[i + 1].type == JSMN_PRIMITIVE) - { - if (((int)strlen(s) == tokens[i].end - tokens[i].start) && - (strncmp(json + tokens[i].start, s, tokens[i].end - tokens[i].start) == 0)) - { - *value = atoi(json + tokens[i + 1].start); - - return true; - } - } - } - - return false; -} - -bool findJsonString(const char* json, jsmntok_t* tokens, int tokens_count, const char* s, char* value) -{ - int key_len; - int value_len; - for (int i = 0; i < tokens_count - 1; i++) - { - if (tokens[i].type == JSMN_STRING && tokens[i + 1].type == JSMN_STRING) - { - key_len = tokens[i].end - tokens[i].start; - if (((int)strlen(s) == key_len) && (strncmp(json + tokens[i].start, s, key_len) == 0)) - { - value_len = tokens[i + 1].end - tokens[i + 1].start; - strncpy(value, json + tokens[i + 1].start, value_len); - value[value_len] = 0; - - return true; - } - } - } - - return false; -} diff --git a/shared/src/azure_iot_mqtt/json_utils.h b/shared/src/azure_iot_mqtt/json_utils.h deleted file mode 100644 index 36e1842f..00000000 --- a/shared/src/azure_iot_mqtt/json_utils.h +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _JSON_UTILS_H -#define _JSON_UTILS_H - -#include - -#include "jsmn.h" - -bool findJsonInt(const char* json, jsmntok_t* tokens, int tokens_count, const char* s, int* value); -bool findJsonString(const char* json, jsmntok_t* tokens, int tokens_count, const char* s, char* value); - -#endif \ No newline at end of file diff --git a/shared/src/azure_iot_mqtt/sas_token.c b/shared/src/azure_iot_mqtt/sas_token.c deleted file mode 100644 index 83ce67e3..00000000 --- a/shared/src/azure_iot_mqtt/sas_token.c +++ /dev/null @@ -1,223 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -// https://docs.microsoft.com/azure/iot-hub/iot-hub-mqtt-support - -#include "sas_token.h" - -#include -#include - -#include "hmac_sha256.h" - -// Expire in one year minus one day -#define SAS_EXPIRATION_SECS (364 * 24 * 60 * 60) -#define SAS_DPS_EXPIRATION_SECS (60 * 60) - -static bool base64_encode(char* src, size_t src_len, char* out) -{ - char* o = out; - char* p = src; - - const char* b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - for (; p < (src + src_len - 2); p += 3) - { - *o++ = b[(p[0] >> 2) & 0x3f]; - *o++ = b[((p[0] & 0x03) << 4) | ((p[1] & 0xf0) >> 4)]; - *o++ = b[((p[1] & 0x0f) << 2) | ((p[2] & 0xc0) >> 6)]; - *o++ = b[p[2] & 0x3f]; - } - - if (p < src + src_len) - { - *o++ = b[(p[0] >> 2) & 0x3f]; - - if (p == src + src_len - 1) - { - *o++ = b[((p[0] & 0x03) << 4)]; - *o++ = '='; - } - - else - { - *o++ = b[((p[0] & 0x03) << 4) | ((p[1] & 0xf0) >> 4)]; - *o++ = b[(p[1] & 0x0f) << 2]; - } - - *o++ = '='; - } - - *o = 0; - - return true; -} - -static size_t base64_decode(char* src, size_t len, char* out) -{ - unsigned char* o = (unsigned char*)out; - unsigned char* p = (unsigned char*)src; - - // clang-format off - const unsigned char b[256] = - { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 - }; - // clang-format on - - while (len > 4) - { - *o++ = b[p[0]] << 2 | b[p[1]] >> 4; - *o++ = b[p[1]] << 4 | b[p[2]] >> 2; - *o++ = b[p[2]] << 6 | b[p[3]]; - - p += 4; - len -= 4; - } - - if (len > 1) - *o++ = b[p[0]] << 2 | b[p[1]] >> 4; - if (len > 2) - *o++ = b[p[1]] << 4 | b[p[2]] >> 2; - if (len > 3) - *o++ = b[p[2]] << 6 | b[p[3]]; - - *o++ = 0; - - return (o - (unsigned char*)out); -} - -static size_t base64_decode_length(char* str, size_t len) -{ - size_t outlen = (len * 6) / 8; - - for (char* p = str + len - 1; *p == '='; p--) - { - outlen--; - } - - return outlen; -} - -static int url_encode(char* dest, char* msg) -{ - const char* hex = "0123456789abcdef"; - char* startPtr = dest; - - while (*msg != 0) - { - if (('a' <= *msg && *msg <= 'z') || ('A' <= *msg && *msg <= 'Z') || ('0' <= *msg && *msg <= '9')) - { - *dest++ = *msg; - } - else - { - *dest++ = '%'; - *dest++ = hex[*msg >> 4]; - *dest++ = hex[*msg & 15]; - } - msg++; - } - *dest = 0; - return dest - startPtr; -} - -bool create_sas_token(char* key, - unsigned int key_size, - char* hostname, - char* device_id, - unsigned long valid_until, - char* output, - unsigned int output_size) -{ - char buffer[128]; - char key_binary[96]; - int key_binary_size; - char hash[32]; - char encoded_hash[44 + 1]; - - char* output_end = output + output_size; - - valid_until += SAS_EXPIRATION_SECS; - snprintf(buffer, sizeof(buffer), "%s%%2Fdevices%%2F%s\n%lu", hostname, device_id, valid_until); - - base64_decode(key, key_size, key_binary); - key_binary_size = base64_decode_length(key, key_size); - - hmac_sha256( - (unsigned char*)hash, (unsigned char*)buffer, strlen(buffer), (unsigned char*)key_binary, key_binary_size); - - base64_encode(hash, sizeof(hash), encoded_hash); - - // Create the output SAS token - output += - snprintf(output, output_end - output, "SharedAccessSignature sr=%s%%2Fdevices%%2F%s&sig=", hostname, device_id); - output += url_encode(output, encoded_hash); - output += snprintf(output, output_end - output, "&se=%lu", valid_until); - - if ((output_end - output) < 2) - { - return false; - } - - return true; -} - -bool create_dps_sas_token(char* key, - unsigned int key_size, - char* id_scope, - char* registration_id, - unsigned long valid_until, - char* output, - unsigned int output_size) -{ - char buffer[128]; - char key_binary[96]; - int key_binary_size; - char hash[32]; - char encoded_hash[44 + 1]; - - char* output_end = output + output_size; - - valid_until += SAS_DPS_EXPIRATION_SECS; - snprintf(buffer, sizeof(buffer), "%s%%2Fregistrations%%2F%s\n%lu", id_scope, registration_id, valid_until); - - base64_decode(key, key_size, key_binary); - key_binary_size = base64_decode_length(key, key_size); - - hmac_sha256( - (unsigned char*)hash, (unsigned char*)buffer, strlen(buffer), (unsigned char*)key_binary, key_binary_size); - - base64_encode(hash, sizeof(hash), encoded_hash); - - // Create the output SAS token - output += snprintf(output, - output_end - output, - "SharedAccessSignature sr=%s%%2Fregistrations%%2F%s&sig=", - id_scope, - registration_id); - output += url_encode(output, encoded_hash); - output += snprintf(output, output_end - output, "&se=%lu&skn=registration", valid_until); - - if ((output_end - output) < 2) - { - return false; - } - - return true; -} diff --git a/shared/src/azure_iot_mqtt/sas_token.h b/shared/src/azure_iot_mqtt/sas_token.h deleted file mode 100644 index 1cdd0994..00000000 --- a/shared/src/azure_iot_mqtt/sas_token.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _SAS_TOKEN_H -#define _SAS_TOKEN_H - -#include - -bool create_sas_token(char* key, - unsigned int key_size, - char* hostname, - char* device_id, - unsigned long valid_until, - char* output, - unsigned int output_size); - -bool create_dps_sas_token(char *key, unsigned int key_size, char *id_scope, - char *registration_id, unsigned long valid_until, - char* output, - unsigned int output_size); - -#endif // _SAS_TOKEN_H diff --git a/shared/src/azure_iot_mqtt/sha256.c b/shared/src/azure_iot_mqtt/sha256.c deleted file mode 100644 index aed18777..00000000 --- a/shared/src/azure_iot_mqtt/sha256.c +++ /dev/null @@ -1,161 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#include "sha256.h" - -#define ROTL32(a, b) (((a) << (b)) | ((a) >> (32 - (b)))) -#define ROTR32(a, b) (((a) >> (b)) | ((a) << (32 - (b)))) - -#define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22)) -#define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25)) -#define s0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ (x >> 3)) -#define s1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ (x >> 10)) - -#define a(i) T[(0 - (i)) & 7] -#define b(i) T[(1 - (i)) & 7] -#define c(i) T[(2 - (i)) & 7] -#define d(i) T[(3 - (i)) & 7] -#define e(i) T[(4 - (i)) & 7] -#define f(i) T[(5 - (i)) & 7] -#define g(i) T[(6 - (i)) & 7] -#define h(i) T[(7 - (i)) & 7] - -#define blk0(i) (W[i] = data[i]) -#define blk2(i) (W[i & 15] += s1(W[(i - 2) & 15]) + W[(i - 7) & 15] + s0(W[(i - 15) & 15])) -#define Ch(x, y, z) (z ^ (x & (y ^ z))) -#define Maj(x, y, z) ((x & y) | (z & (x | y))) - -#define R(a, b, c, d, e, f, g, h, i) \ - h += S1(e) + Ch(e, f, g) + K[i + j] + (j ? blk2(i) : blk0(i)); \ - d += h; \ - h += S0(a) + Maj(a, b, c) - -#define RX_8(i) \ - R(a, b, c, d, e, f, g, h, i); \ - R(h, a, b, c, d, e, f, g, (i + 1)); \ - R(g, h, a, b, c, d, e, f, (i + 2)); \ - R(f, g, h, a, b, c, d, e, (i + 3)); \ - R(e, f, g, h, a, b, c, d, (i + 4)); \ - R(d, e, f, g, h, a, b, c, (i + 5)); \ - R(c, d, e, f, g, h, a, b, (i + 6)); \ - R(b, c, d, e, f, g, h, a, (i + 7)) - -static const uint32_t K[64] = - { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; - -static void sha256_transform(uint32_t *state, const uint32_t *data) -{ - uint32_t W[16] = {0}; - uint32_t j; - - uint32_t a, b, c, d, e, f, g, h; - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - f = state[5]; - g = state[6]; - h = state[7]; - - for (j = 0; j < 64; j += 16) - { - RX_8(0); - RX_8(8); - } - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - state[5] += f; - state[6] += g; - state[7] += h; -} - -static void sha256_write_byte_block(sha256_t *p) -{ - uint32_t data32[16]; - for (unsigned i = 0; i < 16; i++) - { - data32[i] = - ((uint32_t)(p->buffer[i * 4]) << 24) + - ((uint32_t)(p->buffer[i * 4 + 1]) << 16) + - ((uint32_t)(p->buffer[i * 4 + 2]) << 8) + - ((uint32_t)(p->buffer[i * 4 + 3])); - } - - sha256_transform(p->state, data32); -} - -void sha256_init(sha256_t *p) -{ - p->state[0] = 0x6a09e667; - p->state[1] = 0xbb67ae85; - p->state[2] = 0x3c6ef372; - p->state[3] = 0xa54ff53a; - p->state[4] = 0x510e527f; - p->state[5] = 0x9b05688c; - p->state[6] = 0x1f83d9ab; - p->state[7] = 0x5be0cd19; - p->count = 0; -} - -void sha256_update(sha256_t *p, const unsigned char *data, size_t size) -{ - uint32_t curBufferPos = (uint32_t)p->count & 0x3F; - while (size > 0) - { - p->buffer[curBufferPos++] = *data++; - p->count++; - size--; - if (curBufferPos == 64) - { - curBufferPos = 0; - sha256_write_byte_block(p); - } - } -} - -void sha256_final(sha256_t *p, unsigned char *digest) -{ - uint64_t lenInBits = (p->count << 3); - uint32_t curBufferPos = (uint32_t)p->count & 0x3F; - unsigned i; - p->buffer[curBufferPos++] = 0x80; - - while (curBufferPos != (64 - 8)) - { - curBufferPos &= 0x3F; - if (curBufferPos == 0) - { - sha256_write_byte_block(p); - } - p->buffer[curBufferPos++] = 0; - } - - for (i = 0; i < 8; i++) - { - p->buffer[curBufferPos++] = (unsigned char)(lenInBits >> 56); - lenInBits <<= 8; - } - sha256_write_byte_block(p); - - for (i = 0; i < 8; i++) - { - *digest++ = (unsigned char)(p->state[i] >> 24); - *digest++ = (unsigned char)(p->state[i] >> 16); - *digest++ = (unsigned char)(p->state[i] >> 8); - *digest++ = (unsigned char)(p->state[i]); - } - sha256_init(p); -} diff --git a/shared/src/azure_iot_mqtt/sha256.h b/shared/src/azure_iot_mqtt/sha256.h deleted file mode 100644 index 310d118d..00000000 --- a/shared/src/azure_iot_mqtt/sha256.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) Microsoft Corporation. - Licensed under the MIT License. */ - -#ifndef _SHA256_H -#define _SHA256_H - -#include -#include - -#define SHA256_DIGEST_SIZE 32 - -typedef struct -{ - uint32_t state[8]; - uint64_t count; - unsigned char buffer[64]; -} sha256_t; - -void sha256_init(sha256_t* p); -void sha256_update(sha256_t* p, const unsigned char* data, size_t size); -void sha256_final(sha256_t* p, unsigned char* digest); - -#endif // _SHA256_H