In this tutorial you'll create device code that sends a message to IoT Hub when booting up. Knowing your Raspberry Pi's hostname and IP address is helpful information needed to connect via ssh or from Visual Studio Code.
Deploy and Configure StreamAnalytics
-
From your Windows Cloud Machine, open a console application and remote SSH into your Raspberry Pi from the command prompt as using {your account}@{hostname}, for example,
c:\>ssh me@raspberrypi me@raspberrypi's password: Linux raspberrypi 5.15.76-v7+ #1597 SMP Fri Nov 4 12:13:17 GMT 2022 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Jan 1 20:27:12 2023 from fe80::5a68:8a07:f908:168a%wlan0 me@raspberrypi:~ $
-
Using your remote SSH session, open crontab in the GNU nano editor in your Raspberry Pi,
$ crontab -e
For example,
-
Copy and paste the following entry to crontab,
@reboot python ~/repos/IoT/python/raspberrypi/d2cipandhostname.py
*Note that you can use the sudo command in the previous step, but you'll need to reference the full path. For example,
$ sudo crontab -e @reboot python /home/jbeman/repos/IoT/python/raspberrypi/d2cipandhostname.py
-
Type ctrl-o and hit the enter key, for example,
$ ctrl-o $ File Name to Write: /tmp/crontab.4SQV5b/crontab
-
Type
ctrl-x
to exitcrontab
, then run the following command,sudo shutdown -r
-
Verify the message was sent to the cloud and saved in storage using Stream Analytics.
Congratulations, you've successfully remotely coded a real device and connected it to Azure! You are ready to continue your journey and learn to wire IoT electronics to your Raspberry Pi and remotely controlling it.