Skip to content

Create example to send and receive messages with Azure #2

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 30, 2020
Merged

Create example to send and receive messages with Azure #2

merged 16 commits into from
Jul 30, 2020

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented Jul 22, 2020

Introduction

Create an official Mbed OS example to demonstrate how to use the Azure SDK to communicate with an IoT Hub.

Note

  • This uses the MQTT communication protocol
  • The application runs on the main thread, while communication is processed in a dedicated thread internally managed by the Azure SDK
  • Azure's official iothub_convenience_sample is a reference for us. Its steps and API calls are very generic and standardised, so applications that use the SDK (including ours) couldn't differ much from it. In my opinion we may include Microsoft in the copyright header once we added, just in case.

Known issues

  • (Not happening anymore) On GCC_ARM the first message fails to send:
    Error: Time:Wed Jul 22 15:33:15 2020 File:./main.cpp Func:on_connection_status Line:27 Connection failed, reason: IOTHUB_CLIENT_CONNECTION_BAD_CREDENTIAL
    
    subsequent messages are sent successfully
  • (Possible solution: Change get_timestamp() return type to int64_t to support ARMCC ntp-client#12 + retries) The shared access key to access IoT Hub relies on system time being correct. Many targets have no real time clocks, so we fetch time from an NTP server but this can fail sometimes. Please check the time printed is sensible, and reset to rerun the application as needed. A long term solution might be adding an option to use an X.509 key which does not depend on time.

Todo

  • Add copyright headers (TBC, subsequent PR) Done, Apache-2.0 license added
  • Support X.509 keys (future work)

@LDong-Arm LDong-Arm changed the title Create example Create example to send and receive messages with Azure Jul 23, 2020
Comment on lines +169 to +184
NTPClient ntp(_defaultSystemNetwork);
time_t timestamp = ntp.get_timestamp();
if (timestamp < 0) {
LogError("Failed to get the current time, error: %ld", timestamp);
return -1;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens a lot. We'd better implement a retry but it would rely on ARMmbed/ntp-client#12.

Copy link
Contributor

@evedon evedon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments

Setting connection status callback *after* all other callbacks
seems to resolve connection failure on GCC_ARM, and it seems
like the standard thing to do in Azure's existing examples.

We also reduce the frequency to process Azure communication
stack from once per 1ms (default) to 100ms.
Copy link
Contributor Author

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evedon Thanks for the review, I've addressed your comments. Also updated mbed-azure-client.lib so the license and copyright info are in place.

@LDong-Arm LDong-Arm requested a review from evedon July 27, 2020 16:28
@LDong-Arm LDong-Arm changed the base branch from master to development July 29, 2020 13:58
@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Jul 29, 2020

Changed the base branch from master to development. This aligns with the new release model of Mbed OS official example.

@evedon evedon merged commit 4d053a1 into ARMmbed:development Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants