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.

0 Comments

What is the biggest cost in your home?

It is heating!

I will be introducing a home controller project, where I will be focusing on minimizing the consumption of home energy .

This project uses Microsoft software technology stack like Windows 10 IoT Core, Azure, IoThub and PowerBI. Hardware used for this project is Raspberry PI, OneWire digital temperature sensors, relays, some resistors and transistors.

IoT HomeController overview

Where did my story begin?

I had an apartment in a very cool region which has lovely architecture from ages 1950-1970. However, I had 3 major problems there:

1. During the winter we sometimes have –30 degrees and the walls of these buildings are quite thin, my monthly expenditure for heating was sometimes 500 EUR/month.

2. I love kayaking, so I need to keep my 6,5m long kayak somewhere. I cannot take it into my sleeping room.

3. I love to live in a quiet place, but there we had some lovely neighbors with a dog Rottweiler, who was barking almost all the time.

So I started to look for a new home which would be free from these problems. Now we have our own home which is quiet, it has a garage to store the kayak but most importantly, my yearly expenditure for heating the whole home is 1000 EUR using a ground based heat pump.

Even though my monthly costs are so small now, I still wanted to reduce it. I figured out 4 ways for optimization.

What to even optimize on a heat pump?

There are three things you can optimize.

1. Homes with heat pumps have some special pumps (motors), which move water inside the pipes that is inside floor. Usually these pumps are working 24/7. It sounds weird, but yes, no heat pump has been produced that would turn these motors off when room temperature is on normal levels and doesn’t need more heating.

This will be my optimization #1

If room temperature is normal and doesn’t need heating, I can safely turn off this motor to save energy consumption.


2. Usually, these homes have another motor for hot water, which enables you to have instant hot water from the shower. This pump is working 24/7 and I haven’t seen a single solution where it is turned off when there’s no demand for hot water.

This will be my optimization #2

If nobody is at home (children are at school and we are at work) or during the night time when everyone is asleep, this pump can be safely turned off to save energy consumption.


3. Heat pumps are working in automated mode, where they measure the outside temperature and the water temperature inside the heating pipes (outgoing and incoming) and based on that information, the heat pump calculates the heating time to keep the temperature constant in a room.

The heat pump doesn’t know anything about energy price.

But I know. Or the Internet knows.

Energy has a market price that will change hourly. The price is very often twice as high in daytime when compared to night time. Take a look at this graph, from 00:00 to 05:00 it has a price of 3,75 s/kWh but at 8:00 or at 18-19:00 the energy price is over 8 s/kWh. It is more than two times higher.

Energy hourly market price

This will be my optimization #3

If energy price is high, my heat pump will be turned off. This is actually the highest energy consumption in my home compared to my other optimizations.


I worked out a special algorithm to avoid a cold home if the energy price is high during the day. My program will calculate 12 cheapest hours during the day and the heat pumps are turned on only during that time. If the energy price is high during the day, I will still calculate the cheapest hours and my heating system will work during that time. The floor is from betony, so it can keep heat for many hours.

Look at the following graph. Green lines will represent 12 cheapest hours during the day, so my heat pump will work actually during periods: 00:00-06:59, 13:00-13:59, 16:00-16:50 and 21:00-23:59, altogether 12 hours in a day.

Energy hourly market price, green is 12 cheapest hours in a day

In order to use this energy price based optimization, you need to have an energy meter which measures your home energy on an hourly basis and you need an hourly based energy contract with your energy provider. I have both, so this optimization has a huge effect on my energy consumption.


What to even optimize with the ventilation system?

My home also has a ventilation system. The ventilation system will ensure that you will have fresh air in your home.

But how do I know the air is fresh? The most important parameter is to measure CO2 level. If this is high, you could turn ventilation on.  There is a proved science behind the CO2 level in rooms.

This will be my optimization #4

If CO2 level is high, my ventilation will be turned on, after CO2 level is back on normal levels, ventilation will be turned off.


Do I need reports on how my home is doing?

Initially I though that getting reports is not needed, but when I started to learn about Azure IoTHub, stream analytics and PowerBI, I figured out that asking for reports is so easily achievable, that it would be really stupid not to.

Microsoft has tons of information on how to send data to Azure through Azure IoTHub. That just required a few lines of code and the creation of an Azure IoTHub and I was ready to send data into Azure.

PowerBI is working just out-of-the-box. What I was missing was how to send data from Azure to PowerBI. That was very easy – stream analytics will do all the job for you. So I just needed to create PowerBI reports to see what’s happening at home.

Finally, I have a good PowerBI dashboard to see all different aspects regarding heating time, temperatures, CO2 levels, ventilation etc.

temperatures, proposed heating time, real heating timeheating and hot water producing time in minutes per dayCO2, humidity level and report about ventilation time in minutes per dayIoT outside temperature graph in last 24 h