Azure IoT SDK example - RP2040 iothub_ll_c2d sample

1. Prepare IoT Hub and Device for this example

1.1. Azure portal

[MUST] Same as 1.1. Azure portal in _1_APP_TELEMETRY_manual.md

1.2. Developer PC

1.2.1. SDK setting

In the following pico-azure-iot-sdk-c/application/main.c source file, find the line similar to this and replace it as you want:

(...)

// The application you wish to use should be uncommented
//
//#define APP_TELEMETRY
#define APP_C2D
//#define APP_CLI_X509
//#define APP_PROV_X509

(...)

// The application you wish to use DHCP mode should be uncommented
#define _DHCP
static wiz_NetInfo g_net_info =
    {
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x11}, // MAC address
        .ip = {192, 168, 3, 111},                    // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 3, 1},                      // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
#ifdef _DHCP
        .dhcp = NETINFO_DHCP                         // DHCP enable/disable
#else
        // this example uses static IP
        .dhcp = NETINFO_STATIC
#endif

Edit the pico-azure-iot-sdk-c/application/sample_certs.c entering the proper connection string and key value from the Azure Portal:

/* Paste in the your iothub connection string  */
const char pico_az_connectionString[] = "[device connection string]";

 

/* Paste in the your iothub connection string */ const char pico_az_connectionString[] = "[device connection string]";

1.2.2. Build

Run make command

1.2.3. Azure IoT Explorer (preview) setting

[MUST] Same as1.2.3. Azure IoT Explorer (preview) setting in _1_APP_TELEMETRY_manual.md

1.2.4. Serial terminal open

Open "COM" port to see debug code

2. Run the example

This example has 2 functions:

  1. Send 3 messages from IoT device.
  2. Receive 3 C2D (Cloud to Device) messages.

2.1. copy main.uf2 file into your W5100S-EVB-Pico

2.2. Send 3 messages from IoT device to IoT Hub

Send 3 messages same as _1_APP_TELEMETRY_manual.md

You can get result of "function 1" result as below "Azure IoT Explorer" window.

 

2.3. Receive 3 C2D messages from IoT Hub to IoT device

2.3.1. How to send C2D message with Azure IoT Explorer

For "function 2", you can send C2D messages to your device with "Azure IoT Explorer" program as follows:

 

2.3.2. Getting C2D messages

Then, you can see the received #1 C2D message through your "Serial Terminal" window as below:

  • C2D Message #2

 

  • C2D Message #3