0 Comments

Following is a guidance how to set up Raspberry PI from the scratch to working Azure IoT Edge device.

There is a three step-by-step articles.

Lets do it together step-by-step.

Registering the Edge device

Before you can use your IoT devices with Azure IoT Edge, you need to register them with your IoT hub. Once you register a device, you receive a connection string that can be used to set up your device for IoT Edge workloads.

This is all about creating IoT hub in Azure and then creating/registering new IoT Edge device.

Step 1. Create IoT hub in Azure

I assume that you have already Azure subscription. If not you can get one 12 months subscription here for free: https://azure.microsoft.com/en-us/free/

  1. Open Azure portal https://portal.azure.com/
  2. Click “Create new resource

Azure create new resource

3. Enter IoT hub for the search box and click Create

Azure create iot hub

4. Configure IoT hub parameters

  1. Create new resource group, for example “TestGroup”
  2. Select the closest region, I have West Europe
  3. Enter name of your IoT hub, for example IoTHubForTestingPurposes

Azure create iot hub

5. Configure pricing

  1. Open “Size and scale” sheet
  2. Select pricingand scale: “F1: Free tier

Azure iot hub pricing

6. Click “Review + create

Azure iot hub create


Step 2. Create an Edge device

  1. Navigate to your IoT hub
  2. Select IoT Edgefrom the menu
  3. Select Add an IoT Edge device

create azure iot edge device

4. Enter name of your device

5. Leave all other information as default and click Save

create iot edge device


Step 3. Get the device connection string

  1. Openyour IoT Edge device
  2. Click Copy of Primary Connection Stringget the primary connection string


Step 4. Configure the Raspberry device

As you have now IoT Edge device created in Azure IoT hub you can configure your device to connect to the IoT hub.

In previous step you copied the connection string to your clipboard. Now this has to be placed into Edge device. Based this connection string the device knows where is the cloud and cloud knows how to find and connect with the device.

  1. Open PuTTY and connect to your device
  2. Enter following command to open configuration fileconfig.yaml
sudo nano /etc/iotedge/config.yaml

3. Find Manual provisioning section

Find the provisioning configurations of the file and uncomment the Manual provisioning configuration section.

4. Update the value of device_connection_string

Update the value of device_connection_string with the connection string from your IoT Edge device. Make sure any other provisioning sections are commented out.

# Manual provisioning configuration provisioning:
	source: "manual"
	device_connection_string: "HostName=IoTHubForTestingPurposes.azure-devices.net;DeviceId=TestDevice;SharedAccessKey=manynumbersandletters"
# DPS TPM provisioning configuration

5. Save and close the file, CTRL + X, Y, Enter.

  • Close the file: Ctrl + X
  • Do you want to save: Y
  • Exit: Enter

6. Restart your device IoT Edge daemon

sudo systemctl restart iotedge


Congratulation: you have now a working Azure IoT Edge device!

We can start to develop solutions on it but there are some tricky things so I will publish additional guidance's for tips and tricks.

0 Comments

Following is a guidance how to set up Raspberry PI from the scratch to working Azure IoT Edge device.

There is a three step-by-step articles.

Lets do it together step-by-step.

The Azure IoT Edge runtime is what turns a device into an IoT Edge device. The runtime can be deployed on devices as small as a Raspberry Pi or as large as an industrial server. Once a device is configured with the IoT Edge runtime, you can start deploying business logic to it from the cloud.

Step 0. Login to your Raspberry

Before any further step you have to log in to your Raspberry.

  1. Open PuTTY
  2. Enter your Raspberry name and connect
  3. Log in using username: pi and password: raspberry (if not changed)

Step 1. Install the latest runtime version

1. Prepare your device for the IoT Edge runtime installation.

curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list

2. Copy the generated list.

sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/

3. Install Microsoft GPG public key.

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/


Step 2. Install the container runtime

Azure IoT Edge relies on an OCI-compatible container runtime. Microsoft recommended to use the Moby-based engine provided below. It is the only container engine officially supported with Azure IoT Edge.

1. Perform apt update.

sudo apt-get update

2. Install the Moby engine.

sudo apt-get install moby-engine

3. Install the Moby command-line interface (CLI).

sudo apt-get install moby-cli


Step 3. Install the Azure IoT Edge Security Daemon

The IoT Edge security daemon provides and maintains security standards on the IoT Edge device. The daemon starts on every boot and bootstraps the device by starting the rest of the IoT Edge runtime.

1. Perform apt update.

sudo apt-get update

2. Install the security daemon.

sudo apt-get install iotedge


Step  4. Configure the security daemon

To manually provision a device, you need to provide it with a device connection string that you can create by registering a new device in your IoT hub.

Before you can configure security daemon in your IoT Edge device, you have to register your new in Azure IoT Hub.

Please take a look the third article on this series and then come back here to register your device.

#3 Registering the deviceas an IoT Edge device in Azure.

Do you have already IoT hub and Edge device in Azure?

If you have already your IoT Edge device created in Azure IoT hub, then just copy the device connection string from the Azure portal and you can immediately configure your Raspberry.

Based this connection string the device knows where is the cloud and cloud knows how to find and connect with the device.

  1. Open PuTTY and connect to your device
  2. Enter following command to open configuration file config.yaml
sudo nano /etc/iotedge/config.yaml

3. Find Manual provisioning section

Find the provisioning configurations of the file and uncomment the Manual provisioning configuration section.

4. Update the value of device_connection_string

Update the value of device_connection_string with the connection string from your IoT Edge device. Make sure any other provisioning sections are commented out.

# Manual provisioning configuration provisioning:
	source: "manual"
	device_connection_string: "HostName=IoTHubForTestingPurposes.azure-devices.net;DeviceId=TestDevice;SharedAccessKey=manynumbersandletters"
# DPS TPM provisioning configuration

5. Save and close the file, CTRL + X, Y, Enter.

  • Close the file: Ctrl + X
  • Do you want to save: Y
  • Exit: Enter

6. Restart your device IoT Edge daemon

sudo systemctl restart iotedge

Congratulation: you have now a working Azure IoT Edge device!

We can start to develop solutions on it but there are some tricky things so I will publish additional guidance's for tips and tricks.

0 Comments

Following is a guidance how to set up Raspberry PI from the scratch to working Azure IoT Edge device.

There is a three step-by-step articles.

Lets do it together step-by-step.

Installing Linux (Rasbian) on Raspberry PI

Initially I was thinking to take latest and greatest Raspberry Linux from that page https://www.raspberrypi.org/downloads/raspbian/ which is Raspbian Buster. I tried to get it working with IoT Edge but no luck. Then I read the article about supported Azure IoT Edge systems and figured out that only Raspbian-stretch is currently fully supported. Great, I spent almost half day to figure this out.

Don’t download the latest and greatest Raspbian!

Step 1. Download Raspbian-stretch image

  1. Download the Raspbian-stretch lite image from the archive here: https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/
  2. Don’t downloadthe latest and greatest version of Raspbian, it wont work.
  3. Unpack the image to your hard drive.


Step 2. Burn the image to the SD card

For this step I am using Win32 Disk Imager which can be downloaded here: https://sourceforge.net/projects/win32diskimager/

  1. Download Disk Imager and install it to your PC.
  2. Run the Disk Imager
  3. Select image file you just downloaded and unpacked from Raspbian
  4. Select SD card as your device (use at least8Gb or bigger SD card)
  5. Click Write!Disk Imager

When the process complete you may see some prompts that the drive is not ready would you like format it etc.

Don't do this! Don’t format!

Don't format the disk

There is just one partition named boot which can read. Do not touch other partitions.


Step 3. Enable SSH

SSH is used to access remotely to your Raspberry. You definitely need this so don’t think this is unnecessary step.

  1. Open boot drive from the SD card
  2. Create empty file named ssh on that drive (without any extension). No content, nothing, just 0 byte file.


Step 4. Add WiFi network

This step is makes your Raspberry PI connected into your WiFi network after booting.

  1. Open bootdrive from the SD card.
  2. Create a file named wpa_supplicant.conf
  3. Open this file with Notepad and add your WiFi network information.

Btw, my favorite notepad is Notepad++.

ctrl_interface=/run/wpa_supplicant
update_config=1
country=US
network={
	ssid="NETWORK-NAME"
	psk="NETWORK-PASSWORD"
}

Step 5. Enable I2C and SPI protocols

This step will make I2C and SPI connections available. By default they are disabled but many modern sensors are using especially I2C protocol.

  1. Open bootdrive from the SD card
  2. Open existing file config.txt
  3. Find the lines and uncomment all three lines
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on

config.txt I2C, SPI I2S


Step 6. Take the SD card and boot your Raspberry

Now is finally time to take out the SD card from your PC and start the Raspberry from it.

  1. Remove SD card from your PC
  2. Put it into Raspberry
  3. Plug the power cable
  4. Let the Raspberry boot, up to 2 minutes


Step 7. Login to your Raspberry PI through ssh

Now we will log in into the Raspberry to make some additional changes. For this step we need additional software for example PuTTY.

  1. Downloadand installPuTTY
  2. OpenPuTTY
  3. Connect to your Raspberry,
    1. the name of your fresh Raspberry is just raspberrypi
    2. Open PuTTY and connect to Raspberry
    3. First time PuTTY asks security question, Correct answer is Yes
    4. Answer Yes for this security question
  4. Loginto your Raspberry
      1. Username: pi
      2. Password: raspberry
  5. You are in!

Logged in into Raspberry


Step 8. Change your Raspberry name!

You can’t have many devices with the same name. It will be mesh. So better to change the name right now.

  1. Run the following command on your Raspberry:
sudo raspi-config

2. Go to Network Options

Raspberry network options

3. Go to HostnameRaspberry Hostname

4. Enter new name for this Raspberry, for example testpi and press OKRaspberry name

5. Press Finishand let the Raspberry boot

FinishReboot


Step 9. Login with the new name testpi

Login to your Raspberry with the new name


Step 10. Get the updates

To get the important updates run the command:

sudo apt-get update

Get the important updates


Congratulation: Your Raspberry PI setup is done. Please follow the next article to make this Raspberry as an IoT Edge capable device.

Next step: #2 Installing IoT Edge functionality into Raspberry

0 Comments

Another step to make my home smarter using activity detection and human presence.

1. How IoT can modernize your home security? It will be human-centric, almost nonvisible.

2. Are you tired remember another PIN? You can forget your home-security pin forever.

3. Do you need remotely turn off home security? This is easy, you don’t need to do anything for it.

This picture presenting the full smart home concept, security is just a one part of my smart home environment. The main heart is Raspberry as an IoT device and Azure cloud for information processing, reporting and alerting.

Home IoT project

The idea is to use existing:

1) PIR (passive infrared sensor) and door magnetic proximity sensors to detect human movement by sliding window algorithm and

2) Wi-Fi sniffer to detect by phone MAC-address who is at home (assumption: phone Wi-Fi is turned on).

IR detectors and door proximity sensor together are used to automatically secure on unsecure entire home. It is based on sliding window algorithm as there are clear patterns for entry/exit activities.

The accuracy is not 100%, for example, if someone is leaving and doesn’t close the door afterwards, then you cannot say is he really left or just hanging somewhere close.

Wi-Fi sniffer is just listening what kind of Wi-Fi devices are close and by MAC-address you can easily match this information to names.

Secure/unsecure your home:

If algorithm detects exit pattern, then home is automatically secured. What does it mean “secured”?

“Secure” mean just active alerting by SMS/WhatsApp/e-mail.

Secured home mean that, if PIR or proximity sensors are detecting movement, then you will be alerted by SMS, WhatsApp, e-mail that someone is at your home. You can make whatever you like to do now, call neighbors, friends, police etc.

If the person is known by his/her phone MAC-address, then there will be no alerting and security is basically off.

If your phone Wi-Fi is not turned on and you will get alerted, then you must answer to SMS/WhatsApp/e-mail notification. System automatically recognizes you and taking off active alerting functionality.