安装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的更多相关文章

  1. 树莓派MQTT客户端搭建

    树莓派安装和实现MQTT协议 下载Mosquitto 更新软件源:sudo apt-get  update 下载g++编译器:sudo apt-get install g++ 安装:sudo apt- ...

  2. Galileo Gen2 之MQTT通讯

    前言 原创文章,转载引用务必注明链接.如有疏漏,欢迎斧正. Galileo系统:完整版Yocto,内核版本3.8.7-yocto-standard:宿主机:Windows 7 64 bit 这期主要讲 ...

  3. DFRobot万物互联大赛第一轮

    前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. DF搞的这个比赛还挺有趣:micro:bit × OBLOQ DF创客社区玩转物联网挑战赛,一边在写文章一边在爱奇艺上看着印度电影 ...

  4. MQTT学习笔记——Yeelink MQTT维修 采用mqtt.js和paho-mqtt

    0 前言     2014年8月yeelink推出基于MQTT协议的开关类型设备控制API.相比于基于HTTP RESTful的轮训方式,通过订阅相关主题消息,能够远程控制类应用实时性更好. 本文使用 ...

  5. 阿里云物联网平台体验(树莓派+Python篇)

    阿里云物联网平台体验(树莓派+Python篇) 虽然对阿里云物联网平台比较熟悉了,从一开始就有幸参与了飞凤平台(Link Develop 一站式开发平台的前身)的一些偏硬件接入的工作.但是同时也见证了 ...

  6. (3)HomeAssistant 连接MQTT

    整体说明 1 自己在阿里云上搭建MQTT服务器 2 自己笔记本电脑windos10搭建HASS,配置参数连接阿里云服务器 3 手机下载MQTT调试助手,当测试端 4手机当终端---阿里云MQTT--- ...

  7. 云中树莓派(5):利用 AWS IoT Greengrass 进行 IoT 边缘计算

    云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...

  8. 云中树莓派(3):通过 AWS IoT 控制树莓派上的 Led

    云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...

  9. 云中树莓派(2):将传感器数据上传到 AWS IoT 并利用Kibana进行展示

    云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 1. 传感器安装及配置 1.1 DHT22 安装 DHT22 是一款温度与湿度传感器,它有3 ...

随机推荐

  1. (二)SpringBoot整合常用框架Druid连接池

    一,在Pom.xml文件加入依赖 找到<dependencies></dependencies>标签,在标签中添加Druid依赖 <dependency> < ...

  2. display:table / display:table-cell 用法

    display:table  元素会作为块级表格来显示(类似table):表格前后带有换行符: display:table-cell 元素会作为表格单元格来显示(类似<td> 和 < ...

  3. Fiddler抓取HTTPS设置

    做App测试,用Fiddler进行抓包,以下操作记录如何用手机进行设置使其可以捕捉HTTPS协议. 一.电脑端设置 1.手机和电脑保持统一局域网内 2.配置fiddler允许监听到https 打开Fi ...

  4. win10下JDK安装,配置环境变量后报Error: could not open `C:\Program Files\Java\jre1.8.0_112\lib\amd64\jvm.cfg'

    把Path里面的%JAVA_HOME%/bin放在最前面.

  5. popoverController使用注意--转

    一.设置尺寸 提示:不建议,像下面这样吧popover的宽度和高度写死. 1 //1.新建一个内容控制器 2 YYMenuViewController *menuVc=[[YYMenuViewCont ...

  6. hdu 1979 DFS + 字典树剪枝

    http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others ...

  7. EmitMapper系列之一:EmitMapper入门

    EmitMapper的总结 EmitMapper简介 前言: 参考官网: http://emitmapper.codeplex.com/ Project Description Powerful cu ...

  8. jQuery选择器之属性筛选选择器

    在这么多属性选择器中[attr="value"]和[attr*="value"]是最实用的 [attr="value"]能帮我们定位不同类型 ...

  9. jsonp对付同源策略

    当 协议不同或者域名/ip不同或者端口号不同 ,  都不算是同源 这时候 源生的ajax 就不能进行数据请求了 JSONP json with padding 在平时的开发中也发现了  ,当我们请求  ...

  10. 下载JSTL方法

    第一步:访问 http://www.apache.org/dist/ 第二步:点击jakarta