Home

Awesome

How to use Azure SDK for C through Swift

This is a sample implementation of the Embedded C SDK which simplifies the connection of Swift applications to Azure IoT services like Azure IoT Hub and Azure Device Provisioning Service (DPS). We have a sample using this library in an iOS application linked here.

Architecture view

The illustration below shows the Swift sample taking a dependency on the Embedded C SDK which provides libraries used to access all Azure IoT functionalities.

This SDK also implements the BYO (bring your own) network stack approach, which means device builders can choose whichever MQTT client, TLS and TCP stack that works better for their target platform.

In this case, this sample leverages Swift MQTT, Swift NIO-SSL and Swift NIO.

<img src="./resources/architecture.png" width="80%">

Features

Prerequisites

The following should be completed before getting the sample running.

If you're using WSL on Windows with Ubuntu 20.04, you can follow the steps below to get Swift working. For all other OS's and additional setup steps, please refer to the official Swift documentation.

# Last updated on 02-14-2022

apt-get update
apt-get install curl clang libicu-dev git libatomic1 libicu66 libxml2 libcurl4 zlib1g-dev libbsd0 tzdata libssl-dev libsqlite3-dev libblocksruntime-dev libncurses5-dev libdispatch-dev -y
mkdir ~/swift
cd ~swift
wget https://download.swift.org/development/ubuntu2004/swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a/swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a-ubuntu20.04.tar.gz
tar -xvzf ./swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a-ubuntu20.04.tar.gz -C ~/swift
echo 'export PATH="~/swift/swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a-ubuntu20.04/usr/bin:$PATH"' >> ~/.profile
echo 'export PATH="~/swift/swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a-ubuntu20.04/usr/bin:$PATH"' >> ~/.bashrc
export PATH="~/swift/swift-DEVELOPMENT-SNAPSHOT-2022-02-03-a-ubuntu20.04/usr/bin:$PATH" 

Getting Started

Once you have the prerequisites completed:

swift package clean
swift build
swift run demo

Known Issues and Limitations

Support

The Swift sample is an open source solution, it is NOT a Microsoft supported solution or product. For bugs and issues with the codebase please log an issue in this repo.

Contributing

If you would like to contribute to the Swift sample, please base your own branch and pull request (PR) off our dev branch.