0 Comments

Power Apps is a great no-code/low-code platform for home automation.

Home Automation powered by Power Apps

Remote Sauna project

Last weekend I added a new functionality into my home automation. Now the sauna can be turned on and off remotely.

This project had been in my todo list for a long time. I used to be able to turn the sauna on by phone. Just calling my son and asking him to turn it on and voilà, when I got home, it would be ready. Unfortunately, the automation stopped working once he went to high school.

DIY – Do It Yourself

I bought a long drill to drill the hole from sauna to technical room. Huhh. Finally. That was the first and most important step.

Drill the hole

The rest of the work are simple DIY - “Do It Yourself” tasks.

#1 Installing the one wire digital temperature sensor DS18B20.

digital temperature sensor DS18B20

#2 Installing the reed switch sensor + magnet for sauna door.

reed switch sensor + magnet for sauna door

#3 Installing a big ABB relay OKYM 0R40 into my home electrical panel that I found in my garage by luck.

ABB relay OKYM 0R40

#4 Already having a small reserve relay module to control the big relay.

relay module

#5 Already having the I2C to One Wire (DS2482-100) bridge device connected.

The One Wire system is a very nice solution as it can handle great amount of temperature sensors connected into it.

I2C to One Wire (DS2482-100)

#6 Eliminating the mechanical sauna heater timer.

After studying the schema I figured out that only one cable has to be reconnected.

Eliminating the sauna heater timer

#7 Connecting cables into Raspberry PI.

It used to look quite nice when I first started the project. From time to time, I decide to add to its functionalities, increasing the amount of cables by one or two.

20201206_073119808_iOS

#8 Connecting the sauna cables into the big relay.

ABB relay OKYM 0R40


Logic and programming

Every sauna automation has at least three important rules.

1. If sauna door is open then sauna can’t be turned on.

2. If sauna has been turned on already more than 3 hours then it turns off automatically.

3. If sauna temperature is extremely high (more than 110C) then it just turns off.

Implementation: the sauna button is disabled as the sauna door is open. Closing sauna door will enable the button immediately.

Home automation sauna control

Raspberry PI

Raspberry PI is the central hub of home automation. The base OS is Linux and on top of that is Azure IoT Edge, docker platform and containers. The code is inside the containers.

Visual Studio 2019 is the programming IDE. Code deployment and continuous delivery is fully automated by Azure DevOps and a self-hosted Arm32 deployment agent based on Raspberry PI.

A lot of Raspberry pin’s are already used but I have still some availability.

Raspberry PI pins

Power Apps as a user Interface

Home automation user interface is built on Power Apps. There are many reasons of choosing Power Apps over custom made web app.

#1 Power Apps is a no-code/low-code platform. Ready made components to just drag and drop them into place.

#2 Authentication is already done and it’s based on Office 365 security.

#3 Secure database connection to Azure CosmosDB is implemented by Azure Functions.

#4 Two-way communication between the app and Raspberry is secured by Azure IoT Edge.

0 Comments

You may wonder why this question even raised? Why we have to do something such a weird thing as to add Raspberry PI as an Azure DevOps agent?

Azure DevOps have plenty of agents for different OS-s to build and deploy solutions for Windows, Linux and mac-s.

Azure DevOps pipelines

Can I set up CI/CD pipeline for Raspberry?

No by default!

By default Azure DevOps doesn’t have an option to build a solution for Raspberry.

I couldn’t find complete instructions to do this so I created one.

To set up build pipeline for Raspberry we have to build Raspberry as a self-hosted agent for Azure DevOps.

After completing all the steps below you can create a fully automated CI/CD pipeline for your IoT Edge device based on Raspberry PI.

ARM32 hosted agent based on Raspberry PI

This is all SUPERCOOL !

Please be patient and follow all the steps below. It takes more than 1 hour of your time.

Ok, let’s rock with the Raspberry.

Step 1. Install Raspbian-strech /10min

This step is explained in another article so I am not going to repeat the story here. Please follow the instruction here.

#1 Installing Linux(Rasbian-stretch) on Raspberry PI

Step 2. Install prerequisites /4min

If you are smarter than me then you probably know why all this stuff needed.

sudo apt-get install python3-setuptools python3-dev build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y && sudo easy_install3 pip

Step 3. Install Python 3.7  /13min

1. Download and install Python. More information: https://gist.github.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz && tar xf Python-3.7.4.tar.xz && cd Python-3.7.4 && ./configure && make -j 4 && sudo make altinstall && cd ..

2. Make Python 3.7 as default python version. More information: https://raspberry-valley.azurewebsites.net/Python-Default-Version/ 

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 && sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 2

Step 4. Install Azure CLI tools /18min

More information: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux 

Just push enter when the script asks for the default installation directories (twice in the beginning of the script) and paths (twice in the end of script).

curl -L https://aka.ms/InstallAzureCli | bash && exec -l $SHELL

Step 5. Install the IoT Edge runtime /2sec

More information: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux

curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list && sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/ && curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg && sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

Step 6. Install the Moby container runtime /4min

More information: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux

Just push enter when the script ask for the default installation directory.

sudo apt-get update && sudo apt-get install moby-engine && sudo apt-get install moby-cli

Step 7. Install IotEdgeDev tool /15min

More information: https://github.com/Azure/iotedgedev/wiki/manual-dev-machine-setup

sudo pip3 install -U iotedgedev

Step 8. Create an agent pool /2min

Now it is time to switch into Azure DevOps portal and make some configurations here. Go to your https://dev.azure.com portal and open organization.

1. Open organization settings

Azure DevOps organization settings

2. Add new agent pool

Azure DevOps add new agent pool

3. Name it ARM

Azure DevOps add new agent pool

Step 9. Create Personal Access Token (PAT)

1. Click on your name in right corner and open Security.

Azure DevOps create personal access token (PAT)

2. Fill out the PAT form

Enter the name for the token. Put some meaningful name for it to remember later the reason you created it.

For the scope select Agent Pools (read, manage) and make sure all the other boxes are cleared. If you don’t see it just click below the link “Show more scopes”.

Azure DevOps configure personal access token (PAT)

3. Copy the PAT

Warning - Make sure you copy the above token now. You will not be able to see it again.

Azure DevOps personal access token (PAT)

v3xv75txw54cevpkriuafeawojmhqsibp4anxamtgyfr4zqt2ygq


Step 10. Configure Raspberry as an agent /3min

This script will download ARM template and configure Raspberry as an Azure DevOps hosted agent.

This script asks some questions during agent configuration.

wget https://vstsagentpackage.azureedge.net/agent/2.158.0/vsts-agent-linux-arm-2.158.0.tar.gz && mkdir myagent && cd myagent && tar zxvf ../vsts-agent-linux-arm-2.158.0.tar.gz && ./config.sh && sudo ./svc.sh install root && sudo ./svc.sh start && cd ..
  • Accept license terms: y + enter (do not just push enter as this equals No)
  • Server URL: https://dev.azure.com/testarm32 (your organization URL)
  • Your copied PAT: v3xv75txw54cevpkriuafeawojmhqsibp4anxamtgyfr4zqt2ygq
  • Agent pool: ARM
  • Agent name: just push enter

Configure Raspberry PI as an Azure DevOps self-hosted agent

Optional: You may want to change the command if there are never ARM-template available. On that case just update all the version numbers in the command.

To check never version of ARM template then open the agent pool in DevOps portal.

  • Click New Agent
  • Select Linux
  • Select ARM
  • Copy the download link (do not download this file into your PC, you don’t need it).

Finally you are done after 1h 10min!

You have now Raspberry PI configured as a self-hosted agent in Azure DevOps. For next step you can create a fully automated CI/CD pipeline for your Raspberry PI projects.

This is explained very well here by Microsoft: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-ci-cd 

Check the new agent in the Azure DevOps portal.

Azure DevOps self-hosted agent

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)

Step1. Install the latest runtime version

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

curl https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb > ./packages-microsoft-prod.deb

2. add the Microsoft package signing key to your list of trusted keys.

sudo apt install ./packages-microsoft-prod.deb

Step2. 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

Step3.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 aziot-edge defender-iot-micro-agent-edge

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 fileconfig.toml
sudo nano /etc/aziot/config.toml

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

This is the article about supported Azure IoT Edge systems. Only Raspbian Debian 11 (bullseye) is currently fully supported.

Step 1. Download Raspbian-bullseye image

  1. Download the Raspbian-bullseye lite image from the archive here: https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2022-09-26/
  2. Downloadthe latest and greatest version of Raspbian Bullseye.
  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 3.1 Add user

For security reason Debian 11 has removed the default user for Raspberry. This mean that after installation you cannot log in remotely through SSH as you dont have any user.

  1. Open boot drive from the SD card
  2. Create empty file named userconf.txton that drive.
  3. Add the following content. This content will create a username piwith password password.
pi:$6$38HiUnLhwlE1DRdL$MHHb6/OsyAlZNqmW7igj333g/CRwG/g5nls7ylTEqZZg9rOIM/cUvE962.5x6M0ONMz/r6OlBy/G6f4v8zrH51

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