Go to Configure your device page and setup your Pi for first-time use.
Go to Docker website and follow the steps to install Docker of CE (Community Edition) version.
-
Run below command to clone the repo.
git clone https://github.com/Azure-Samples/iot-hub-c-raspberrypi-docker.git
-
Run below commands to do the build.
sudo docker pull microsoft/iot-hub-c-raspberrypi-build sudo docker run --rm -v $PWD/iot-hub-c-raspberrypi-docker/samples:/repo -it microsoft/iot-hub-c-raspberrypi-build /build.sh --source blink
--rm
is a Docker running option. For details, please check Docker reference.$PWD/iot-hub-c-raspberrypi-docker/samples
is your sample folder path if the repo is cloned to your current working directory.-v
option maps your sample folder to/repo
folder of the Ubuntu OS running inside Docker container.-it
option allows you to interact with the running Docker container.microsoft/iot-hub-c-raspberrypi-build
is Docker image name. Referencedockerfile
folder if you're interested in how it works./build.sh
is the shell script name inside the Ubuntu container.--source blink
tellsbuild.sh
thatCMakeList.txt
is underblink
folder.
- Use SCP to deploy the built binary and sample code to your Pi's
/home/pi
folder.
Below
<>
parts need to be replaced with your own values.
cd </home/user-name/some-path/iot-hub-c-raspberrypi-docker/samples>
scp -r blink <user name>@<device ip address>:/home/pi
scp build/blink/blink <user name>@<device ip address>:/home/pi/blink
-
Use SSH to login in to the Pi device and run the app.
ssh <user name>@<device ip address> blink/blink
-
Install Visual Studio Code
-
Download and install Visual Studio Code. Visual Studio Code is a lightweight but powerful source code editor.
-
Open VS Code and install extension named
C/C++
. If you have already installed it, please make sure you're using the latest version.a. In VS Code, press
Cmd + P
and typeext install c/c++
as below.b. Click
Install
to install the extension and reload VS Code as prompted.
-
-
The
C/C++
extension needs a pipe program to communicate with a remote shell for remote debugging. Here we choose SSH. To avoid password input, we generate SSH key and upload it to Pi.a. Run
ssh-keygen
command in Terminal to generate SSH key.b. Run
ssh-copy-id <user name>@<device IP address>
to upload the SSH key to device. -
Generate
lanuch.json
.- Run below command to open
blink
folder.
code blink
- Press
F5
key. VS Code will prompt for environment selection.
- Choose
C++(GDB/LLDB)
.launch.json
is generated automatically.
- Run below command to open
-
Config
launch.json
.-
program
is the full path of the deployed app on device. The built binaryblink
, underbuild/blink
folder of host machine, is deployed to device's/home/pi/blink
folder. So the full path value should be/home/pi/blink/blink
. -
cwd
is the working folder on device and should be/home/pi/blink
. -
pipeTransport
is for authenticating pipe connection. Paste below properties tolaunch.json
and update the user name and IP address accordingly."pipeTransport": { "pipeCwd": "/usr/bin", "pipeProgram": "/usr/bin/ssh", "pipeArgs": [ "<user name>@<device ip address>" ], "debuggerPath": "/usr/bin/gdb" },
-
sourceFileMap
is for mapping the path of where the code exists on the remote shell to where it is locally. Please add this property and update these two paths accordingly."sourceFileMap": { // "remote": "local" "/home/pi/blink": "</home/user-name/some-path/iot-hub-c-raspberrypi-docker/samples/blink>" },
-
osx
specifies the debugger, which should begdb
instead oflldb
. Simply replace its value withLinux
's.
-
-
Debug
main.c
.a. Open
main.c
and insert breakpoints by pressingF9
key.b. Start debugging by pressing
F5
key. Code execution will stop at the breakpoint you set.c. Press
F10
to debug step by step. Enjoy debugging!
If you're interested in how to send messages to IoT Hub, please check Azure IoT Hub tutorial.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.