
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
miot 命名 来自于 MQTT IOT
,它是一个基于 MQTT 协议的物联网平台框架。请注意,它和小米公司没任何关系。通过它,你可以快速地搭建属于你自己的物联网平台。通过下图,你可以大概地了解该平台的结构。
此平台分为四层,其主要名称和功能如下:
此外,为了便于后面的叙述,下面对涉及平台相关的一些名词做出解释:
如果你已经安装了 npm 客户端,可以通过 npm 安装服务程序 miot:
$ npm install miot
此服务程序即外网网关,同时它内置了视图服务以及中间件服务,下面给出的是项目的基本结构:
miot/
├── miot.js // 主文件
├── config.json // 配置文件
├── middle/ // 中间件目录
└── static/
├── views/ // 视图层目录
└── index.html // 视图层入口
这里仅对配置文件做些说明,对于其它内容,你只需要稍微了解就可以,当后面各章节会有详细的说明。
{
"proxy": {
"http": {"port": 8080, "static": "dir/static"}
//"https": { "port": 443, bundle: true, "static": "dir/static" },
//"secure": { "keyPath": "dir/secure/tls-key.pem", "certPath": "dir/secure/tls-cert.pem" } },
},
"mosca": {
"port": 1883
//"secure": { "port": 8443, "keyPath": "dir/secure/tls-key.pem", "certPath": "dir/secure/tls-cert.pem" }
},
"logger": {
"lever": "info",
"appender" "default"
}
}
上面配置中,proxy 是提供给视图连接的配置,你可以根据需要来决定是否提供 https 服务。mosca 是提供给内网网关连接的配置,你可以根据需要来决定是否启用 lts 安全连接。logger 是日志打印配置。
在上节给出的项目的基本结构中,视图层位于 /miot/static/views 目录中。其中,index.html 是主文件,旗下目录 views 存放了相关的视图目录。
在视图层主文件 index.html 的开头是外网网关的 MQTT 服务器的地址配置,你可以按需修改该内容:
<meta name="mqtt-server" content="ws://localhost:8080">
上面 content 中的 8080 即来自上节中配置文件的 port 值。当一切配置就绪后,即可使用如下命令启动项目:
$ node miot.js
项目启动后,用浏览器访问 index.html,使用初始用户名 admin 和密码 123456 即可登录后台进行配置管理。
与视图类似,中间件也依附于外网网关,位于 /miot/middles/ 目录中,中间件由外网网关动态按需实例化。
首先,安装内网网关服务程序 miot-local:
$ npm install miot-local
此服务程序包含了内网网关的相关文件,下面仅列出最要紧的两个文件:
miot-local/
├── miot-local.js // 主文件
└── config.json // 配置文件
相对于于外网网关,内网网关较为简单,在此着重对配置文件做些说明:
{
"proxy": {
"port": 1883, // 若开启 tls,则使用 8443 端口
"host": "localhost",
"clientId": "be1aa660-2b48-11ec-a191-4dbcbb23f97f", // 连接到外网网关的客户端标识符
"protocol": "mqtt", // 若开启 tls,则使用 mqtts
//"rejectUnauthorized": true, // 开启授权
//"ca": "dir/secure/tls-cert.pem" // 自签名证书
},
"mosca": {
"port": 1883,
//"secure": { "port": 8443, "keyPath": "dir/secure/tls-key.pem", "certPath": "dir/secure/tls-cert.pem" }
},
"parts": [
{ "id": "d9ae5656-9e5e-4991-b4e4-343897a11f28", "path": "/system" },
{ "id": "35e64bc0-1268-477a-9327-94e880e67866", "path": "/player" }
]
}
上面配置中,proxy 是连接到外网网关的配置,你可以根据需要来决定是否使用 lts 连接。mosca 是提供给内网配件连接的配置,你可以根据需要来决定是否开启 lts 安全连接。
另外,上述 parts 项是连接到内网网关的配件列表,parts 中的 path 参数用于唯一地命名配件,其描述方式类似于操作系统的文件定位。
当一切配置就绪后,即可使用如下命令启动网关服务:
$ node miot-local.js
任何支持 MQTT 客户端的软硬件平台都可以非常方便地建立配件以接入内网网关。下面仅以 Node.js 环境示例。首先安装 miot-part 模块。
$ npm install miot-part
下面一个是配件的示例,由此示例可知,配件想要连接到内网网关,提供的参数与上节中连接到外网网关的 proxy 配置类似。
let xmlplus = require("miot-part"); // 模块引入
let config = {
"port": 1883, // 若开启 tls,则使用 8443 端口
"host": "localhost",
"partId": "d9ae5656-9e5e-4991-b4e4-343897a11f28", // 连接到外网网关的客户端标识符
"protocol": "mqtt", // 若开启 tls,则使用 mqtts
//"rejectUnauthorized": true, // 开启授权
//"ca": "dir/secure/tls-cert.pem" // 自签名证书
};
xmlplus("part-demo", (xp, $_) => {
$_().imports({
Index: {
cfg: { index: config },
xml: "<i:Client id='index' xmlns:i='//miot-part'/>",
fun: function (sys, items, opts) {
this.watch("/hi/alice", (e, body)=> {
this.trigger("to-users", "/hi/bob");
});
}
}
});
}).startup("//part-demo/Index");
与中间件不同,配件是一个独立的终端应用程序,它通过 MQTT 协议与内网网关相联系。
FAQs
An IOT platform based on MQTT.
The npm package miot receives a total of 22 weekly downloads. As such, miot popularity was classified as not popular.
We found that miot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.