Azure IoT Edge et SQL Edge: déchargement des charges de travail cloud sur les appareils au sol

Azure IoT Edge est un module complémentaire à IoT Hub qui vous permet de traiter certaines des données et de traiter les événements localement plutôt que dans le cloud, de réduire la quantité de données transférées vers le cloud et de maintenir le système opérationnel lorsque la connexion au cloud est perdue.



Azure SQL Edge est un module pour IoT Edge qui vous permet d'implémenter le traitement des données en streaming, l'apprentissage automatique directement sur un appareil avec IoT Edge avec une faible consommation de mémoire.



Au départ, le principe du cloud computing consistait en un transfert centralisé des charges des appareils locaux vers les centres de données, de sorte que l'idée même de renvoyer le traitement cloud d'une partie des données, en quelque sorte, «retour» vers un appareil au sol, peut à première vue ne pas sembler tout à fait claire. Dans ce document, nous déterminerons systématiquement ce que cela signifie et quels avantages cela donne.



Nous allons également mettre en place un IoT Hub dans Azure, déployer un runtime IoT Edge sur Windows 10 IoT et Linux, configurer et connecter un capteur émulé au cloud; Examinons l'installation et la configuration de SQL Edge.



Problèmes de terminologie



"" — "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