MQTT 浏览器 mqttws31.min.js
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>mqttws31.min.js 测试</title>
<style>
.divblock {
display: inline-block;
padding: 20px;
border: 2px solid #00ff00;
border-radius: 6px;
margin: 20px 0px;
user-select: none;
} .divblock:active {
background-color: #455072;
border: 1px solid #0044ff;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js"
type="text/javascript"></script>
</head> <body>
<div>4路开关模块</div>
<div class="divblock" onclick="Onmqtttest()">mqtt 发送</div>
</body> <script>
var client = null; // Create a client instance
client = new Paho.MQTT.Client('gzlema.cn', Number(8083), (Math.random() * 1000000000).toString()); // "clientId" 随机数来代替 // set callback handlers
client.onConnectionLost = onConnectionLost; // 指定丢失事件
client.onMessageArrived = onMessageArrived; // // connect the client 指定mqtt 事件 onSuccess 回调函数
client.connect({ onSuccess: onConnect }); // called when the client connects 成功连接mqtt服务器之后的事件函数
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("hotekey_cloud"); // 订阅主题
} // called when the client loses its connection mqtt 丢失或连接不存在而触发的事件函数
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:" + responseObject.errorMessage);
}
} // called when a message arrives 接收到订阅消息
function onMessageArrived(message) {
console.log("onMessageArrived:" + message.payloadString);
} // 推送消息函数
function mqttPublish(sendata) {
message = new Paho.MQTT.Message(sendata); // 消息内容
message.destinationName = "hotekey_board"; // 目标主题
client.send(message); // 推送主题
} // 用户程序点击事件
function Onmqtttest() {
message = "message from browser with websocket"; // 消息内容
mqttPublish(message);
}
</script> </html>
官网手册 https://www.eclipse.org/paho/clients/js/#
MQTT 浏览器 mqttws31.min.js的更多相关文章
- ZeroClipboard / jquery.zclip.min.js跨浏览器复制插件使用中遇到的问题解决
之前写过一个淘宝优惠券连接PC端转手机端连接的小工具,当时写到将转换好的url复制到剪切板这块时解决了IE和火狐,就是没办法搞定Chrome,知道可以通过flash搞定,但是觉得太麻烦没有仔细研究. ...
- jquery.placeholder.min.js让吃屎的IE浏览器支持placeholder去吧
描述:现在都是HTML5时代了,所有的浏览器都支持placeholder,唯独IE不支持.现在我们有了这款插件,IE下终于可以支持了! 图片展示: 兼容浏览器:IE6+/Firefox/Goog ...
- Mvc 之System.Web.Optimization 压缩合并如何让*.min.js 脚本不再压缩
最近项目中用到了easy ui ,但是在配置BundleConfig 的时候出现了问题,easy ui的脚本jquery.easyui.min.js 压缩后出现各种脚本错误,总是莫名其妙的 i标量错误 ...
- html5shiv.js and respond.min.js
因为用到这两个插件,所以记录下来.. html5shiv:解决ie9以下浏览器对html5新增标签的不识别,并导致CSS不起作用的问题. respond.min:让不支持Css3 Media Quer ...
- 让IE系列支持HTML5的html5shiv.js和respond.min.js
HTML5越来越成为主流,被广大搜索引擎所使用,但IE对HTML5的支持却常被人唾弃. 解决方案有两种: 1.为网站创建多套模板,通过程序对User-Agent的判断给不同的浏览器用户显示不同的页面, ...
- Java - 字符串和Unicode互转 - 解析小米pm.min.js
小米JS地址: http://p.www.xiaomi.com/zt/20130313/huodong/pm.min.js 上面这个JS是小米抢手机页面的代码.和抢手机有直接关联.. 虽然我3次都没抢 ...
- html5shiv.min.js 和 respond.min.js 作用(bootstrap做IE低版本兼容时需要用到这两个插件)
1. html5shiv.min.js解决ie9以下浏览器对html5新增标签的不识别,并导致CSS不起作用的问题. respond.min.js让不支持css3 Media Query的浏览器包括I ...
- 为网页生成二维码(jquery.qrcode.min.js)
做网站活动页面的时候,要为每个活动生成一个二维码,虽然简单,但还是习惯记录下来. jquery.qrcode.min.js是js的一个库,主流的浏览器都支持:IE6~10, Chrome, Firef ...
- html5shiv.js和respond.min.js
做页面常用的东西,写这里用的时候省点去找了... html5shiv:解决ie9以下浏览器对html5新增标签的不识别,并导致CSS不起作用的问题. respond.min:让不支持css3 Medi ...
随机推荐
- 题解【洛谷P5248】 [LnOI2019SP]快速多项式变换(FPT)
题目描述 这是一道构造题. 诗乃在心中想了一个n+1项的多项式f(x).第i项的次数为i,系数为ai: f(x)=a0+a1*x+a2*x2+a3*x3+⋯+an*xn 给定m以及f(m)的 ...
- webview在compileSdkVersion 大于等于23 android6.0以上系统执行js代码异常,但是在compileSdkVersion小于23 android6.0以下系统却执行正常问题
问题分析: 在compileSdkVersion>=23 android6.0以上webview.loadUrl用这个方法执行js时会将js中的一些代码当做特殊字符处理, 比如js中var t= ...
- js实现汉字转拼音
汉字转拼音,每个字首字母大写:pinyin.getFullChars(name); 提取首字母并大写:pinyin.getCamelChars(name); /* --- description: P ...
- AcWing 866. 试除法判定质数
#include <iostream> #include <algorithm> using namespace std; bool is_prime(int x) { ) r ...
- 断点调试,issubclass和ininstance的使用
一等公民 只要可以把一个东西赋值给一个变量,这个东西就叫一等公民 断点调试 在想要加断点的地方用鼠标点击一下,你会看到一个红色圆圈 变红的地方,程序执行到,就会暂停 断电应该加载报错之前 绿色箭头表示 ...
- node 连接数据库异常
1 找不到mysql模块 报错:Cannot find module 'mysql' 处理:npm install mysql 2 建立了多次连接 报错:Cannot enqueue Handshak ...
- 用eclipse发布springboot项目
使用eclipse打包springboot项目时一直报错 [ERROR] No compiler is provided in this environment. Perhaps you are ru ...
- Git - 02. git 版本库简述: 类比平行宇宙
1. 概述 简单描述 平行宇宙世界观 将 git 与 平行宇宙世界观 做一个类比, 方便理解 熟悉科幻, 或者具体点, 是 漫威宇宙 的朋友, 可以稍微轻松一点 这个是 第一次 重写后的版本. 代码在 ...
- 问题:宿主机访问不到虚拟机内的docker容器
问题描述:初学Docker,主机Windows 10,虚拟机Cent OS7 运行了一个docker容器(Tomcat7),宿主机无法访问容器运行的服务. 问题原因:宿主机无法访问docker容器ip ...
- Airflow 操作知识总结(完善中)
airflow默认以utc时区运行,如果需要计算正确的时间,需要把时间进行时区转换,核心代码如下 #将本地时间转换为utc时间,再设置为start_date tz = pytz.timezone('A ...