一. 时序数据库的基本概念:
2.实战Azure Time Series Insights
创建IoT Hub;
创建时序见解
从IoT Hub接收据;
在UI上查询数据;
3. 通过API 调用时序数据
案例中用到的Python模拟器代码:
可参考官网教程:https://docs.azure.cn/zh-cn/iot-hub/quickstart-send-telemetry-python
import random
import time
# 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.
from azure.iot.device import IoTHubDeviceClient, Message
# 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 table
CONNECTION_STRING = "your device conn string"
# Define the JSON message to send to IoT Hub.
TEMPERATURE = 120.0
HUMIDITY = 160
MSG_TXT = '{{"temperature": {temperature},"humidity": {humidity}}}'
def iothub_client_init():
# Create an IoT Hub client
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
return client
def 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.format(temperature=temperature, humidity=humidity)
message = Message(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.
if temperature > 30:
message.custom_properties["temperatureAlert"] = "true"
else:
message.custom_properties["temperatureAlert"] = "false"
# Send the message.
print( "Sending message: {}".format(message) )
client.send_message(message)
print ( "Message successfully sent" )
time.sleep(1)
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()
相关产品的链接:
IoT Hub:https://docs.azure.cn/zh-cn/iot-hub/
时序见解:https://www.azure.cn/zh-cn/home/features/time-series-insights/
视频中PPT 如下:
获取Token的API调用: