目标:
在Azure IoT边缘查看IoT数据
我想将一个模块部署到我的IoT边缘设备上。因此,为了将MPU6050传感器部署为一个模块,我遇到了以下疑问。如果有人能给我他/她的见解,因为我是Azure的新手,那将是非常有帮助的。
当前职位:
Edge实例已经在Azure门户上创建,只剩下"set模块“部分。我已经将我的Raspberry Pi配置为一个边缘设备,并且可以查看Azure Edge中的列表。在Azure门户上创建了新的注册表。只有我的my 6050-读取图像文件的推送到注册表是剩余的。
怀疑:
-集线器-sdk被配置为读取MPU6050数据-->它是在码头上构建和运行的->本地对接器被推入我已经创建的Azure注册表->该注册表链接被复制并粘贴到边缘设备部署->边缘实例链接到我的物理边缘设备->所以当边缘函数运行时,我可以看到本地连接的边缘设备上的整个传感器数据,该设备没有互联网连接。
我对上述任何问题的任何帮助或建议都将不胜感激。
谢谢!干杯!
发布于 2019-02-04 13:47:47
有关于如何为IoT边缘:https://learn.microsoft.com/en-us/azure/iot-edge/tutorial-python-module创建基于Python的模块的教程
正如本教程所建议的,我建议使用和IoT边缘扩展。然后获得Python模块模板、Dockerfile等。您可以直接从VS代码将您的自定义模块推入您的私有容器注册表,例如Azure容器注册表,还可以设置您的部署清单(哪个模块在哪个边缘设备上运行)。
按照注释中的要求,我构建了一个快速完整的示例(虽然没有进行测试)。当使用VS代码IoT边缘扩展创建新的Python模块时,该示例只是基于模板示例
import random
import time
import sys
import iothub_client
# pylint: disable=E0611
from iothub_client import IoTHubModuleClient, IoTHubClientError, IoTHubTransportProvider
from iothub_client import IoTHubMessage, IoTHubMessageDispositionResult, IoTHubError
# messageTimeout - the maximum time in milliseconds until a message times out.
# The timeout period starts at IoTHubModuleClient.send_event_async.
# By default, messages do not expire.
MESSAGE_TIMEOUT = 10000
# global counters
RECEIVE_CALLBACKS = 0
SEND_CALLBACKS = 0
# Choose HTTP, AMQP or MQTT as transport protocol. Currently only MQTT is supported.
PROTOCOL = IoTHubTransportProvider.MQTT
# Callback received when the message that we're forwarding is processed.
def send_confirmation_callback(message, result, user_context):
global SEND_CALLBACKS
print ( "Confirmation[%d] received for message with result = %s" % (user_context, result) )
map_properties = message.properties()
key_value_pair = map_properties.get_internals()
print ( " Properties: %s" % key_value_pair )
SEND_CALLBACKS += 1
print ( " Total calls confirmed: %d" % SEND_CALLBACKS )
class HubManager(object):
def __init__(
self,
protocol=IoTHubTransportProvider.MQTT):
self.client_protocol = protocol
self.client = IoTHubModuleClient()
self.client.create_from_environment(protocol)
# set the time until a message times out
self.client.set_option("messageTimeout", MESSAGE_TIMEOUT)
# Forwards the message received onto the next stage in the process.
def forward_event_to_output(self, outputQueueName, event, send_context):
self.client.send_event_async(
outputQueueName, event, send_confirmation_callback, send_context)
def main(protocol):
try:
print ( "\nPython %s\n" % sys.version )
print ( "IoT Hub Client for Python" )
hub_manager = HubManager(protocol)
print ( "Starting the IoT Hub Python sample using protocol %s..." % hub_manager.client_protocol )
print ( "The sample is now waiting for messages and will indefinitely. Press Ctrl-C to exit. ")
while True:
# Build the message with simulated telemetry values.
# Put your real sensor reading logic here instead
temperature = TEMPERATURE + (random.random() * 15)
humidity = HUMIDITY + (random.random() * 20)
msg_txt_formatted = MSG_TXT % (temperature, humidity)
message = IoTHubMessage(msg_txt_formatted)
hubManager.forward_event_to_output("output1", message, 0)
time.sleep(10)
except IoTHubError as iothub_error:
print ( "Unexpected error %s from IoTHub" % iothub_error )
return
except KeyboardInterrupt:
print ( "IoTHubModuleClient sample stopped" )
if __name__ == '__main__':
main(PROTOCOL)https://stackoverflow.com/questions/54515767
复制相似问题