Azure IoT Edge and SQL Edge: Offloading Cloud Workloads to Ground Devices

Azure IoT Edge is an add-on to the IoT Hub that allows you to process some of the data and process events locally instead of in the cloud, reduce the amount of data transferred to the cloud, and keep the system up and running when the connection to the cloud is lost.



Azure SQL Edge is a module for IoT Edge that allows you to implement streaming data processing, machine learning directly on a device with IoT Edge with low memory consumption.



Initially, the principle of cloud computing consisted in centralized transfer of loads from local devices to data centers, so the very idea of ​​returning cloud processing of a part of the data, as it were, "back" to a ground device, at first glance may not seem entirely clear. In this material, we will consistently figure out what this means and what advantages it gives.



We will also set up an IoT Hub in Azure, deploy an IoT Edge runtime on Windows 10 IoT and Linux, configure and connect an emulated sensor to the cloud; Let's look at installing and configuring SQL Edge.



Terminology issues



"" β€” "edge", , , . "" / , .. , , . " " ( "edge computing") , " " " ". " ".



" " β€” , - ("") . , , , . .




, , , .



:



  • . , , , . , "" . Azure , , : , , ;
  • " " : ( , , ). , , , , , ;
  • - -. " ".


" ", :



  • " " . : ;
  • , .. - ;
  • , .. - .


?



IoT Edge , , , : "".



- :



  • ;
  • ;
  • , , .


IoT Edge " ":



  • . , . "", .. " " , " " . ;
  • . Azure ( HTTP, MQTT, AMQP). , . IoT Edge ;
  • "" " ": , , , , , ;
  • , .


IoT Edge , IoT Edge, "". Edge Azure.



, IoT Edge.



, Azure IoT Hub IoT Edge.



IoT Edge



IoT Edge :



  • β€” , Azure, , . IoT Edge, ;
  • β€” IoT Edge ;
  • β€” IoT Edge. , β€” Azure.


Azure IoT Edge IoT Hub Basic.


IoT Edge



IoT Edge β€” , Docker- , . . "" Azure , IoT Edge .



"" Azure , , . Azure Marketplace .



Java, .NET Core 2.0, Node.js, C, Python.



, , (Yocto Linux).



IoT Edge



IoT Edge ( , ) . ARM Intel/AMD ( ) Linux Windows, .. .



: Raspberry Pi, , , .

IoT Edge . ( ), .. - , .



:



  • , ;
  • Azure IoT Edge;
  • , IoT Edge ;
  • IoT Edge ;
  • IoT Edge , , IoT Edge, IoT Edge .


IoT Edge , β€” " ". ("downstream") , .



IoT Edge .





IoT Edge



, , . - , , . , .



Azure IoT Edge , :



  • - ;
  • ;
  • " ".






β€” , IoT Edge. , .



, inputs/inX. IoT Edge IoT Hub, $upstream. SQL- :



FROM <source> WHERE <condition> INTO <sink>


:



  • source β€” , , /messages/modules/{module_id}/outputs/{output_id};
  • condition β€” , ;
  • sink β€” () .


, , , URI .



:



FROM /messages/modules/module1/outputs/*
WHERE sensorType="pressure"
INTO $upstream


, .





"" , Azure.



IoT Edge , .



IoT Edge



-, IoT Edge IoT Hub.



IoT Hub β€” PaaS , .

IoT Edge , , IoT Hub "" IoT Edge, :



  • (transparent) β€” , IoT Hub HTTP, MQTT, AMQP. "" ;
  • (protocol translation) β€” . , IoT Hub , HTTP, MQTT, AMQP. IoT Edge "" , IoT Hub. IoT Hub IoT Edge;
  • (identity translation) β€” , (.. IoT Edge) , , IoT Hub, , .


:





IoT Edge , , , IoT Hub.



Azure SQL Edge



Azure SQL Edge ( preview) β€” , IoT Edge. SQL Edge Microsoft SQL Server Database Engine, .. SQL Edge , SQL Server Azure SQL Database. , T-SQL.



SQL Edge Azure Marketplace : , , 8 64 , (developer), 4 32 .





SQL Edge :





Azure SQL Edge preview, SQL Server.





, , IoT Edge .



IoT Edge Linux, Windows 10, , Windows 10 IoT Enterprise LTSC. IoT Edge



Windows 10 IoT Enterprise LTSC (Long-term Servicing Channel) β€” . 10 , , , , , . . (https://www.quarta-embedded.ru/we/10/, https://habr.com/ru/company/quarta/blog/279521/), 3 "" .

. IoT Edge IoT Edge.



Windows 10 x64, 1809 ( 17763). Moby, IoT Edge, . ( 2020) Windows LTSC.



IoT Edge, . , , , , .





Azure. , .



Azure, . , .



Cloud Shell :





, . , .



Bash.



Azure IoT:



az extension add --name azure-iot




az account list-locations -o Table


, West Europe. , . , .



rg-aziotedge-test ,



az group create --name rg-aziotedge-test --location westeurope -o json


IoT Hub, , iothub-test-{id}, {id} , , , .. XXYYMMDD, iothub-test-if200810. id , {id}.



IoT Hub :



az iot hub create --name iothub-test-{id} -g rg-aziotedge-test --sku S1 --location westeurope -o json


IoT Hub IoT Edge edge1:



az iot hub device-identity create --device-id edge1 --edge-enabled --hub-name iothub-test-{id} --auth-method shared_private_key


, IoT Hub, :



az iot hub device-identity show-connection-string --device-id edge1 --hub-name iothub-test-{id}


JSON .



, Azure. Resource Groups, rg-aziotedge-test. IoT Hub .



Automatic Device Management IoT Edge IoT Edge. Primary Connection String, .



. , .



Windows 10



Windows 10, :



  • IoT Edge Azure, , ;
  • Windows 10 .


. VirtualBox .



Windows 10 Enterprise LTSC 2019 (1809) . , .



"ISO β€” LTSC"

Windows. , (Nested) . .



Azure, :



az vm create --resource-group rg-aziotedge-test --name EdgeVM --image MicrosoftWindowsDesktop:Windows-10:rs5-pro:latest --admin-username azureuser --admin-password {password} --size Standard_DS1_v2


{password} β€” .



RDP.





Windows 10 , . PowerShell x64 .



, .



, 64- PowerShell,



(Get-Process -Id $PID).StartInfo.EnvironmentVariables["PROCESSOR_ARCHITECTURE"]


, Windows IoT Edge, , Moby IoT Edge:



. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; Deploy-IoTEdge


, .



PowerShell x64 . IoT Edge, :



. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
Initialize-IoTEdge -ContainerOs Windows


. , ( ).



, IoT Edge ,



Get-Service iotedge


:



. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; Get-IoTEdgeLog


, IoT Edge,



iotedge list


, .



, Edge . .



IoT Edge IoT Hub.



IoT Edge



. , Marketplace.



, , . , . .



Azure Marketplace, .



Azure IoT Hub Automatic Device Management IoT Edge. edge1.



Set Modules.





IoT Edge Modules Add Marketplace Module .





Simulated Temperature Sensor .



, SimulatedTemperatureSensor , (Desired status) running.



Next: Routes.



, Routes, . , IoT Hub. -. .



route IoT Hub ($upstream). SimulatedTemperatureSensorToIoTHub , Marketplace. SimulatedTemperatureSensor IoT Hub. , , . .





Next: Review + create, .



Review + create JSON, , IoT Edge. , SimulatedTemperatureSensor , edgeAgent, edgeHub. Create.



: IoT Edge , - . IoT Hub . , . (, , .. ) , . , IoT Edge, , . , Refresh , running, :







Windows 10 PowerShell x64 .



, , , ,



iotedge list




, :



iotedge logs SimulatedTemperatureSensor -f


, : .



Ctrl+C, .



Azure Cloud Shell. , IoT Hub:



az iot hub monitor-events --hub-name iothub-test-{id} --device-id edge1


{id} , .



, IoT Hub , Ctrl+C, .



, Windows 10. , 500 . PowerShell:



iotedge restart SimulatedTemperatureSensor


, , , :



To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).

, . ("registry"), IoT Edge , .



Azure



"" Azure:



  • Azure Functions ( )
  • Azure Stream Analytics ( )
  • Azure Machine Learning ( "")
  • Azure Custom Vision ( )
  • Azure SQL Server ( "")


Stream Analytics. , "" IoT Edge.



Stream Analytics "" "", . , Stream Analytics Azure, IoT Edge .



, , 30- . 70 , , - .



:





Azure Stream Analytics. Azure, :



  1. Azure Create a resource, Storage, Storage account.
  2. : Resource group: rg-aziotedge-test, Name: asatest{id}, Region: West Europe, Replication: LRS, .
  3. Review + create, Create.


Stream Analytics:



  1. Azure Create a resource, Internet of Things, Stream Analytics job.
  2. : Job name: asa-iotedge-test, Resource group: rg-aziotedge-test, Location: West Europe, Hosting environment: Edge.
  3. Create. Go to resource.
  4. Configure Storage account settings, Add storage account , (asatest{id}). Container ( , , asa) Save.


Stream Analytics:



  1. Job topology Inputs, Add stream input, Edge Hub. Input alias temperature, Event serialization format: JSON, Encoding: UTF-8, Event compression type: None. Save.
  2. Output alert, .


Job Topology Query :



SELECT  
    'reset' AS command
INTO
   alert
FROM
   temperature TIMESTAMP BY timeCreated
GROUP BY TumblingWindow(second,30)
HAVING Avg(machine.temperature) > 70


Save query.



reset alert, 70 30- .



IoT Edge.



  1. Azure IoT Edge.
  2. Set modules, Add Azure Stream Analytics Module asa-iotedge-test. Save.


, , . Cancel. Routes.



:



alertsToCloud FROM /messages/modules/asa-iotedge-test/* INTO $upstream
alertsToReset FROM /messages/modules/asa-iotedge-test/* INTO BrokeredEndpoint("/modules/SimulatedTemperatureSensor/inputs/control")
telemetryToAsa FROM /messages/modules/SimulatedTemperatureSensor/* INTO BrokeredEndpoint("/modules/asa-iotedge-test/inputs/temperature")


Stream Analytics, β€” IoT Hub.



Review + Create, Create. (Refresh), , asa-iotedge-test .



, , Windows 10 SimulatedTemperatureSensor:



iotedge restart SimulatedTemperatureSensor


reset, ( - ).



iotedge logs -f SimulatedTemperatureSensor


, Ctrl+C.







IoT Edge , IoT Edge :



  • (downstream) . IoT Hub;
  • IoT Hub ;
  • , IoT Hub.


:



  1. . IoT Edge . , , IoT Edge, - . IoT Edge. , Manage Child Devices Cloud Shell.
  2. IoT Hub. IoT Edge Azure. , IoT Edge , IoT Hub.
  3. . ( ) IoT Edge , IoT Hub. IoT Edge. timeToLiveSecs $edgeHub. β€” 68 , .. , IoT Edge. β€” 2 .
  4. IoT Hub. IoT Hub. .


, IoT Edge , "" IoT Edge, .



, IoT Edge SimulatedTemperatureSensor . PowerShell:



iotedge restart SimulatedTemperatureSensor


Cloud Shell IoT Edge:



az iot hub monitor-events --hub-name iothub-test-{id} --device-id edge1


, , .



Cloud Shell , , , .



, .



SQL Edge



SQL Edge preview Linux, Linux- Azure IoT Edge.



, IoT Edge. ,

IoT Edge , Cloud Shell :



az iot hub device-identity create --device-id edge2 --edge-enabled --hub-name iothub-test-{id} --auth-method shared_private_key
az iot hub device-identity show-connection-string --device-id edge2 --hub-name iothub-test-{id}


.



, {password} . .



az vm create --resource-group rg-aziotedge-test --name vm-edge2 --image microsoft_iot_edge:iot_edge_vm_ubuntu:ubuntu_1604_edgeruntimeonly:latest --admin-username azureuser --admin-password {password} --size Standard_DS1_v2 --authentication-type password


Cloud Shell:



ssh azureuser@{publicIpAddress}


{publicIpAddress} β€” .



yes. . Ubuntu, .



, IoT Edge ,



iotedge version


IoT Edge 1.0.9, , :



curl -L https://github.com/Azure/azure-iotedge/releases/download/1.0.9/libiothsm-std_1.0.9-1_ubuntu16.04_amd64.deb -o libiothsm-std.deb && sudo dpkg -i ./libiothsm-std.deb
curl -L https://github.com/Azure/azure-iotedge/releases/download/1.0.9/iotedge_1.0.9-1_ubuntu16.04_amd64.deb -o iotedge.deb && sudo dpkg -i ./iotedge.deb


, N ( ).



IoT Edge:



systemctl restart iotedge


, .



IoT Edge IoT Hub,



sudo /etc/iotedge/configedge.sh "{ }"


. .



SQL Edge IoT Edge.



  1. Azure Create a resource.
  2. Search the Marketplace Azure SQL Edge Enter.
  3. Azure SQL Edge β€” Preview , Developer Create.
  4. Target Devices for IoT Edge Module : Subscription: , IoT Hub: iothub-test-{id}, IoT Edge Device Name: edge2. Create.
  5. Set Modules on device AzureSQLEdgePreview.
  6. Environment Variables . . SA_PASSWORD: ( ), MSSQL_LCID: SQL Server (1049 ), MSSQL_COLLATION: ( ).
  7. Module Settings Restart Policy: always Desired Status: running. Update.
  8. Review + create, Create.
  9. IoT Edge .


1433 SQL Edge. :



  1. Azure rg-aziotedge-test.
  2. vm-edge2NSG. .
  3. Settings Inbound security rules, Add.
  4. Destination port ranges 1433, Protocol: TCP, Name: SQL, Action: Allow. . Add.


SQL Edge . , SQL Edge IoT Edge. SQL Edge .



  1. Azure Data Studio.
  2. Start New Connection.
  3. Server: IP- . Authentication type: SQL Login, User name: sa, Password: SQL Edge, . Connect.


:





New Query :



SELECT @@VERSION


Run Results :





:



CREATE DATABASE TestDatabase;


. , , TestDatabase :







CREATE TABLE CUSTOMERS( 
   ID   INT              NOT NULL, 
   NAME VARCHAR (20)     NOT NULL, 
   AGE  INT              NOT NULL, 
   ADDRESS  CHAR (25) , 
   SALARY   DECIMAL (18, 2),        
   PRIMARY KEY (ID));


Run. , :





T-SQL, .



, SQL Edge SQL Server. . , SQL Edge:





end-to-end SQL Edge .





rg-aziotedge-test .



IoT Edge SQL Edge. IoT Edge Windows, Linux.



Microsoft , .



Microsoft β€” .



β€” , . sergant (at) quarta.ru.




All Articles