Rena Kim
Published © GPL3+

How to connect to Azure IoT Central using W5100S-EVB-Pico

Using WIZnet's W5100S-EVB-Pico board can connect to Azure IoT Central with X.509 certificate.

BeginnerProtip2 hours29
How to connect to Azure IoT Central using W5100S-EVB-Pico

Things used in this project

Hardware components

W5100S-EVB-Pico
WIZnet W5100S-EVB-Pico
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Ethernet Cable, Cat6a
Ethernet Cable, Cat6a
×1

Software apps and online services

Microsoft Azure IoT Central
MS Azure IoT Central

Story

Read more

Code

Root CA

Plain text
~$ mkdir rootca
~$ cd rootca/
~/rootca$ mkdir certs db private

~/rootca$ touch db/index
~/rootca$ openssl rand -hex 16 > db/serial
~/rootca$ echo 1001 > db/crlnumber

*# Change certificate name (commonName)**
~/subca$ vi rootca.conf

~/rootca$ openssl req -new -config rootca.conf -out rootca.csr -keyout private/rootca.key
~/rootca$ openssl ca -selfsign -config rootca.conf -in rootca.csr -out rootca.crt -extensions ca_ext

Verify

Plain text
~/subca$ openssl genpkey -out pop.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048
~/subca$ openssl req -new -key pop.key -out pop.csr

****Paste the verification code into Common Name**

~/subca$ openssl ca -config subca.conf -in pop.csr -out pop.crt -extensions client_ext

Device Cert

Plain text
$ openssl genpkey -out device.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048
$ openssl req -new -key device.key -out device.csr

==> Common Name (e.g. server FQDN or YOUR name) []: Enter w5100s-evb-pico-01

$ openssl req -text -in device.csr -noout
$ openssl ca -config subca.conf -in device.csr -out device.crt -extensions client_ext

main.c

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

Convert certificate

Plain text
$ vi convert_cert.sh

input=$1
bContinue=true
prev=
while $bContinue; do
    if read -r next; then
      if [ -n "$prev" ]; then
        echo "\"$prev\\n\""
      fi
      prev=$next
    else
      echo "\"$prev\";"
      bContinue=false
    fi
done < "$input"

sample_certs.c

Plain text
const char pico_az_id_scope[] = "<ID Scope>";

const char pico_az_COMMON_NAME[] = "w5100s-evb-pico-01";

const char pico_az_CERTIFICATE[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIDQDCCAiigAwIBAgIPAoh1JOyCoN2l8TasygP2MA0GCSqGSIb3DQEBCwUAMCUx\n"
...
"3agwSktbbJYEpQt2sZrdgIf5V3RsZH2/wZtLBBiVFismcVVEgY2qnBQXNxyQcc0z\n"
"9Vz3OITjhrWKTMkF0l/TNiy4eEU=\n"
"-----END CERTIFICATE-----";

const char pico_az_PRIVATE_KEY[] =
"-----BEGIN PRIVATE KEY-----\n"
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDpHayE/0vdXbp2\n"
...
"W10KeONpLN+MyMr0fDgsHb6Bc5Re/S4s+CgprfvxiHLgQSFlb1wfCXG3xvuqgJk+\n"
"vrEySFLI2uifS0f64HLVtAPe\n"
"-----END PRIVATE KEY-----";

Build logs

Plain text
[main] Building folder: RP2040-HAT-AZURE-C 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --build d:/_RaspberryPi_Pico/RP2040-HAT-AZURE-C/build --config Debug --target all -j 10 --
[build] Warning: NMake does not support parallel builds. Ignoring parallel build command line option.
[build] [  0%] Built target bs2_default
[build] [  1%] Built target bs2_default_padded_checksummed_asm
[build] [ 12%] Built target mbedcrypto
...
...
[build] [ 97%] Built target LOOPBACK_FILES
[build] [ 97%] Built target FTPSERVER_FILES
[build] [ 98%] Built target HTTPSERVER_FILES
[build] [100%] Built target MQTT_FILES
[build] Build finished with exit code 0

RP2040-HAT-AZURE-C

https://github.com/Wiznet/RP2040-HAT-AZURE-C

Credits

Rena Kim

Rena Kim

1 project • 0 followers

Comments