设备数据通过Azure Functions 推送到 Power BI 数据大屏进行展示(1准备工作)
admin
2023-03-28 02:01:24
0

设备数据通过Azure Functions 推送到 Power BI 数据大屏进行展示(1准备工作)

本案例适用于开发者入门理解Azure Functions/ IoT Hub / Service Bus / Power BI等几款产品。


设备数据通过Azure Functions 推送到 Power BI 数据大屏进行展示(1准备工作)

主要实战的内容为:


  1. 将设备遥测数据上传到物联网中心,

  2. 将遥测数据路由到消息中间件的Topic中,

  3. 使用Azure Function解析消息中间件Topic中的消息并推送到大屏 。


本文主要是本案例的准备工作,即(第1条和第2条的内容):


1.创建IoT Hub:

https://v.qq.com/x/page/h4031pnaxi8.html


2.创建Service Bus:

https://v.qq.com/x/page/b3031hdv9yk.html


3. 创建IoT Hub 消息路由,将遥测消息路由到Service Bus Topic

https://v.qq.com/x/page/i3031hkec4q.html



本示例中的Python Device 代码来自于微软官网,请参照:

https://docs.azure.cn/zh-cn/iot-hub/quickstart-send-telemetry-python

# Copyright (c) Microsoft. All rights reserved.# Licensed under the MIT license. See LICENSE file in the project root for full license information.import randomimport timeimport sys# Using the Python Device SDK for IoT Hub:#   https://github.com/Azure/azure-iot-sdk-python# The sample connects to a device-specific MQTT endpoint on your IoT Hub.import iothub_client# pylint: disable=E0611from iothub_client import IoTHubClient, IoTHubClientError, IoTHubTransportProvider, IoTHubClientResultfrom iothub_client import IoTHubMessage, IoTHubMessageDispositionResult, IoTHubError, DeviceMethodReturnValue# The device connection string to authenticate the device with your IoT hub.# Using the Azure CLI:# az iot hub device-identity show-connection-string --hub-name {YourIoTHubName} --device-id MyNodeDevice --output tableCONNECTION_STRING = "your device conn string"# Using the MQTT protocol.PROTOCOL = IoTHubTransportProvider.MQTTMESSAGE_TIMEOUT = 10000# Define the JSON message to send to IoT Hub.TEMPERATURE = 20.0HUMIDITY = 60MSG_TXT = "{\"temperature\": %.2f,\"humidity\": %.2f}"def send_confirmation_callback(message, result, user_context):    print ( "IoT Hub responded to message with status: %s" % (result) )def iothub_client_init():    # Create an IoT Hub client    client = IoTHubClient(CONNECTION_STRING, PROTOCOL)    return clientdef iothub_client_telemetry_sample_run():    try:        client = iothub_client_init()        print ( "IoT Hub device sending periodic messages, press Ctrl-C to exit" )        while True:            # Build the message with simulated telemetry values.            temperature = TEMPERATURE + (random.random() * 15)            humidity = HUMIDITY + (random.random() * 20)            msg_txt_formatted = MSG_TXT % (temperature, humidity)            message = IoTHubMessage(msg_txt_formatted)            # Add a custom application property to the message.            # An IoT hub can filter on these properties without access to the message body.            prop_map = message.properties()            if temperature > 30:              prop_map.add("temperatureAlert", "true")            else:              prop_map.add("temperatureAlert", "false")            # Send the message.            print( "Sending message: %s" % message.get_string() )            client.send_event_async(message, send_confirmation_callback, None)            time.sleep(3)    except IoTHubError as iothub_error:        print ( "Unexpected error %s from IoTHub" % iothub_error )        return    except KeyboardInterrupt:        print ( "IoTHubClient sample stopped" )if __name__ == '__main__':    print ( "IoT Hub Quickstart #1 - Simulated device" )    print ( "Press Ctrl-C to exit" )    iothub_client_telemetry_sample_run()


设备数据通过Azure Functions 推送到 Power BI 数据大屏进行展示(1准备工作)



相关内容

热门资讯

特朗普下令不打了,美国的“余粮... 可以说戛然而止,快得让很多人都无法适应。前两周,每一天美国都要打击伊朗一通。就在7月24日白宫会议前...
穆杰塔巴最新表态:支持黎真主党 △伊朗最高领袖穆杰塔巴·哈梅内伊(资料图)当地时间7月26日晚,伊朗最高领袖穆杰塔巴·哈梅内伊对黎巴...
美军瘫痪一艘驶向伊朗的油轮,特... 美国总统特朗普虽下令暂停打击伊朗,但美军仍在执行对霍尔木兹海峡的封锁任务。针对美军瘫痪一艘驶向伊朗油...
“小牌大耍”的底气到底是哪里来... 澎湃首席评论员 李平这两天,“艺人李权哲乘高铁占座事件”在网上引发热议,该艺人参加的活动主办方曾发布...
越南籍船舶南海遇险沉没,中方已... 据凤凰卫视报道,一艘越南船舶7月24日夜间在越南庆和以东220海里附近遇险沉没,船上共62名越南籍人...
李权哲占座、蒙面、装死:娱乐圈... 你买了一张高铁一等座的票,找到自己的位置,18A。有人坐着。你拿出手机看了眼购票记录——没错,18A...
杭州景区咖啡店闯入1条幼蛇,仅... 夏天气温高、湿度大,蛇类活动进入高峰期,千万别被“小蛇无害”的刻板印象骗了!有些幼蛇看着迷你可爱,实...
AI开源公开信签署企业增至50... IT之家 7 月 26 日消息,英伟达、微软、IBM、Meta 等 25 家美国科技企业本周(7 月...
南阳快手短视频代运营企业的服务... 在短视频平台快速发展的背景下,企业通过快手等渠道进行内容运营已成为常见的市场动作。对于希望借助短视频...
普通人该如何跟上科技发展的步伐 这个被称作科技的词汇, 听起来既有宏大之感, 又颇为遥远, 好似仅仅归属于在实验室里专心致志钻研的科...