我有一个 Raspberry Pi 3 A+,并且我将 Raspberry Pi OS 32 位下载到我的硬件上。我已按照以下说明安装了 IoT Edge:Create and provision an IoT Edge device on Linux using symmetric keys.连接到 IoT 中心并运行 IoT 代理和 IoT 边缘模块工作正常。当我尝试推送额外的模块时,问题就出现了。
我尝试遵循这些Tutorial: Develop IoT Edge modules with Linux containers部署 IoT Edge 模块。当我将其部署到虚拟机(Linux ubuntu 20.04 x64)时,它工作正常。但当我尝试对我的 Raspberry 进行相同的部署时,它不起作用。
如果您不熟悉说明;这是在 VS Code 中创建*Azure IoT Edge:新 IoT Edge 解决方案时创建的模板代码。我唯一添加的基本上就是名称“temperatureTest”。其余的代码是为我生成的。正如我所提到的,它适用于 (Linux ubuntu 20.04 x64) VM。但当我把它推到我的树莓派上时它不起作用。 (在部署我的配置文件之前,我确实将“设置边缘解决方案的默认目标平台”交换为arm32v7)。
{
"$schema-template": "4.0.0",
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.1",
"runtime": {
"type": "docker",
"settings": {
"minDockerVersion": "v1.25",
"loggingOptions": "",
"registryCredentials": {
"****": {
"username": "$CONTAINER_REGISTRY_USERNAME_****",
"password": "$CONTAINER_REGISTRY_PASSWORD_****",
"address": "****.azurecr.io"
}
}
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-agent:1.4",
"createOptions": {}
}
},
"edgeHub": {
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.4",
"createOptions": {
"HostConfig": {
"PortBindings": {
"5671/tcp": [
{
"HostPort": "5671"
}
],
"8883/tcp": [
{
"HostPort": "8883"
}
],
"443/tcp": [
{
"HostPort": "443"
}
]
}
}
}
}
}
},
"modules": {
"temperatureTest": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "${MODULES.temperatureTest}",
"createOptions": {}
}
},
"SimulatedTemperatureSensor": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.4",
"createOptions": {}
}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.1",
"routes": {
"temperatureTestToIoTHub": "FROM /messages/modules/temperatureTest/outputs/* INTO $upstream",
"sensorTotemperatureTest": "FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/temperatureTest/inputs/input1\")"
},
"storeAndForwardConfiguration": {
"timeToLiveSecs": 7200
}
}
}
}
}
在我的树莓派上运行命令iotedge logs tempTest会给出以下输出:
IoT Hub Client for Python
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/adapters.py", line 41, in connect
sock.connect(socket_path)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 499, in send
timeout=timeout,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 788, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 76 9, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/adapters.py", line 41, in connect
sock.connect(socket_path)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError (111, 'Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./main.py", line 79, in <module>
main()
File "./main.py", line 55, in main
client = create_client()
File "./main.py", line 17, in create_client
client = IoTHubModuleClient.create_from_edge_environment()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/aio/patch_docume ntation.py", line 224, in create_from_edge_environment
return super(IoTHubModuleClient_, cls).create_from_edge_environment(**kwargs )
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/abstract_ clients.py", line 688, in create_from_edge_environment
server_verification_cert = hsm.get_certificate()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/edge_hsm. py", line 65, in get_certificate
headers={"User-Agent": urllib.parse.quote_plus(user_agent.get_iothub_user_ag ent())},
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/__init__.py", line 51, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/__init__.py", line 46, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 547, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedEr ror(111, 'Connection refused'))
IoT Hub Client for Python
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/adapters.py", line 41, in connect
sock.connect(socket_path)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 499, in send
timeout=timeout,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 788, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 76 9, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packaib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/adapters.py", line 41, in connect
sock.connect(socket_path)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError (111, 'Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./main.py", line 79, in <module>
main()
File "./main.py", line 55, in main
client = create_client()
File "./main.py", line 17, in create_client
client = IoTHubModuleClient.create_from_edge_environment()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/aio/patch_docume ntation.py", line 224, in create_from_edge_environment
return super(IoTHubModuleClient_, cls).create_from_edge_environment(**kwargs )
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/abstract_ clients.py", line 688, in create_from_edge_environment
server_verification_cert = hsm.get_certificate()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/edge_hsm. py", line 65, in get_certificate
headers={"User-Agent": urllib.parse.quote_plus(user_agent.get_iothub_user_ag ent())},
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/__init__.py", line 51, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests_unixsocket/__init__.py", line 46, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 547, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedEr ror(111, 'Connection refused'))
IoT Hub Client for Python
Subscribe for input failed. Not enabling feature
./main.py:36: RuntimeWarning: coroutine 'execute_patch_for_async.<locals>.shutdo wn' was never awaited
client.shutdown()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_tran sport.py", line 396, in connect
host=self._hostname, port=8883, keepalive=self._keep_alive
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 914, i n connect
return self.reconnect()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_ address=source)
File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
raise err
File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/aio/async _clients.py", line 33, in handle_result
return await callback.completion()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/async_ada pter.py", line 94, in completion
return await self.future
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/pipeline/ pipeline_stages_mqtt.py", line 193, in _run_op
self.transport.connect(password=password)
任何帮助将不胜感激。
最佳答案
因此,我们需要调查一些事情,因为我们无法离线解决整个问题..
首先,我们必须确保更新我们的物联网设备固件!
更新 Raspberry Pi 的固件:sudo rpi-update
尝试部署开箱即用的 TemperatureSensor模块provided by Microsoft ,这可能是您的 RaspberryPI 上的一些配置问题,此示例模块部署将确保模块代码和连接问题中没有错误。
检查 operating system 的版本:
cat /etc/os-release
检查.NET Core版本:dotnet --version
检查Docker版本:docker --version
Ping 网站以验证互联网连接:
ping www.google.com
使用traceroute诊断网络问题:traceroute www.google.com
这将有助于验证连接。检查 Azure IoT Edge runtime logs :
sudo iotedge logs
检查特定模块的日志:sudo iotedge logs <module-name>
始终执行此操作以获取初始日志以进行故障排除!这是我最喜欢的一步! 检查所有模块的状态:
sudo iotedge list
检查特定模块的状态:sudo iotedge list <module-name>
重新启动 Azure IoT Edge 运行时:
sudo systemctl restart iotedge
重启特定模块:sudo iotedge restart <module-name>
** 在某些情况下,我发现使用正确的镜像重新镜像 Raspberry pi 可能有助于解决许多隐藏的问题,并且无法通过常规故障排除步骤和文档进行追踪。
关于azure - 物联网边缘 : SimulatedTemperatureSensor not working on my Raspberry 3 A+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75566650/