Skip to content

WIZnet-ioNIC/WIZnet-PICO-AZURE-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Raspberry Pi Pico W5x00 Azure IoT SDK Examples

RP2040 or RP2350 - W5100S, W5500 or W55RP20 network examples - Azure IoT Cloud functions, Azure IoT SDK, Azure IoT device client, ...


1. 🎯 Azure IoT SDK examples

Application Description
examples Basic Azure IoT Cloud functions with Azure IoT SDK. (NonOS + WIZnet W5100S, W5500 or W55RP20)

1.1. 3rd party SDKs & libraries

3rd party SDKs & libraries are in the WIZnet-PICO-AZURE-C\libraries directory of 'WIZnet-PICO-AZURE-C', the example for connecting Azure IoT Cloud.

SDKs & libraries Description
ioLibrary_Driver A library that can control WIZnet's W5x00 series Ethernet chip.
mbedtls It supports security algorithms and SSL and TLS connection.
azure-iot-sdk-c A collection of C source files consisting of Embedded C (C-SDK) that can be used by embedded applications to securely connect IoT devices to Azure IoT Cloud.
pico-sdk It makes a development environment for building software applications for the Pico platform.
pico-extras pico-extras has additional libraries that are not yet ready for inclusion the Pico SDK proper, or are just useful but don't necessarily belong in the Pico SDK.

Each SDKs & libraries consists of submodule.

2. πŸŽ“ Getting started

Please refer to Getting Started with the Raspberry Pi Pico and the README in the pico-sdk for information on getting up and running.

2.1. πŸ—‚ Set up example

2.1.1. Make 'port' directory for azure-iot-sdk-c, ioLibrary_Driver, mbedtls and timer

For Pico - W5100S, W5500 or W55RP20 platform, we need to port code, please check porting guide below.

Result of above porting can be found in WIZnet-PICO-AZURE-C\port\azure-iot-sdk-c directory.

2.1.2. Modify 'CMakeLists.txt'

First, set the ethernet chip according to the evaluation board used in the following WIZnet-PICO-AZURE-C/CMakeLists.txt file.

  • WIZnet Ethernet HAT
  • W5100S-EVB-Pico
  • W5500-EVB-Pico
  • W55RP20-EVB-Pico
  • W5100S-EVB-Pico2
  • W5500-EVB-Pico2

For example, when using WIZnet Ethernet HAT :

# Set board
set(BOARD_NAME WIZnet_Ethernet_HAT)

When using W5500-EVB-Pico:

# Set board
set(BOARD_NAME W5500_EVB_PICO)

When using W55RP20-EVB-Pico:

# Set board
set(BOARD_NAME W55RP20_EVB_PICO)

When using W5500-EVB-Pico2:

# Set board
set(BOARD_NAME W5500_EVB_PICO2)

When using W5100S-EVB-Pico2:

# Set board
set(BOARD_NAME W5100S_EVB_PICO2)

And find the line similar to this and replace it as your environment:

# Set the project root directory if it's not already defined, as may happen if
# the tests folder is included directly by a parent project, without including
# the top level CMakeLists.txt.
if(NOT DEFINED AZURE_SDK_DIR)
    set(AZURE_SDK_DIR ${CMAKE_SOURCE_DIR}/libraries/azure-iot-sdk-c)
    message(STATUS "AZURE_SDK_DIR = ${AZURE_SDK_DIR}")
endif()

if(NOT DEFINED WIZNET_DIR)
    set(WIZNET_DIR ${CMAKE_SOURCE_DIR}/libraries/ioLibrary_Driver)
    message(STATUS "WIZNET_DIR = ${WIZNET_DIR}")
endif()

if(NOT DEFINED MBEDTLS_LIB_DIR)
    set(MBEDTLS_LIB_DIR ${CMAKE_SOURCE_DIR}/libraries/mbedtls)
    message(STATUS "MBEDTLS_LIB_DIR = ${MBEDTLS_LIB_DIR}")
endif()

if(NOT DEFINED PORT_DIR)
    set(PORT_DIR ${CMAKE_SOURCE_DIR}/port)
    message(STATUS "PORT_DIR = ${PORT_DIR}")
endif()

2.1.3. Set your board network information and select sample application

In the following WIZnet-PICO-AZURE-C/examples/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, 0x56}, // MAC address
        .ip = {192, 168, 11, 2},                     // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 11, 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
};

2.1.4. Set the key information

Copy & Paste proper connection string and key value from the Azure Portal to WIZnet-PICO-AZURE-C/examples/sample_certs.c:

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

const char pico_az_x509connectionString[] = "[device connection string]";

const char pico_az_x509certificate[] =
"-----BEGIN CERTIFICATE-----""\n"
"-----END CERTIFICATE-----";

const char pico_az_x509privatekey[] =
"-----BEGIN PRIVATE KEY-----""\n"
"-----END PRIVATE KEY-----";

const char pico_az_id_scope[] = "[ID Scope]";

const char pico_az_COMMON_NAME[] = "[custom-hsm-device]";

const char pico_az_CERTIFICATE[] =
"-----BEGIN CERTIFICATE-----""\n"
"-----END CERTIFICATE-----";

const char pico_az_PRIVATE_KEY[] =
"-----BEGIN PRIVATE KEY-----""\n"
"-----END PRIVATE KEY-----";

2.2. ⏳ Build example

2.2.1. Run command

Run the following CMake commands from the root of the repository:

mkdir build
cd build

# As your environment, select
cmake .. -G "MSYS Makefiles" ## on MSYS2 (MinGW64) + Windows 10 Platform
# or
cmake .. -G "Visual Studio 15 2017" ## For Visual Studio 2017
# or
cmake .. -G "Visual Studio 16 2019" -A Win32
# or
cmake ..

cd examples
make

Then, copy generated "main.uf2" file into your RP-Pico board. Done!

2.2.2. Patch

With Visual Studio Code, each library set as a submodule is automatically patched, but if you do not use Visual Studio Code, each library set as a submodule must be manually patched with the Git commands below in each library directory.

/* Change directory */
// change to the 'ioLibrary_Driver' library directory.
cd [user path]/WIZnet-PICO-AZURE-C/libraries/ioLibrary_Driver

// e.g.
cd D:/RP2040/WIZnet-PICO-AZURE-C/libraries/ioLibrary_Driver

/* Patch */
git apply --ignore-whitespace ../../patches/01_iolibrary_driver_sntp.patch

β€» If the board pauses when rebooting using W55RP20-EVB-Pico, patch it as follows.

// Patch
cd D:/RP2040/WIZnet-PICO-AZURE-C
git apply ./patches/0001_pico_sdk_clocks.patch

2.3. πŸ“ Sample application results

2.3.1. πŸ“¬ 'iothub_ll_telemetry_sample' application result

πŸ“‘ Let's see this doc for iothub_ll_telemetry_sample application

2.3.2. πŸ“© 'iothub_ll_c2d_sample' application result

πŸ“‘ Let's see this doc for iothub_ll_c2d_sample application

2.3.3. πŸ” 'iothub_ll_client_x509_sample' application result

πŸ“‘ Let's see this doc for iothub_ll_client_x509_sample application

2.3.4. 🚒 'prov_dev_client_ll_sample' application result

πŸ“‘ Let's see this doc for prov_dev_client_ll_sample application