安装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. IT兄弟连 JavaWeb教程 URI、URL

    URI介绍 URI(Uniform Resource Identifier),是统一资源标识符的缩写,是一个用于标识某一个Web资源名称的字符串,该标识允许用户对任何资源通过特定的协议进行交互.Web ...

  2. 如果没有intelliJ 编译器?

    刚刚是了一晚上的用记事本来写代码,脱离编译器,发现自己完全废了. 写了好多个类,在命令行编译失败,上网查错误,说编码问题, 编码问题解决后,命令行还是编译失败,粘贴到编译器 发现完全是自己代码能力太弱 ...

  3. 手机测试用例-STK测试用例

    ID 功能描述 操作步骤 预期结果 test time P/F comment tester test time P/F comment tester STK服务 SIM卡适应性测试 1.选取支持ST ...

  4. $ybt\ 【信息学奥赛一本通】题解目录$

    [信息学奥赛一本通]题解目录 $ \large -> OJ$ $ problem1000 $ \(Answer\) - > $ \large 1000$ $ problem1001 $ \ ...

  5. New Land LightOJ - 1424

    New Land LightOJ - 1424 题意:找出01矩阵中最大的完全由0组成的矩阵. 方法: 重点在于转化. 先预处理(i,j)点向上最长能取到的连续的全0条的长度.然后枚举某一行作为矩阵的 ...

  6. git简单使用方法

    跟远程库关联起来: http://www.cnblogs.com/Gabriel-Wei/p/6564102.html http://www.liaoxuefeng.com/wiki/00137395 ...

  7. 自己写的MD5加密原码

    package com.wh.md5; import java.security.MessageDigest; import java.util.Arrays; /** * @author 王恒 * ...

  8. 单页Html及Android App供小孩学习常用汉字

    为了检验及帮助小孩学习常用汉字,简单开发本网页应用: 常用汉字是按使用频率排序的,来源于网上: 该简单应用 有Android APP下载 “学习常用汉字_20150910.apk” 单页Html 示例 ...

  9. CSS3常用属性浏览器兼容前缀

    1.检测网站https://gsnedders.html5.org/outliner/ 2.查询是否支持前缀http://caniuse.com 3.border-radius\box-shadow\ ...

  10. php同时查询两个表的数据

    业务环境,表一 会员等级表, 表二会员表, 有一个字段是相同的 会员等级ID level 在会员的显示页面要直接显示会员的会员等级名称,不是等级ID. 1.同时查询两个表 2.表设置别名, selec ...