In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This case study is for developers to get started understanding several products such as Azure Functions/ IoT Hub / Service Bus / Power BI.
The main contents of actual combat are:
Upload device telemetry data to the IoT hub,
Routing telemetry data into Topic of messaging middleware
Use Azure Function to parse messages in Topic and push them to the big screen.
This article is mainly the preparatory work of this case, namely (the content of articles 1 and 2):
1. Creating an IoT Hub:
https://v.qq.com/x/page/h4031pnaxi8.html
2. Creating a Service Bus:
https://v.qq.com/x/page/b3031hdv9yk.html
3. Create IoT Hub message routing to route telemetry messages to Service Bus Topic
https://v.qq.com/x/page/i3031hkec4q.html
The Python Device code in this example comes from Microsoft's official website. Please refer to:
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()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.