npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-flies

v1.0.5

Published

基于ruff,egg和mosca或者aliyun物联网套件的iot框架

Downloads

7

Readme

Flies 起源

“飞蝇”意义表轻巧、快速。Fli 取自飞猪前半部分,将 Fly 复数化。可帮助个人开发者实现快速搭建家庭私有物联网,目标能让开发者通过框架实现前端展现变成通用范式并统一通信规范,框架包含 Ruff 的构建和实时通信及通信鉴权以保证 IoT 安全,最终可实现两种服务搭建模式

使用方法

  • 安装脚手架
$ npm install tnpm -g --registry=http://registry.npm.alibaba-inc.com
$ tnpm install @ali/generator-flies -g
  • 然后生成项目
yo @ali/flies

环境准备

  • node 版本>=8

项目说明

本地模式

通信原理

项目说明

  • web server 采用 egg 作为服务端,react 作为 view 层,主要进行页面的托管
  • mqtt broker 采用基于 js 的 mosca 开源实现。
  • 硬件端采用 ruff development board,其对硬件操作都做了基于 js 语言的抽象,对于开发者十分友好
  • 硬件和客户端的消息均采用 mqtt 协议进行交互。

运行方法

  1. 安装项目依赖

如果  项目生成时未选择自动安装依赖,在  项目根目录下执行

npm i

依赖安装中可能出现一些依赖安装不成功的情况,是因为依赖本地编译时需要的  一些 c/c++包找不到所致。下面以 macOS 为例:

  • mac 上找不到 pkg-config
    • 使用 brew install pkg-config 因为 mac 上默认没有
  • 找不到 libzmq
    • install zmq using brew : brew install zmq
    • export PKG_CONFIG_PATH=/usr/local/Cellar/zeromq/4.0.4/lib/pkgconfig/
    • sudo visudo and add Defaults env_keep += "PKG_CONFIG_PATH"
    • sudo npm install zmq

这样一般  便能安装成功依赖

  1. web server 配置
`config/config.default.js`;
exports.mosca = {
  auth: {
    test: {
      password: '666666',
      subscribe: ['led-status', 'led-operate', 'get-led-status'],
      publish: ['get-led-status', 'led-operate']
    }
  }
};

其中'test'代表可登入服务器的用户名,'password'代表登录密码,'subscribe'数组里为该用户名可订阅的 topic,publish 为该用户名可发布的 topic。初始项目可不必更改,保持原状。

  1. 启动 web server

于项目根目录执行命令

npm run dev

 启动完成后会自动打开浏览器,页面如下所示

输入配置的‘username’和‘password’即可链接服务器成功。页面文件路径为 app/web/page/home。

  1. 安装 ruff sdk

具体安装方法参考 ruff 官网 step 4。

  1. ruff 配置
`ruff/src/config.js`;
module.exports = {
  url: 'mqtt://{IP}:1883',
  username: 'test',
  password: '666666'
};

其中{IP}为你电脑连上 ruff 开发板时的 ip。具体连接开发板操作方法参考 ruff 官网 step 4。‘username’和‘password’和 web server 配置保持一致。

  1. 安装样例 demo 所需的按钮组件

在项目根目录执行命令封装好的命令(执行命令时需连外网)

npm run ruff-layout-visual

或者进入./ruff 目录执行原生命令

rap layout --visual

会在浏览器打开一个可视化界面,按照图示将按钮连接上 ruff 开发版即可。

  1. 部署代码到 ruff 开发板

在项目根目录执行命令封装好的命令

npm run ruff-deploy

或者进入./ruff 目录执行原生命令

rap deploy -s
  1. 部署完成

完成上述步骤,整个项目便能运行成功,此时点击 web 界面里的开关 ,ruff 开发板的红色 led 灯会  相应的点亮或熄灭。按下 ruff 开发板上连接的按钮,也可控制 led 的亮灭,并且状态会实时反映到 web 界面上。

阿里云 iot 模式

基于阿里云物连网通信

通信原理

项目说明

  • web server 采用 egg 作为服务端,react 作为 view 层,主要进行页面的托管和用户鉴权,以及消息中转
  • mqtt broker 采用阿里云物联网套件
  • 硬件端采用 ruff development board,其对硬件操作都做了基于 js 语言的抽象,对于开发者十分友好
  • 设备采用 mqtt 协议和阿里云物联网条件进行交互。阿里云套件将设备上报信息存入消息队列。服务端可以从消息队列取出消息,进行消费

Node 服务端运行方法

  1.  安装  项目依赖如果  项目生成时未选择自动安装依赖,在  项目根目录下执行
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm i

这样安装项目所需要的依赖包。

  1. 阿里云 IOT 套件连接接参数
`config/config.default.js`;
exports.aliyunIot = {
  endpoint: 'https://iot.cn-shanghai.aliyuncs.com',
  apiVersion: '2018-01-20',
  region: 'cn-shanghai',
  accessKeyId: '阿里云accessKeyId',
  accessKeySecret: '阿里云accessKeySecret',
  aliyunId: '阿里云账户id',
  queueName: '开通阿里云物联网套件生成MNS消息队列',
  productKey: '阿里云物联网套件中申请的productKey',
  deviceName: '阿里云物联网套件中申请的deviceName'
};

下面对主要阿里云 iot 参数获取的进行说明:

  • queueName,阿里云消息队列名称 如图下面在阿里云网站获取

  • deviceName, productKey 如图下面在阿里云网站获取

  • accessKeyId,accessKeySecret 为访问阿里云 api 的秘钥,如图下面在阿里云网站获取

配置阿里云通信 Topic

  1. 系统使用的 Topic 类列表为

    • ledStatus
    • ledOperate
    • getLedStatus
  2. 需要在阿里云 iot 套件中新建对应的 topic,建立好对应的 Topic 类列表如下图所示

  3. 在阿里云 iot 中建立对应的 topic 列表后,设备和应用可以通过阿里云 iot 消息中心进行通信。

    测试用户和密码配置

`config/config.default.js`;

exports.auth = {
  username: 'test',
  password: '666666'
};

其中'test'代表可登入服务器的用户名,'password'代表登录密码。

启动 web server

于项目根目录执行命令

npm run dev

 启动完成后浏览器浏览器打开链接http://localhost:7001,页面如下所示

输入配置的‘username’和‘password’即可链接服务器成功。页面文件路径为 app/web/page/home。

ruff 开发板运行方法
  1. 安装 ruff sdk 具体安装方法参考 ruff 官网 step 4。
  2. ruff 配置配置阿里云 IOT 参数
`ruff/src/config.js`;
module.exports = {
  productKey: '阿里云物联网套件中申请的productKey',
  deviceName: '阿里云物联网套件中申请的deviceName',
  deviceSecret: '阿里云物联网套件中申请的deviceSecret'
};
  • 其中 productKey,deviceName,deviceSecret 可以参考上面 阿里云 IOT 套件连接接参数 配置详解
  1. ruff IP 配置
  • 由于系统架构需要 ruff 开发版需要直接将消息推送到阿里云服务端,因此 ruff 开发版需要直接连接外部 wifi。
  • 具体操作如下: _ 请确保开发机已经连接到开发板提供的无线网络上。 _ 在浏览器中访问 console.ruff.io(当域名不可用时,请访问 192.168.78.1)。 _ 填写常用无线网络的 SSID 和密码并确认(注意开发板仅支持 2.4G 无线网络)。 _ 具体操作还可以参考ruff 官网添加外部 wifi
  1. 安装样例 demo 所需的按钮组件

在项目根目录执行命令封装好的命令

npm run ruff-layout-visual

或者进入./ruff 目录执行原生命令

rap layout --visual

会在浏览器打开一个可视化界面,按照图示将按钮连接上 ruff 开发版即可。

  1. 部署代码到 ruff 开发板在项目根目录执行命令封装好的命令
npm run ruff-deploy

或者进入./ruff 目录执行原生命令

rap deploy -s

部署完成

完成上述步骤,整个项目便能运行成功,此时点击 web 界面里的开关 ,ruff 开发板的红色 led 灯会  相应的点亮或熄灭。按下 ruff 开发板上连接的按钮,也可控制 led 的亮灭,并且状态会实时反映到 web 界面上。

License

MIT ©