更多内容,关注公众号:

树莓派是很多动手达人必备的小玩具,本节内容,让我们拿出树莓派,在30分钟内,将树莓派连接到微软云Azure的IoT Hub,然后将温湿度曲线可视化。
(本节内容完整视频在文章末尾。)

本节内容中,树莓派发送的数据是模拟出来的,并没有真实的连接到传感器,您可以选购不同的传感器来采集真实的环境信息。

Azure IoT Hub 为我们提供了设备与云双向通讯的能力,通过多种语言的SDK,我们能轻松快速的将树莓派接入到云。本案例使用微软官方代码,示例代码一共约70行,非常简单。

关于IoT Hub的更多内容,请参考:

https://mp.weixin.qq.com/s?__biz=Mzg2OTEyNzMzOQ==&mid=2247483659&idx=1&sn=68cdff986d7dcc9b6233e48ba820300c&chksm=cea084cff9d70dd9898cbec3b2fe3e06175f7288acd244af9cc6f1b5fe0e5aa0fc946da585ad&scene=21#wechat_redirect

时序见解(Azure Time Series Insights)用来存储时间序列的值,同时提供UI,将数据可视化。

关于时序见解的更多内容,请参考:

https://mp.weixin.qq.com/s?__biz=Mzg2OTEyNzMzOQ==&mid=2247483703&idx=1&sn=a6ca6b60e5bd11359a3684e222fb2716&chksm=cea084f3f9d70de51626da3ca4816ae6510bc8c9418c3365184ce4936b3e7b708a3306ab982c&scene=21#wechat_redirect

时序见解和IoT Hub可以无缝连接,无需写代码即可将上传到IoT Hub的数据进行可视化。

树莓派上传数据的代码:

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 string}" # Define the JSON message to send to IoT Hub.
TEMPERATURE = 20.0
HUMIDITY = 60
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/quickstart-send-telemetry-python

树莓派系统下载:

https://www.raspberrypi.org/downloads/

Micro SD卡格式化工具:

https://www.sdcard.org/downloads/index.html

树莓派系统写入Micro SD卡工具:

https://sourceforge.net/projects/win32diskimager/

完整实战视频如下:

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

30分钟连接树莓派到微软云 Azure IoT Hub,并将数据进行可视化的更多相关文章

  1. 微软云 azure 数据迁移之oracle11g dataguard

    背景,将本地的oracle数据迁移到微软云azure云上面的oracleserver. 1.复制本地的rman备份集到微软云azure的oracleserver上 scp -r -P56922 201 ...

  2. 微软云Azure Website 远程调试

    微软云Azure Website 远程调试 是可以的 但是只有48小时,要在后台开启,所以还是很麻烦的啊! 但是安全性提高了,不得不承认哦

  3. 本号讯 | 永不消失的协作“空间站”开课;微软推出微软云Azure文档网站

    8月29日,针对企业常面临的“协同办公”困难,开展以“还有这种操作?永不消失的协作'空间站'”为主题的协同办公培训课. 课程内容包含:在Office 365环境中,如何利用Teams与Groups等功 ...

  4. 【物联网云端对接-1】 通过HTTP协议与微软Azure IoT hub进行云端通信

    在2015年曾写过一篇文章<从微软build 2015,展望微软未来发展>,提到了微软的Azure和Windows 10 IoT,那算是初次接触微软物联网技术.比较幸运的是在后续的时间里, ...

  5. 【物联网云端对接-3】通过MQTT协议与微软Azure IoT Hub进行云端通信

    在上一篇文章<通过MQTT协议与阿里云物联网套件进行云端通信>中,我们介绍了通过MQTT对接阿里云的物联网套件.其实同样的代码,稍加调整也可以对接到微软Azure IoT hub上,不过需 ...

  6. Azure IoT Hub 十分钟入门系列 (3)- 使用消息路由将原始设备数据记录存档

    本文主要分享一个案例: 10分钟使用消息路由将原始设备数据记录存档 B站视频讲解:https://www.bilibili.com/video/av90223893/ 本文主要有如下内容: 1.理解什 ...

  7. Azure IoT Hub 十分钟入门系列 (1)- 10分钟带你了解Azure IoT Hub 并创建IoT Hub

    建议您先对<Azure 上 IoT 整体解决方案概览 >进行了解. 本文主要分享一个案例: 10分钟-了解Azure IoT Hub并创建Azure IoT Hub 本文主要有如下内容: ...

  8. Azure IoT Hub 十分钟入门系列 (4)- 实现从设备上传日志文件/图片到 Azure Storage

    本文主要分享一个案例: 10分钟内通过Device SDK上传文件到IoTHub B站视频:https://www.bilibili.com/video/av90224073/ 本文主要有如下内容: ...

  9. Azure IoT 技术研究系列2-起步示例之设备注册到Azure IoT Hub

    上篇博文中,我们主要介绍了Azure IoT Hub的基本概念.架构.特性: Azure IoT 技术研究系列1-入门篇 本文中,我们继续深入研究,做一个起步示例程序:模拟设备注册到Azure IoT ...

随机推荐

  1. http://t.cn/xxxxx的短链接如何生成?

    var convertStr = encodeURIComponent(urlStr); //转换的原链接可能存在"&"这样的特殊符号,导致原链接的某些字段会被当做ajax ...

  2. PyCharm 2019.3激活破解教程(永久)

    2019.12.02 jetbrains公司发布了Python的最强编辑器PyCharm 2019.3版本.本次大版本主要对Jupyter notebooks .MongoDB.Python3.8功能 ...

  3. JGit----将 Git 嵌入你的应用

    如果你想在一个 Java 程序中使用 Git ,有一个功能齐全的 Git 库,那就是 JGit . JGit 是一个用 Java 写成的功能相对健全的 Git 的实现,它在 Java 社区中被广泛使用 ...

  4. 使用node.js将xmind导出的excel转换为json树

    xmind文件如图所示, 最终生成的数据结构如图  2,选择导出为excel文件,导出的excel文件打开如图 3,安装node读取excel模块 cnpm i  node-xlsx --save 4 ...

  5. Pyhton表白代码——浪漫圣诞节

    圣诞节即将到了,所以这回通过turtle模块来编写一个表白的小程序 开发时间:2019-12-15 开发工具:Sublime 开发模块:turtle 这里用到了turtle库的相关知识,如果不熟悉可以 ...

  6. 最全的防火墙(firewalld)

    第1章  防火墙的介绍 1.1  防火墙的介绍 1.1.1 概念 动态管理防火墙服务(图形界面和linux界面都可以实现) 支持不同防火墙的区域信息 属于传输层次的防火墙 1.1.2 防火墙的默认规则 ...

  7. ARTS-S python把非汉语和非字母的字符替换成空格

    # coding: utf-8 import re text = "aa[bb,aa#cWc中a国" FILTER_PUNTS = re.compile("[^\u4E0 ...

  8. Python流程控制之分支结构

    目录 if/else结构 多重if结构 嵌套if结构 练习 if/else结构 if如果,else否则 # java if(){ }else{ } # python if 条件: 语句 else: 语 ...

  9. Vue如何实现数据响应的

    参考博客:https://medium.com/vue-mastery/the-best-explanation-of-javascript-reactivity-fea6112dd80d 翻译博客: ...

  10. 201871010119-帖佼佼《面向对象程序设计(java)》第7周学习总结

    博文正文开头格式:(2分) 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.co ...