树莓派 - MQTT
安装mosquitto
下载源代码包
wget http://mosquitto.org/files/source/mosquitto-1.5.tar.gz
解压
tar zxfv mosquitto-1.5.tar.gz
进入目录
cd mosquitto-1.5
编译
make
安装
sudo make install
安装问题
handle_connect.c:33:25: fatal error: uuid/uuid.h: No such file or directory
# include <uuid/uuid.h>
解决:
pi@raspberrypi:~/mosquitto-1.5 $ sudo apt-get install uuid-dev
找不到openssl/ssl.h
解决:sudo apt-get install libssl-dev
error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
解决:
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
sudo ldconfig
在linux 虚拟机上也安装mosquitto, sudo apt install mosquitto
测试
在raspberryPi上运行mosquitto -v
pi@raspberrypi:~ $ mosquitto -v
1533737054: mosquitto version 1.5 starting
1533737054: Using default config.
1533737054: Opening ipv4 listen socket on port 1883.
1533737054: Opening ipv6 listen socket on port 1883.
1533737096: New connection from 192.168.0.197 on port 1883.
1533737096: New client connected from 192.168.0.197 as mosqpub|9828-ubuntu (c1, k60).
1533737096: No will message specified.
1533737096: Sending CONNACK to mosqpub|9828-ubuntu (0, 0)
1533737096: Received PUBLISH from mosqpub|9828-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737096: Received DISCONNECT from mosqpub|9828-ubuntu
1533737096: Client mosqpub|9828-ubuntu disconnected.
1533737126: New connection from 192.168.0.197 on port 1883.
1533737126: New client connected from 192.168.0.197 as mosqsub|9829-ubuntu (c1, k60).
1533737126: No will message specified.
1533737126: Sending CONNACK to mosqsub|9829-ubuntu (0, 0)
1533737126: Received SUBSCRIBE from mosqsub|9829-ubuntu
1533737126: gpio (QoS 0)
1533737126: mosqsub|9829-ubuntu 0 gpio
1533737126: Sending SUBACK to mosqsub|9829-ubuntu
1533737170: New connection from 192.168.0.197 on port 1883.
1533737170: New client connected from 192.168.0.197 as mosqpub|9832-ubuntu (c1, k60).
1533737170: No will message specified.
1533737170: Sending CONNACK to mosqpub|9832-ubuntu (0, 0)
1533737170: Received PUBLISH from mosqpub|9832-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737170: Sending PUBLISH to mosqsub|9829-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737170: Received DISCONNECT from mosqpub|9832-ubuntu
1533737170: Client mosqpub|9832-ubuntu disconnected.
1533737186: Received PINGREQ from mosqsub|9829-ubuntu
1533737186: Sending PINGRESP to mosqsub|9829-ubuntu
1533737228: New connection from 192.168.0.197 on port 1883.
1533737228: New client connected from 192.168.0.197 as mosqpub|9835-ubuntu (c1, k60).
1533737228: No will message specified.
1533737228: Sending CONNACK to mosqpub|9835-ubuntu (0, 0)
1533737228: Received PUBLISH from mosqpub|9835-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737228: Sending PUBLISH to mosqsub|9829-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737228: Received DISCONNECT from mosqpub|9835-ubuntu
1533737228: Client mosqpub|9835-ubuntu disconnected.
1533737235: New connection from 192.168.0.197 on port 1883.
1533737235: New client connected from 192.168.0.197 as mosqpub|9836-ubuntu (c1, k60).
1533737235: No will message specified.
1533737235: Sending CONNACK to mosqpub|9836-ubuntu (0, 0)
1533737235: Received PUBLISH from mosqpub|9836-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737235: Sending PUBLISH to mosqsub|9829-ubuntu (d0, q0, r0, m0, 'gpio', ... (20 bytes))
1533737235: Received DISCONNECT from mosqpub|9836-ubuntu
1533737235: Client mosqpub|9836-ubuntu disconnected.
1533737246: Received PINGREQ from mosqsub|9829-ubuntu
1533737246: Sending PINGRESP to mosqsub|9829-ubuntu
在PC机上分别开两个终端运行
mosquitto_sub -v -t gpio -h 192.168.0.135
mosquitto_pub -t gpio -h 192.168.0.135 -m "{\"pin\":17,\"value\":0}"
树莓派的IP地址为192.168.0.135.
发布者发布数据:
~$ mosquitto_pub -t gpio -h 192.168.0.197 -m "{\"pin\":17,\"value\":0}"
~$ mosquitto_pub -t gpio -h 192.168.0.135 -m "{\"pin\":17,\"value\":0}"
~$ mosquitto_pub -t gpio -h 192.168.0.135 -m "{\"pin\":17,\"value\":0}"
订阅者接收到数据:
~$ mosquitto_sub -v -t gpio -h 192.168.0.135
gpio {"pin":17,"value":0}
gpio {"pin":17,"value":0}
gpio {"pin":17,"value":0}
#
Reference
https://github.com/eclipse/mosquitto
https://blog.csdn.net/xukai871105/article/details/39255089
树莓派 - MQTT的更多相关文章
- 树莓派MQTT客户端搭建
树莓派安装和实现MQTT协议 下载Mosquitto 更新软件源:sudo apt-get update 下载g++编译器:sudo apt-get install g++ 安装:sudo apt- ...
- Galileo Gen2 之MQTT通讯
前言 原创文章,转载引用务必注明链接.如有疏漏,欢迎斧正. Galileo系统:完整版Yocto,内核版本3.8.7-yocto-standard:宿主机:Windows 7 64 bit 这期主要讲 ...
- DFRobot万物互联大赛第一轮
前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. DF搞的这个比赛还挺有趣:micro:bit × OBLOQ DF创客社区玩转物联网挑战赛,一边在写文章一边在爱奇艺上看着印度电影 ...
- MQTT学习笔记——Yeelink MQTT维修 采用mqtt.js和paho-mqtt
0 前言 2014年8月yeelink推出基于MQTT协议的开关类型设备控制API.相比于基于HTTP RESTful的轮训方式,通过订阅相关主题消息,能够远程控制类应用实时性更好. 本文使用 ...
- 阿里云物联网平台体验(树莓派+Python篇)
阿里云物联网平台体验(树莓派+Python篇) 虽然对阿里云物联网平台比较熟悉了,从一开始就有幸参与了飞凤平台(Link Develop 一站式开发平台的前身)的一些偏硬件接入的工作.但是同时也见证了 ...
- (3)HomeAssistant 连接MQTT
整体说明 1 自己在阿里云上搭建MQTT服务器 2 自己笔记本电脑windos10搭建HASS,配置参数连接阿里云服务器 3 手机下载MQTT调试助手,当测试端 4手机当终端---阿里云MQTT--- ...
- 云中树莓派(5):利用 AWS IoT Greengrass 进行 IoT 边缘计算
云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...
- 云中树莓派(3):通过 AWS IoT 控制树莓派上的 Led
云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...
- 云中树莓派(2):将传感器数据上传到 AWS IoT 并利用Kibana进行展示
云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 1. 传感器安装及配置 1.1 DHT22 安装 DHT22 是一款温度与湿度传感器,它有3 ...
随机推荐
- bzoj 1982: [Spoj 2021]Moving Pebbles【博弈论】
必败状态是n为偶数并且数量相同的石子堆可以两两配对,因为这样后手可以模仿先手操作 其他状态一定可以由先手给后手一步拼出一个必败状态(用最大堆补) #include<iostream> #i ...
- bzoj 3926: [Zjoi2015]诸神眷顾的幻想乡【SAM】
有一个显然的性质就是每个串一定在某个叶子为根的树中是一条直的链 然后因为SAM里是不会有相同状态的,所以以每个叶子为根dfs一遍,并且动态构造SAM(这里的节点u的last指向父亲),最后统计答案就是 ...
- poj 1733 Parity game【hash+带权并查集】
hash一下然后用带权并查集做模2下的前缀和 #include<iostream> #include<cstdio> #include<map> #include& ...
- rpm -e ** error :No such file or directory 解决
参考文章:http://www.redhat.com/archives/rpm-list/2006-June/msg00025.html 我遇到的情况是这样的: 1 先安装包 rpm -ivh tes ...
- LuoguP2055 [ZJOI2009]假期的宿舍【二分图最大匹配】By cellur925
题目传送门 这道题开始感觉不出是二分图最大匹配的qwq.但是今天学了匈牙利算法,想来做几个题qwq.做这个题的时候想了很久它哪里是二分图,脑子里是“两列,每列有很多点的那种图 qwq.” 然后看了题解 ...
- json2.js 源码解读
这一部分是对Date String Number Boolean扩展toString方法,Date的toString是返回UTC格式的字符串,而后面几个是返回原始值. function f(n) {/ ...
- Ubuntu rar的坑
通过apt-get安装rar后,执行rar命令会有如下坑: rar: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (si ...
- 使用css3 制作switch开关
使用css3来实现switch开关的效果: html代码: <!--switch开关--><div class="switch-btn"> <inpu ...
- 用vue做一个酷炫的menu
写在前面 最近看到一个非常酷炫的menu插件,一直想把它鼓捣成vue形式,谁让我是vue的死灰粉呢,如果这都不算爱
- C#处理Android Audio and Video
Video Converter for .NET (C#) FFMpeg wrapper http://www.nrecosite.com/video_converter_net.aspx Docum ...