Skip to content

Commit 739c269

Browse files
authored
Arduino nano RP2040 and portenta H7 samples (#51)
* Merging nano and portenta samples * Addressing comments * Addressing comments Central Arduino Nano * Addressing comments Central Arduino Portenta * Adding support for ECCX08 with hmac update * Renaming and removing mbedtls includes * Adding install instructions for ArduinoECCX08 * Addressing comments
1 parent c59a2b1 commit 739c269

38 files changed

+9202
-0
lines changed

examples/Azure_IoT_Central_Arduino_Nano_RP2040_Connect/AzureIoT.cpp

Lines changed: 1309 additions & 0 deletions
Large diffs are not rendered by default.

examples/Azure_IoT_Central_Arduino_Nano_RP2040_Connect/AzureIoT.h

Lines changed: 827 additions & 0 deletions
Large diffs are not rendered by default.

examples/Azure_IoT_Central_Arduino_Nano_RP2040_Connect/Azure_IoT_Central_Arduino_Nano_RP2040_Connect.ino

Lines changed: 526 additions & 0 deletions
Large diffs are not rendered by default.

examples/Azure_IoT_Central_Arduino_Nano_RP2040_Connect/Azure_IoT_PnP_Template.cpp

Lines changed: 544 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
/*
5+
* Azure_IoT_PnP_Template.cpp implements the IoT Plug and Play template
6+
* specific for the Arduino Nano RP2040 Connect board.
7+
*/
8+
9+
#ifndef AZURE_IOT_PNP_TEMPLATE_H
10+
#define AZURE_IOT_PNP_TEMPLATE_H
11+
12+
#include "AzureIoT.h"
13+
14+
/*
15+
* @brief Initializes internal components of this module.
16+
* @remark It must be called once by the application, before any other function
17+
* call related to Azure IoT.
18+
*/
19+
void azure_pnp_init();
20+
21+
/*
22+
* @brief Returns the model id of the IoT Plug and Play template implemented by this device.
23+
* @remark Every IoT Plug and Play template has a model id that must be informed by the
24+
* device during Azure IoT provisioning and connection with the Azure IoT Hub.
25+
* @return az_span An `az_span` containing the model id implemented by this module.
26+
*/
27+
const az_span azure_pnp_get_model_id();
28+
29+
/*
30+
* @brief Sends the device description to Azure IoT Central.
31+
* @remark Azure IoT Central expects the application to send a description of device and its capabilities.
32+
* This function generates a description of the Arduino Nano RP2040 Connect and sends it to
33+
* Azure IoT Central.
34+
*
35+
* @param[in] azure_iot A pointer the azure_iot_t instance with the state of the Azure IoT client.
36+
* @param[in] request_id An unique identification number to correlate the response with when
37+
* `on_properties_update_completed` (set in azure_iot_config_t) is invoked.
38+
* @return int 0 if the function succeeds, non-zero if any error occurs.
39+
*/
40+
int azure_pnp_send_device_info(azure_iot_t* azure_iot, uint32_t request_id);
41+
42+
/*
43+
* @brief Sets with which minimum frequency this module should send telemetry to Azure IoT Central.
44+
* @remark `azure_pnp_send_telemetry` is used to send telemetry, but it will not send anything
45+
* unless enough time has passed since the last telemetry has been published.
46+
* This delay is defined internally by `telemetry_frequency_in_seconds`,
47+
* set initially to once every 10 seconds.
48+
*
49+
* @param[in] frequency_in_seconds Period of time, in seconds, to wait between two consecutive
50+
* telemetry payloads are sent to Azure IoT Central.
51+
*/
52+
void azure_pnp_set_telemetry_frequency(size_t frequency_in_seconds);
53+
54+
/*
55+
* @brief Sends telemetry implemented by this IoT Plug and Play application to Azure IoT Central.
56+
* @remark The IoT Plug and Play template implemented by this device is specific to the
57+
* Arduino Nano RP2040 Connect board, which contains several sensors. The template
58+
* defines telemetry data points for temperature, humidity, pressure, altitude,
59+
* luminosity, magnetic field, rolling and pitch angles, as well as acceleration. All of
60+
* these data are read from the board sensors and sent to Azure IoT Central when
61+
* `azure_pnp_send_telemetry` is called. This function must be called frequently enough,
62+
* no slower than the frequency set with `azure_pnp_set_telemetry_frequency` (or the
63+
* default frequency of 10 seconds).
64+
*
65+
* @param[in] azure_iot A pointer to a azure_iot_t instance, previously initialized
66+
* with `azure_iot_init`.
67+
*
68+
* return int 0 on success, non-zero if any failure occurs.
69+
*/
70+
int azure_pnp_send_telemetry(azure_iot_t* azure_iot);
71+
72+
/*
73+
* @brief Handles a command when it is received from Azure IoT Central.
74+
* @remark This function will perform the task requested by the command received
75+
* (if the command matches the expected name) and sends back a response to
76+
* Azure IoT Central.
77+
*
78+
* @param[in] azure_iot A pointer to a azure_iot_t instance, previously initialized
79+
* with `azure_iot_init`.
80+
* @param[in] command_request The `command_request_t` instance containing the details of the
81+
* device command.
82+
*
83+
* return int 0 on success, non-zero if any failure occurs.
84+
*/
85+
int azure_pnp_handle_command_request(azure_iot_t* azure_iot, command_request_t command_request);
86+
87+
/*
88+
* @brief Handles a payload with writable properties received from Azure IoT Central.
89+
* @remark This function will consume the writable properties update received
90+
* and send back a response to Azure IoT Central.
91+
*
92+
* @param[in] azure_iot A pointer to a azure_iot_t instance, previously initialized
93+
* with `azure_iot_init`.
94+
* @param[in] properties Raw properties writable-properties payload received from Azure.
95+
* @param[in] request_id The request ID of the response that is sent to the Azure IoT Central.
96+
* In Azure IoT Plug and Play, a response to a writable-property update is
97+
* itself a reported-property (device-side property) update, so it gets a
98+
* a response from Azure with the same request ID provided here as argument.
99+
*
100+
* return int 0 on success, non-zero if any failure occurs.
101+
*/
102+
int azure_pnp_handle_properties_update(azure_iot_t* azure_iot, az_span properties, uint32_t request_id);
103+
104+
#endif // AZURE_IOT_PNP_TEMPLATE_H
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
// Wifi
5+
#define IOT_CONFIG_WIFI_SSID "SSID"
6+
#define IOT_CONFIG_WIFI_PASSWORD "PWD"
7+
8+
// Azure IoT Central
9+
#define IOT_CONFIG_DPS_ID_SCOPE "ID Scope"
10+
#define IOT_CONFIG_DEVICE_ID "Device ID"
11+
#define IOT_CONFIG_DEVICE_KEY "Device Key"
12+
13+
// User-agent (url-encoded) provided by the MQTT client to Azure IoT Services.
14+
// When developing for your own Arduino-based platform, please follow the format '(ard;<platform>)'.
15+
#define IOT_CONFIG_AZURE_SDK_CLIENT_USER_AGENT "c%2F" AZ_SDK_VERSION_STRING "(ard;nanorp2040connect)"
16+
17+
// For how long the MQTT password (SAS token) is valid, in minutes.
18+
// After that, the sample automatically generates a new password and re-connects.
19+
#define IOT_CONFIG_MQTT_PASSWORD_LIFETIME_IN_MINUTES 60
20+
21+
// Time Zone Offset
22+
#define IOT_CONFIG_TIME_ZONE -8
23+
#define IOT_CONFIG_TIME_ZONE_DAYLIGHT_SAVINGS_DIFF 1
24+
#define IOT_CONFIG_DAYLIGHT_SAVINGS true
Loading
Loading

0 commit comments

Comments
 (0)