e-RT3 플러스에서 Azure IoT hub로 원격 측정 데이터 전송
다음은 본 강좌의 몇 가지 기본적인 선결 조건-
Azure Portal 사물인터넷 센터 창설.
Azure Cloud Shell 디바이스를 생성하고 디바이스에서 연결 문자열을 가져옵니다.
Visual Studio Code에서
Python 스크립트를 작성하여 원격 측정 데이터를 발송합니다.Azure IoT explorer은 수신된 데이터를 검증합니다.
카탈로그
본 강좌에서 우리는 다음과 같은 내용을 소개할 것이다-
Azure IoT 센터 구성
이 섹션에서는 Azure Portal에 IoT 센터를 구성하는 방법에 대해 설명합니다.이 절은 두 부분으로 나뉜다-
사물인터넷 센터를 창설하다.
Azure portal에 IoT 센터를 만들려면 다음 단계를 따라야 합니다.

Note: If your web browser does not look like the same as mentioned here, then please consider to refer the official documentation provided by Microsoft.
IoT Hub resource을 만듭니다.사물인터넷 센터를 만들려면 + 자원 만들기 단추를 선택하십시오.
이 버튼을 클릭하면 Azure marketplace로 이동합니다.

검색 상자에
IoT hub을 입력하고 드롭다운 옵션에서 IoT Hub을 선택합니다.
목록에서
IoT Hub을 선택하면 중심 페이지로 이동합니다.탐색에 성공하면 만들기 버튼을 클릭합니다.
IoT Hub 양식을 작성하세요.
기본 탭에서는 Azure에서 제공하는 양식을 작성해야 합니다.
심사가 끝난 후 '창설' 단추를 누르면 센터를 만들 수 있습니다. (시간이 좀 걸릴 수도 있습니다.)
사물인터넷 센터에 설비를 등록하다
IoT 허브에 장치를 등록하려면 다음 절차를 따르십시오.
azure-iot인지 확인하려면 다음 명령을 사용하십시오.az extension list
az extension add --name azure-iot
az iot hub device-identity create --hub-name YOUR_HUB_NAME --device-id YOUR_DEVICE_ID
az iot hub device-identity connection-string show --hub-name YOUR_HUB_NAME --device-id YOUR_DEVICE_ID --output table
Note: To create the device instance into Azure IoT Hub we are using Azure Cloud Shell. Without accessing the
Azure Cloud Shell, you might lose your connect string. It's always a good idea to take a backup of your connection string into somewhere else like a temporary file.
python으로 아날로그 원격 측정 데이터 보내기
원격 측정 데이터를 보내기 위해서 우리는
azure-iot 스크립트를 사용합니다.이 단계에서는 e-RT3 Plus 디바이스에 Python 및 pip3이 설치되어 있는지 확인합니다.venv은 기본적으로 e-RT3 Plus OS과 함께 제공됩니다.e-RT3 Plus OS 파일은 파트너 포털의 등록 구성원만 액세스할 수 있습니다.이전에python 가상 모듈(venv)이 설치되지 않았다면 다음 절차를 통해 설치할 수 있습니다 -
SUDO 사용자 활성화
When you are working as a normal user and you want to use commands that require root privileges, you usually add
sudoto the beginning, but you may be rejected as follows -# Working with the General User username $sudo apt update [sudo] password for username: # Enter Password username is not in the sudoers file. This incident will be > reported.If that is the case, you could resolve it by using the following steps -
Since the configuration is done as root, switch to the root user with the
sucommand once.$su Password: # Enter root password root @ ubuntu:/home/username #Edit the configuration file with the
visudocommand -visudoAdd the following lines at the end of the configuration file and save it -
Replace username with your username.username ALL = (ALL) ALL # replace username with your usernameLog out of root and see if the sudo command works -
root @ ubuntu:/home/username # exit exit username @ ubuntu: ~ $sudo apt update [sudo] password for username: # Enter Password Get: 1 http://ports.ubuntu.com/ubuntu-ports bionic InRelease [242 kB] ... username @ ubuntu: ~ $If you have configured your ert3 user with
sudopermissions, then you may try to use the following commands to install the same -sudo apt update sudo apt install python3-venvOnce the installation is completed you are ready to create a virtual python environment. If you need Proxy settings, please visit the supplementary section.
python 가상 환경 만들기
python virtual environment을 만들려면 먼저 원하는 폴더 위치 (작업 영역) 를 찾아야 합니다.네비게이션이 끝난 후python 가상 환경을 만들기 위해 아래 명령을 실행하십시오 -
python3 -m venv YOUR_ENV_NAME
가상 환경을 만든 후 다음 명령을 사용하여 활성화할 수 있습니다.source YOUR_ENV_NAME/bin/activate
활성화 완료 후, 당신의 pip3은 아래와 같습니다 -(YOUR_ENV_NAME)username@ubuntu: ~ $
가상 환경을 활성화하면 원격 측정 데이터를 보내려면python 스크립트를 만들어야 할 수도 있습니다.python 스크립트를 만들려면 다음 명령을 실행하십시오 -touch YOUR_FILE_NAME.py
파이썬 코드로 아날로그 데이터 보내기
"e-RT3 Plus"에 방문하여python 스크립트를 실행할 수 있다면 Azure IoT Hub에 아날로그 데이터를 보낼 수 있습니다.
터미널 창에서 필요한 경우 다음 명령을 실행하여 azure-iot-device을 설치합니다.
pip3 install azure-iot-device
설치가 완료되면 생성된 파일에 코드를 쓰기 시작합니다. from azure.iot.device import IoTHubDeviceClient, Message
terminal을 저장할 변수를 선언합니다(Register a device in the IoT hub의 5단계 참조). CONNECTION_STRING = YOUR_CONNECTION_STRING
# Method to initialize the iot hub client instance
def iothub_client_init():
# Create an IoT Hub client
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
# return the client instance
return client
def iothub_client_telemetry_sample_run():
# crete a client instance
client = iothub_client_init()
# create a Message to send to the IoT Hub
message = Message("YOUR_TELEMETRY_DATA_AS_STRING")
# Send the message to IoT hub
client.send_message(message)
device connection string을 호출하여 원격 측정 데이터를 발송한다. 아래와 같다- if __name__ == '__main__':
iothub_client_telemetry_sample_run()
import random
import time
# Import azure IoT hub client and Message from `azure-iot-device`
from azure.iot.device import IoTHubDeviceClient, Message
# Your connection string of the IoT Device
CONNECTION_STRING="YOUR_CONNECT_STRING"
# Initializing the iot hub client instance
def iothub_client_init():
# Create an IoT Hub client with connection string
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
# returning the client
return client
def iothub_client_telemetry_sample_run():
try:
# crete a client instance
client = iothub_client_init()
print ( "IoT Hub device sending messages, press Ctrl+C to exit" )
while True:
# create a Message to send to the IoT Hub
message = Message("YOUR_TELEMETRY_DATA_AS_STRING")
# Create a custom property with the Message payload
message.custom_properties["myCustomProp"] = (random.random() * 15)
# Send the message to IoT hub
print( "Sending message: ")
#print data and both system and application (custom) properties
for property in vars(message).items():
if all(property):
print(" {0}".format(property))
client.send_message(message)
print ( "Message successfully sent" )
time.sleep(10)
except KeyboardInterrupt:
print ( "IoTHubClient sample stopped" )
if __name__ == '__main__':
iothub_client_telemetry_sample_run()
참고 에이전트가 원격 측정 데이터를 azure CAN으로 보내야 할 수도 있습니다.이 경우 iothub_client_telemetry_sample_run 함수를 다음 코드로 바꾸십시오 - from azure.iot.device import ProxyOptions
import socks
def iothub_client_init():
proxy_opts = ProxyOptions(
proxy_type=socks.HTTP,
proxy_addr="YOUR_PROXY_ADDRESS",
proxy_port=YOUR_PROXY_PORT,
proxy_username="YOUR_PROXY_USERNAME",
proxy_password="YOUR_PROXY_PASSWORD"
)
# Create an IoT Hub client with connection string
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING, websockets=True, proxy_options=proxy_opts)
# returning the client
return client
python3 YOUR_FILE_NAME.py
(YOUR_ENV_NAME) username@ubuntu:~/workspace$ python3 YOUR_FILE_NAME.py
IoT Hub device sending messages, press Ctrl+C to exit
Sending message:
('data', 'YOUR_TELEMETRY_DATA_AS_STRING')
('custom_properties', {'myCustomProp': 13.066109804837703})
Message successfully sent
Sending message:
('data', 'YOUR_TELEMETRY_DATA_AS_STRING')
('custom_properties', {'myCustomProp': 11.664970897921908})
Message successfully sent
사물인터넷 센터에서 원격 측정 데이터를 읽다
원격 측정 데이터가 Azure IoT 센터로 성공적으로 업데이트되면 azure-iot-explorer을 사용하여 유효성을 검사할 수 있습니다.마이크로소프트는 이미 이 소프트웨어에 관한 좋은 문서를 제공하였으니, this link을 클릭하여 그것에 대한 정보를 더 많이 읽으십시오.
IoT 허브가 설치되어 연결되면 원격 탐지 탭을 클릭하고 시작 버튼을 클릭하여 원격 탐지 데이터를 읽습니다.

보충적
프록시 설정
개인적으로 가장 어려운 것 중 하나는
iothub_client_init()을 설정하는 것입니다. 그리고 이것은 환경에 따라 다르다고 생각합니다.여기서 이 e-RT3 플러스 설비에 대한 설정을 말씀드리겠습니다. export HTTP_PROXY=USERNAME:[email protected]:port
export HTTPS_PROXY=USERNAME:[email protected]:port
export NO_PROXY=localhost,127.0.0.1,*.my.lan.domain
프록시 설정이 있는 경우 환경 변수를 상속하고 실행할 Proxy 옵션을 추가합니다.# apt command example
sudo -E apt update
완료되면 다음 명령을 사용하여 환경 변수를 삭제합니다 -unset HTTP_PROXY HTTPS_PROXY NO_PROXY
결론
이것은 원격 측정 데이터를 업로드하는 데 사용되는 엔트리급python 스크립트로, e-RT3 Plus와 Azure IoT hub을 미리 알아야 할 수도 있습니다.
참고 문헌
1. Azure Tutorial
2. Azure IoT Explorer
3. Python Virtual Environments and Packages
4. Azure SDK for Python
Reference
이 문제에 관하여(e-RT3 플러스에서 Azure IoT hub로 원격 측정 데이터 전송), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/yokogawa-yts_india/send-telemetry-data-from-e-rt3-plus-to-azure-iot-hub-41i텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)