第一部分:matlab与mqtt
1、下载 MQTT in MATLAB 工具箱,放在matlab目录下。(链接:https://www.mathworks.com/matlabcentral/fileexchange/64303-mqtt-in-matlab)

2、编写代码
下面是部分范例,更多范例可自行在上图中查看

function obj = mqtt(varargin)% MQTT Create a MQTT connection to an MQTT broker.MQTT创建到MQTT代理的MQTT连接。% %% Syntax 语法% ------ % mObj = mqtt(brokerAddress)%creates a new MQTT connection to a broker at BrokerAddress%创建一个新的mqtt连接到BrokerAddress的代理%% mObj = mqtt(brokerAddress, NAME, VALUE) %uses additional options specified by one or more Name, Value pair arguments.%使用其他选项由一个或多个名称、值对参数指定。%% Inputs 输入% ------ % BrokerAddress:  Host name or IP address of the MQTT broker, % specified as a string or character array including connection% protocol. Supported protocols include TCP, WS, SSL, and WSS.% MQTT代理的主机名或IP地址,指定为包含连接协议的字符串或字符数组。% 支持的协议包括TCP、WS、SSL和WSS。%   Name-Value Pair Arguments 名称-值对参数%   -------------------------%%   Name名字         Description描述                        Data Type数据类型%   ----    --------------------                         ---------%%   Port 端口 (Integer 整数) %     Specify the socket port number to use when connecting to the MQTT broker.%     指定连接到MQTT代理时要使用的套接字端口号。%%   Username 用户名 (string, char 字符串,字符)%     Specify username to use when connecting to the MQTT broker.%     指定连接到MQTT代理时要使用的用户名。%%   Password 密码   (string, char 字符串,字符)%     Specify password to use with the username used for connecting to MQTT broker.%     指定用于连接到MQTT的用户名的密码%%   ClientID 客户端ID(string, char 字符串,字符)%    Specify an MQTT identifier that identifies the client to the broker. %    指定用于向代理标识客户端的MQTT标识符。%%   Timeout  超时    (Integer 整数)%    Specify time in seconds to complete a connection to the broker.%    指定以秒为单位完成与代理的连接。%%   CAFile           (string, char 字符串,字符)%    Specify Server Root Certificate to use%    for authenticating the broker during%    secure connection.%    指定在安全连接期间用于验证代理的服务器根证书。%%   ClientCertificate  客户端证书     (string, char 字符串,字符)%    Specify Client Certificate to use for%    authenticating client during secure %    connection.%    指定用于在安全连接期间对客户端进行身份验证的客户端证书%%   ClientKeyFile      (string, char 字符串,字符)%    Specify private key file to use along%    with ClientCertificate for client %    authentication during secure connection.%    指定私钥文件与ClientCertificate一起用于安全连接期间的客户端身份验证。%%   SSLPassword        (string, char 字符串,字符)%    Specify password to decrypt the private%    key in ClientKeyFile.    %    指定密码以解密ClientKeyFile中的私钥。%%   Examples实例:%   --------%%     Connect to broker 连接到代理%     -------------------------------    %%     % Example 1: Connect to broker 示例 1:连接到代理%     % ----------%     % Create an MQTT connection to hivemq public broker. 创建到hivemq公共代理的MQTT连接%     myMQTT = mqtt('tcp://broker.hivemq.com')%%     % Example 2: Create an MQTT connection with ClientID and Port Number  %       示例 2:使用ClientID和Port创建MQTT连接%     %  ---------- %     % Create an MQTT connection to hivemq public broker at port %     % number 1883 and specify the clientID as 'myClient'%       在端口号1883处创建到hivemq public broker的MQTT连接,并将clientID指定为“myClient”%%     myMQTT = mqtt('tcp://broker.hivemq.com','ClientID','myClient',...%       'Port',1883)%%     % Example 3: Create a secure MQTT connection over TCP%       示例 3 :通过TCP创建安全MQTT连接%     %  ---------- %     % Create an MQTT connection to mosquitto public broker at port %     % number 8884 and specify the broker root certificate, client%     % certificate and private key.%     在端口号8884处创建到mosquitto公共代理的MQTT连接,并指定代理根证书、客户机证书和私钥。%%     myMQTTSSL = mqtt('ssl://mosquitto.org', 'Port', 8884, ...%       'CAFile', 'C:.\mosquitto.org.pem',...%       'ClientCertificate', 'C:.\client.pem',...%       'ClientKeyFile', 'C:.\client.key')%%     % Example 4: Create a secure MQTT connection over WSS%       示例 4 :通过WSS创建安全MQTT连接%%     %  ---------- %     % Create an MQTT connection with WSS to ThingSpeak. If required,%     % you can specify the required certificates and keys using %     % Name-Value input arguments.%       创建一个带有WSS的MQTT连接来ThingSpeak。如果需要,%       可以使用名称值输入参数指定所需的证书和密钥。%%     myMQTT = mqtt('wss://mqtt.thingspeak.com', 'Port', 443)  %%     % Example 5: Subscribe to topic 订阅主题%     %  ---------- %     % Create an MQTT connection to hivemq public broker and subscribe to 'myTopic'.%     % 创建到hivemq公共代理的MQTT连接,并订阅“myTopic”。%%     myMQTT = mqtt('tcp://broker.hivemq.com');%%     %Subscribe to a topic 订阅主题%     mySub = subscribe(myMQTT,'Topic')%%     % Example 6: Subscribe to topic at QoS 2 阅QoS 2上的主题%     %  ---------- %     % Create an MQTT connection to hivemq public broker and subscribe to 'myTopic'.%     % 创建到hivemq公共代理的MQTT连接,并订阅“myTopic”。%%     myMQTT = mqtt('tcp://broker.hivemq.com');%%     %Subscribe to a topic 订阅主题%     mySub = subscribe(myMQTT,'Topic', 'QoS', 2);%%     % Example 7: Publish to topic 发布到主题%     %  ---------- %     % Create an MQTT connection to hivemq public broker and %     % publish message 'testMessage' to topic 'myTopic'.%       创建到hivemq公共代理的MQTT连接并将消息“testMessage”发布到主题“myTopic”。%%     myMQTT = mqtt('tcp://broker.hivemq.com');%%     % Publish a message to a topic 将消息发布到主题%     publish(myMQTT, 'myTopic', 'testMessage');    % Copyright 2017-2019, The MathWorks, Inc.

3、发布、订阅等主题编写需要自行到图3的html中查找

第二部分:oneNET与mqtt
1、打开控制台选择 “MQTT物联网套件——创建项目——添加产品——添加设备“ 设置所需参数。

2、找到设定的clientID、username、password、等放入第一部分的代码中。
设备创建与密码等教程参考上图的文档中心,根据里面的文档操作即可(链接:https://open.iot.10086.cn/doc/iot_platform/book/device-connect&manager/device-auth.html)

第三部分:运行后常见报错
1、未定义变量 “com” 或类 “com.mathworks.mqttclient.client.Client”

解决办法:在matlab命令行窗口加入下面两条路径
javaaddpath("D:\WIFI\MQTT in MATLAB\jar\org.eclipse.paho.client.mqttv3-1.1.0.jar")
javaaddpath("D:\WIFI\MQTT in MATLAB\mqttasync.jar")


2、Unable to establish connection with broker.
查看oneNET平台的设备日志,打开文档中心查询报错日志对应的原因,查询对应日志错误信息与解决方案。
本日志显示为“1104”,查询结果为token已过期,解决办法为检查token的过期时间。



第四部分:Matlab通过oneNET与其他设备(如手机)通信
可以使用oneNET平台的场景联动功能。

Matlab与oneNET通过Mqtt通信相关推荐

  1. 使用 MQTTnet 快速实现 MQTT 通信

    1 什么是 MQTT ? MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是 IBM 开发的一个即时通讯协议,有可能成为物联网的重要组成部分.MQT ...

  2. c# 批量mqtt_C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载)

    MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载) 原创weixin_pwtank1983 发布于2018-02-03 10:22:24 阅读数 36681 收 ...

  3. 差分跳频MATLAB,基于Matlab的短波差分跳频通信仿真设计与实现

    第29卷第5期沈阳理工大学学报V01.29No.52010年10月JOURNALOFSHENYANGLIGONGUNIVERSIrⅣOct.2010文章编号:1003-1251(2010)05-001 ...

  4. matlab gul介绍及串口通信实现,Matlab - GUl介绍及串口通信实现(转)

    新建Blank GUI. 在新建Blank GUI界面中,包含了一般的界面元素,如菜单.按钮.坐标轴.控件等.添加必要的串口通信参数设置按钮. 2 串口数据发送与接收功能实现 2.1 建立串口通信流程 ...

  5. 手机端(APP点灯blinker)-PC端(Node-red)-设备端(ESP32)-客户端(MQTTX客户端)四者之间的通信——通过MQTT通信(上)

    手机端(APP点灯blinker)-PC端(Node-red)-设备端(ESP32)-客户端(MQTTX客户端)四者之间的通信--通过MQTT通信(上) 前言: 本次实验是通过MQTT来进行手机端-设 ...

  6. 搭建阿里云物联网平台实现MQTT通信

    1,点击进入阿里云官方网站:阿里云-上云就上阿里云 (aliyun.com) 2,注册登录并且进行实名认证: 如下图: 点击右上角 控制台,进入如图界面: 3,在阿里物联网云平台创建设备: 首先创建产 ...

  7. WiFi-ESP8266入门http(3-4)网页一键配网(1若为普通wifi直连 2若为西电网页认证自动网页post请求连接)+网页按钮灯控+MQTT通信...

    网页一键配网(1若为普通wifi直连  2若为西电网页认证自动网页post请求连接)+网页按钮灯控+MQTT通信 工程连接:https://github.com/Dongvdong/ESP8266_H ...

  8. 阿里云服务器ECS搭建EMQ快速实现MQTT通信

    文章目录 一.简介 二.环境准备 1.树莓派 2.阿里云ECS 3.PC 三.ECS搭建部署EMQ 1.EMQ X Enterprise的安装 2.添加License文件 四.MQTT通信 1.准备工 ...

  9. 物联网温湿度显示控制项目(网页、Android双端显示搭载linux平台网关MQTT通信)

    演示视频如下: 物联网项目案例-温湿度检测及mqtt实现控制(带双端显示) 代码资源可在我的资源中免费下载学习使用~ 资源链接:https://download.csdn.net/download/q ...

最新文章

  1. 【文本分类】Recurrent Convolutional Neural Networks for Text Classification
  2. 常见的CSS属性和值CascadingStyleSheets
  3. Delphi (Library Path Browsing Path)
  4. VS2010下使用dmp文件和pdb文件定位程序异常代码行号的注意事项
  5. 机器知道哪吒是部电影吗?解读阿里巴巴概念图谱AliCG
  6. PADS 非常用操作 备忘
  7. Windows XP SP3细节官方详解
  8. 利用matlab自带函数graycoprops 实现基于共生矩阵的遥感图像纹理特征分析
  9. visual studio 删除附加项
  10. P2922 [USACO08DEC]秘密消息Secret Message
  11. 偏序关系与全序关系的区别
  12. lua游戏脚本自动打怪_了解Lua(官方文档翻译)
  13. 自适应各终端懒人泽客导航源码v2.6 无后门
  14. 体育类App原型制作分享-Onefootball
  15. pwm波控制舵机原理(转)
  16. 电脑技巧:Win10操作系统关闭这几个功能,可以大幅度提升电脑的运行速度
  17. 基于Win32框架的OpenGL程序
  18. shell 获取当前目录的路径
  19. Matlab上位机开发(一) —— 了解上位机
  20. Thread.setDaemon设置说明

热门文章

  1. 任务栏图标空白,图标是一块白板
  2. dva源码解析(四)
  3. 易信客户端导出聊天记录方法
  4. 同声传译器哪个好?快把这些软件收好
  5. 读书笔记 - 《激荡十年,水大鱼大》
  6. 田野调查手记·浮山摩崖石刻(十五)
  7. jquery读取ajax,JQuery / AJAX从外部文件读取数据
  8. 杨立昆:科学之路读书笔记1
  9. EF登录+首页+列表
  10. 【前端】React---基础1