Skip to content

paho.mqtt.wxapp可以让你在微信小程序里连接MQTT broker,实现在小程序里控制硬件,也可用于游戏,已测试的broker:mosquitto、emqtt、hivemq,及百度天工物联网,物接入 IoT Hub

Notifications You must be signed in to change notification settings

visoar/paho.mqtt.wxapp

 
 

Repository files navigation

使用方法

git clone https://github.com/tennessine/paho.mqtt.wxapp.git

执行mvn后会在target下生成paho-mqtt.js、paho-mqtt.min.js,然后在微信小程序里引入即可

直接下载

https://unpkg.com/[email protected]/target/paho-mqtt-min.js

https://unpkg.com/[email protected]/target/paho-mqtt.js

通过npm安装

npm install --save paho-wxapp

sample目录是我写的一个小程序连接MQTT broker的demo

在线文档

https://tennessine.github.io/paho.mqtt.wxapp/target/docs/

测试

https://www.mengmeitong.com/mqtt-client/

百度云测试服务器

host:miniprogram.mqtt.iot.bj.baidubce.com

port:443

username:miniprogram/gekongfei

password:sgx+vSWVMhLS5asUlvXZG03vDTGO8McG+9IMwbVpL40=

注意事项

小程序只能用备案后的域名,并且不能带端口号,所以如果你服务器不是用的443端口或者用的是第三方的服务器,那就需要用nginx反向代理一下(百度云物接入已经支持443端口,无需代理)。

nginx反向代理

server {
  listen 443;
  server_name www.mengmeitong.com;
  ssl on;
  root /opt/nginx/wwwroot/laravel/public;
  index index.php index.html index.htm;
  ssl_certificate   cert/www.mengmeitong.com.crt;
  ssl_certificate_key  cert/www.mengmeitong.com.key;
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;

  location = /mqtt {
    proxy_pass https://miniprogram.mqtt.yourserver.com:8884;
    proxy_redirect off;
    proxy_set_header Host https://miniprogram.mqtt.yourserver.com:8884;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

QQ群

679985050 (2k)

About

paho.mqtt.wxapp可以让你在微信小程序里连接MQTT broker,实现在小程序里控制硬件,也可用于游戏,已测试的broker:mosquitto、emqtt、hivemq,及百度天工物联网,物接入 IoT Hub

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 58.1%
  • HTML 39.7%
  • CSS 2.2%