Azure IoT Edge和SQL Edge:将云工作负载卸载到地面设备

Azure IoT EdgeIoT中心的附加组件,可让您在本地而不是在云中处理某些数据并处理事件,减少传输到云的数据量,并在失去与云的连接时保持系统正常运行。



Azure SQL Edge是IoT Edge的模块,允许您在具有低内存消耗的IoT Edge设备上直接实现流数据处理和机器学习。



最初,云计算的原理在于将负载从本地设备集中转移到数据中心,因此乍一看似乎完全不了解将部分数据的云处理``返回''到地面设备的想法。在本材料中,我们将不断弄清楚这意味着什么以及它带来的好处。



我们还将在Azure中建立IoT中心,在Windows 10 IoT和Linux上部署IoT Edge运行时,配置并将仿真传感器连接到云;让我们看一下安装和配置SQL Edge。



术语问题



“ Edge”是英语“ edge”的描写纸,也许并不完全成功,但却相当成熟。这恰好意味着物联网设备的“边缘”,即直接连接到云的地面部分,但还不是云本身。尽管“边缘计算”或“边缘计算”似乎更成功,但术语“边缘计算”已经很好地确立了。在本文中,我们将使用公认的术语“边缘计算”。



" " — , - ("") . , , , . .




, , , .



:



  • . , , , . , "" . 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