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

IOTA on 2014 aastal loodud innovaatiline ja tulevikukindel tehnoloogia, mis loob turvalise andmevõrgu Internet of Things ehk IoT seadmetele.

IOTA-t nimetatakse mõnikord ka blockchain 3.0, kuigi IOTA ei ole blockchain.

IOTA sobib suurepäraselt IoT seadmetel põhinevatele rakendustele, võimaldades

  • mikro- ja nanomakseid,
  • odomeetrid (auto pass),
  • seadmelt-seadmele suhtlust (sensorid-kontrollerid),
  • smart city,
  • energy grid,
  • adaptiivsed süsteemid
  • jm suured hajusvõrgud,
  • Industrial Revolution 4.0.

IOTA võimalused

Kui maailm on vaevalt hakanud rääkima blockchainist ja aru saamas selle toimise põhimõtetest ning kasulikkusest majandusele, on matemaatikud-geeniused-programmeeriad välja töötanud täielikult teistel alustel töötava krüptoraha mudeli IOTA.

IOTA vs Blockchain

Mille poolest erineb IOTA blockchainist?

tangle vs blockchain

  • IOTA võrk on suunatud atsükliline graaf (Directed Acyclic Graph - DAG) ja  alustehnoloogia kannab nime Tangle. Blockchainis on kõik blokid ühes ranges reas.
  • IOTA-s pole blokke, ahelat ja ei toimu kaevandamist. Blockchainis asuvad kõik tehingud blokkides ja tehingute kinnitamist nimetatakse kaevandamiseks ning see võtab aega.
  • IOTA-s on kõik ülekanded tasuta ja reaalajas. Blockchainis on igal ülekandel väike võrgutasu ning tehingu kinnitamine võib aega võtta 10 minutit (Bitcoin).

IOTA no fees

  • IOTA skaleerub lõpmatuseni. Blockchain ei skaleeru andmemahtude kasvades.

IOTA unlimited scalability

  • IOTA disainiti miljoneid IoT seadmeid silmas pidades, eesmärgiks ei olnud otseselt krüptoraha loomine, kuigi turul on ka IOTA krüptoraha. Blockchain ei sobi IoT seadmetele, kuna sisaldab tehingutasusid.

IOTA the next sharing economy

  • IOTA eesmärk on anda turvaline ja skaleeruv alusvõrk IoT sedmetele.
  • IOTA on tulevikukindel ja tänase teadmise kohaselt ka kvantarvutite kindel. Blockchaini on teoreetiliselt võimalik kvantarvutite tekkimisel murda.
  • IOTA tangle võrgus on võimalikud offline tehingud ja offline Tanglevõrk.Blockchainis puudub igasugune võimalus, et mõni blokk offline’s välja arvutataks ja jadasse lisataks.

Tasuta IOTA ülekanded

Erinevalt blockchainist puuduvad IOTA-s vahendustasud (seetõttu on võimalikud ka mikro- või nanomaksed).

Blockchainis eksisteerivad vahendustasud selleks, et vältida spämmerite tegevust (spämmer = DDoS rünnak). IOTA toimib graafi põhimõttel ning iga tehing peab enne võrku jõudmist valideerima kaks eelmist tehingut, sellega on muudetud spämmimine (ehk DDoS rünnak) mõttetuks.

Ehk siis valideerimisnõudega saavutati IOTA-s kaks eelist:

  • tehingud on tasuta,
  • välistatud tehingute spämm.

 

Kuidas toimib IOTA?

Alljärgnevalt püüan seda keerulist IOTA asja selgitada. Selleks, et IOTA toimimisest lõpuni aru saada peab aga olema kõrgema matemaatikaga sina-peal.

1: IOTA Tangle on suunatud atsükliline graaf (Directed Acyclic Graph ehk DAG). Tangle pole blockchain. Blockchain on ahel, tangle on graaf.

DAG on suunatud graaf, kus  puudub tsükkel, ehk siis graafi tipud on teineteisele pidevas järgnevuses.

IOTA tangle

Sellel pildil tähistavad tähed/tipud IOTA tehinguid ja nool tähistab tehingu valideerimise suunda. Aeg liigub vasakult paremale ning tsüklite tekkimine on välistatud. Iga tehing kinnitab kaks eelmist tehingut, A kinnitab näiteks tehingud B ja D.

2: IOTA on skaleeruv.Iga node peab omapoolse tehingu tegemisel kinnitama enne kaks teist tehingut.

3: IOTA on detsentraliseeritud.

4: IOTA on kiire.

5: IOTA tehingud on tasuta. Blockchaini puhul lisandub alati väikene võrgutasu mis läheb tehingu kinnitamise arvutamiseks.

6: IOTA on kvantarvutite kindel, tänase teadmise kohaselt. Blockchaini on teoreetiliselt võimalik ülisuure arvutusvõimsusega murda (täna sellist arvutusvõimsust ei eksisteeri).

Skaleeruvus

IOTA skaleeruvus väljendub selles, et enne oma tehingu sooritamist tuleb kinnitada kaks teist tehingut. Seega, mida rohkem on IOTA-s seadmeid ja suhtlust, seda kiiremini saavad tehingud kinnituse.

Mida rohkem on IOTA kasutajaid, seda kõrgemaks muutub turvalisus ja kiiremaks tehingute kinnitamine.

Kuna iga tehingu lisandumisel saavad kinnituse kaks eelmist tehingut, tõuseb iga üksiku tehingu usaldusväärsus ajas.

Võrreldes blockchainiga muutub IOTA ajas seda kiiremaks mida rohkem on kasutajaid kuna seal puudub blockchainile omane blokkide arvutamine. Blockchain on oma olemuselt mahtude kasvades ajas aeglasemaks muutuv.

Kuidas IOTA kiiremaks muutub?

IOTA ei pea järjestama oma tehinguid nende täpses toimumise järjekorras nagu see toimub blockchainis. Tehingud võivad asuda suvalises järjekorras.

Kui lülitada juurde uus node, siis sünkroniseerimisel grupeeritakse tehingud aadresside järgi ja tehingute järjestus pole samal ajal oluline. IOTA aadress on nn. krüptoraha konto, millega tehakse tehinguid.

IOTA tehingute kiirus on väga suur sest ühe konto arvutamisel arvestatakse kommutatiivsuse seadust a+b=b+a. Tehingud liidetakse kokku kokku suvalises järjekorras ning see tagab kiiruse. Nullide liitmise peale aega ei kulutata, need visatakse lõppu.

Blockchainis on tehingud rangelt ajalises järjestuses ja seal ei arvestata kommutatiivsuse seadust seega kõik tehingud tuleb ükshaaval kokku liita.

IOTA-s puudub mõiste “maksimaane tehingute arv ühes blokis” nagu see on blockchainis. Näiteks suure hulga tehingute korral ootavad blockchain tehingud järjekorras ja see lisab ajalise viite nende kinnitamisele.

Tulenevalt graafi iseloomust kinnitatakse IOTA-s tehinguid paralleelselt. Blockchainis toimub tehingute kinnitamine ühes kindlas ahelas ja järjestuses ning see tingib paratamatult andmemahtude kasvades kiiruse langust.

Konsensusel põhinev võrk?

Me teame, et inimeste vahel pole 100% konsensust olemas, alati on kellelgi oma arvamus.

IOTA tehingud kinnitatakse Markov chain Monte Carlo (MCMC) algoritmiga konsensue põhimõttel.

IOTA konsensus

Rohelisedon konsensusega kinnitatud tehingud, punastetehingute puhul pole konsensus lõplikult kindel ja hallidon täiesti uued, kinnitamata tehingud.

Kuidas siis saavad hallid tehingud endale kinnituse?

Tehingute kinnitamise algoritm baseerub MCMC-l. Kui näiteks kaupmehe jaoks on tehingu 51% tõenäosus piisav, võib ta oma tehing edukaks lugeda. Seega kinnituste lisandumisel liiguvad punased tehingud lihtsalt aja möödudes roheliseks.

Ebaaus tehing süsteemis?

Esimene küsimus mis ülaltoodud kirjelduse peale ilmselt tekib on, et “mis siis kui ma panen süsteemi ebaausa tehingu?”

Oletagem näiteks, et üks hall tehing on non-valid,mis tähendab peaasjalikult seda, et üritatakse maksta rahaga mida kontol pole.

  1. Esiteks kinnitab see non-validtehing kaks punast tehingut
  2. siis jääb non-valid tehing endale kinnitust ootama, et võrku pääseda
  3. saabub uus tehing, mis ühena peab kinnitama selle non-valid tehingu
  4. kinnitamiseks arvutatakse kontojääk ning kui see ei klapi, tehingule kinnitust ei anta ja see jääb süsteemist välja
  5. kui aga peaks osutuma mingil (tehnilisel) põhjusel et non-validtehing saab siiski kinnituse, peavad seda ka teised valideerima ning pettus tuleb igal juhul välja.
  6. Lisaks on selline “pahatahtlik” kinnitamine väga ohtlik, kuna non-valid tehingule kinnituse andja node’i edaspidiseid tehinguid ei kinnita. Node muutub süsteemi jaoks ebausaldusväärseks.

Seega IOTA süsteemi autentsul baseerub ühisel tehingute-vahelisel konsensusel.

Masinad teenivad raha?

Lähitulevikus on võimalik mudel, kus masinad hakkavad ise maksma oma hoolduse, energiatarbe, arvutusvõimsuse, andmemahu või ka kindlustuse eest. Seega masinad hakkavad isesisvalt teenima ja kulutama raha sensoritelt ja anduritelt saadud info põhjal.

Masinal tekib esimest korda mõttekus pangakonto omanikuks hakata. Masina sissetulek baseerub pakutavatel teenustel ning väljaminekud võivad olla energia või kindlustuse maksed.

IOTA ärimudelid?

IOTA ärimudelite väljatöötamisega tegeleb Innovation HUB.

IOTA ja Microsoft

Microsoft teeb koostööd IOTA-ga. Azure’s on olemas teenused IOTA kasutamiseks.

  • IoT seadmete maksekanal
  • Smart Contracts
  • Luua oma Tangle võrk