extrablind / monithomebundle
从 Symfony 控制 MySensors 网关。
dev-master
2020-09-29 23:29 UTC
Requires
- php: >=7.2
- friendsofsymfony/rest-bundle: ^2.5
- jms/serializer-bundle: ^3.0
- sensio/framework-extra-bundle: ^5.2
- symfony/flex: ^1.1
- symfony/form: ^4.1
- symfony/monolog-bundle: ^3.3
- symfony/process: ^4.1
- symfony/webpack-encore-bundle: ^1.0
- dev-master
- dev-dependabot/npm_and_yarn/Resources/vue/monithome/cookiejar-2.1.4
- dev-dependabot/npm_and_yarn/Resources/vue/monithome/bootstrap-4.3.1
- dev-dependabot/npm_and_yarn/Resources/vue/monithome/luxon-1.28.1
- dev-dependabot/npm_and_yarn/Resources/vue/monithome/jquery-3.6.4
- dev-dependabot/npm_and_yarn/Resources/vue/monithome/node-sass-7.0.0
This package is auto-updated.
Last update: 2024-08-30 01:44:52 UTC
README
注意
!!! 新的独立 symfony/vuejs 控制器(单页面应用)即将推出,使用 mercure 代替 websockets!!!!!! 这不再是最新的。!!!
请报告任何错误,欢迎贡献
这是关于什么的?
- 这个 symfony 扩展包是 MySensors 的控制器,处于早期阶段,完全用 PHP 编写。
- 它使用 vue.js 作为前端引擎来展示数据和绘图。
- 它使用 dio 扩展与串行网关(USB 网关)进行适当的通信。
- 使用 websockets 在 vuejs 和 php 之间进行实时通信。
- 一旦从网关(处理后)收到消息(节点的新值),它就会被推送到 vue,实时(正在优化 ws 请求/响应时间以改善响应时间)
- 与 Symfony 4.2 和 PHP 7.2-7.3 进行了测试
展示
先决条件和限制
- 您必须安装 php_dio 扩展(pecl 扩展):这将允许 PHP 直接访问串行端口,这是串行端口工作的唯一方式。实际上没有进行检查,因此首先请检查此要求(见下文)!
- 您需要通过 cron、nohup 或 screen 在后台运行守护程序(在树莓派上大约占用 4% 的内存)
- 一个用于 websockets
- 一个用于检索和处理 USB 网关信息
- 目前仅支持串行网关(连接到 USB)或模拟文件网关
- 您的数据库必须原生支持
json_array类型(maria db >=10.2 或 sqlite3) - 特定的服务器配置(mod proxy for apache,详细信息见下文)
它做什么?
- 获取并显示当前传感器的状态
- 使用切换按钮轻松设置激活器
- 支持:
V_STATUS、V_LIGHT_LEVEL、V_TEMP、V_HUM等,更多功能即将推出...
- 记录接收到的数据
- 使用 chartjs 简单地绘制每个传感器的数据
- 完整图形显示所有传感器的全局视图
- 简单的日期范围查询日志
- 通过在详细模式下启动守护程序(-vvv)进行完整的和简单的网关调试
- 同时触发多个操作
- WIP:根据条件构建场景
- 安排操作
- 绘制您的网络拓扑
- 文件模拟网关用于本地测试目的(无需网关即可贡献)
- 在收到来自网关的新消息时分发事件
- 简约的 REST API(需要更多关注)
待办事项
- 触发器和条件
- 目前仅支持手动触发操作或安排操作
- 条件(场景)尚未实现,但已在界面中显示
- 允许通过 GUI 创建和修改节点
- 目前仅支持 yaml 定义
- 在收到网关的展示消息时创建新节点和传感器(自动模式)
- 测试新消息类型(和传感器)、新值、新单位和调试...
- 改进图表数据(冗余的大查询和未优化的格式化)
- 改进 API 以提高网络传输
安装和配置
在 php.ini 文件中配置 php dio 扩展
从 pecl 安装
sudo pecl install channel://pecl.php.net/dio-0.1.0
在 cli 和 apache php ini conf 中添加 dio 扩展
# php -v => current used php version # php --ini => current user php ini files # php -m | grep dio => check modules installed correctly extension=dio
使用 composer 安装插件
composer require extrablind/monithomebundle
在 /config/bundles.php 中注册
return [ # [...] Extrablind\MonitHomeBundle\ExtrablindMonitHomeBundle::class => ['all' => true], ];
注册路由: /config/routes.yml
extrablind_monithome: resource: "@ExtrablindMonitHomeBundle/Resources/config/routing.yml"
使用文件网关配置扩展(开发时无需 USB 网关) config/packages/dev/monithome.yml
parameters: # Service used as gateway monithome.gateway.service: 'monithome.gateway.file' # Final uri for websockets monithome.ws.url: 'ws://:54300' extrablind_monit_home: gateway: file: # Path to the emulated gateway path: "%kernel.project_dir%/var/data/gateway.txt" # Web Socket Configuration # You will probably need to edit only firewall, hosts and port gos_web_socket: client: firewall: dev # Example: secured_area, you must replace it by your firewall server: port: 1337 # The port the socket server will listen on host: 127.0.0.1 # The host ip to bind to router: resources: - "@ExtrablindMonitHomeBundle/Resources/config/ws/routing.yml" topics: - "@monithome.input.topic" - "@monithome.push.topic" pushers: wamp: host: 127.0.0.1 port: 1337
使用 USB 网关配置扩展,例如 prod 配置:/config/prod/monithome.yml
parameters: monithome.gateway.service: 'monithome.gateway.usb' # See apache configuration for proxying ! monithome.ws.url: 'wss://<yourdomain>/wss' extrablind_monit_home: gateway: # Parameters for USB gateway usb: device: /dev/ttyUSB0 baudrate: 115200 bits: 8 stop: 1 parity: 0 # Web Socket Configuration gos_web_socket: client: firewall: main server: port: 1337 host: 127.0.0.1 router: resources: - "@ExtrablindMonitHomeBundle/Resources/config/ws/routing.yml" topics: - "@monithome.input.topic" - "@monithome.push.topic" pushers: wamp: host: 127.0.0.1 port: 1337
安装资产
bin/console assets:install --symlink
更改你的设备所有权
# You may need some additionnal rights here
sudo chown -R www-data:www-data /dev/ttyUSB0
创建并迁移Doctrine模式
# !!! Must support json_array type natively (maria db >=10.2 or sqlite3). Currently tested on sqlite3 only... Please report any bug here for mysql or mariadb. Currently only tested with sqlite3 bin/console doc:mi:diff && bin/console doc:mi:mi
使用自己的网络拓扑编辑节点和传感器定义
# Double check this step # See value types here : https://www.mysensors.org/download/serial_api_20 # A full commented example can be found in vendor/extrablind/monithomebundle/Resources/config/mysensors.sample.yml bin/console mysensors:update var/data/mysensors.yml
# You can truncate all table before inserting with :
bin/console mysensors:update var/data/mysensors.yml --truncate
配置服务器
sudo a2enmod proxy_wstunnel
配置你的虚拟主机(假设你在https上)
# Websocket proxy
# wss redirects to working ws protocol
ProxyPass /wss ws://127.0.0.1:1337 retry=0 keepalive=On
ProxyPassReverse /wss ws://127.0.0.1:1337 retry=0
sudo service apache2 restart
启动守护进程
没有守护进程,你无法与网关通信,所以没有日志,没有接收新消息的事件,没有从网关更新的值……什么都没有。启动守护进程非常重要。它将一直运行,直到你停止它,或从ssh断开连接(将其screen或cron以避免这种行为)。只启动一个守护进程。
!!! 一个效率低下的监视器正在检查守护进程是否存活,并在GUI中显示!! WIP:在界面内添加重启命令!!!始终在mysensor循环之前启动websocket服务器(gos:websocket:server),因为它依赖于它
屏幕方式(直到计算机重启)
sudo apt-get install screen screen bin/console gos:websocket:server screen bin/console mysensors:daemon:start # Type ctrl+a AND after ctrl+d to detach screen console # screen -ls to see available detached screen.
或使用bash脚本 bash <project_dir>/bin/start.sh
#/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" >/dev/null && pwd )" cd $DIR echo "> Working Directory : $DIR" echo "> Kill previous process" screen -X -S monithomesockets quit screen -X -S monithomegateway quit echo "> Screen start socket and gateway, then detach" screen -S monithomesockets -d -m bin/console gos:websocket:server screen -S monithomegateway -d -m bin/console my:daemon:start exit
cron方式(每次重启时启动)
crontab -e @reboot cd your/app/dir/ && bin/console gos:websocket:server @reboot cd your/app/dir/ && bin/console mysensors:daemon:start
测试方式
# A very verbose gateway to understand every message coming to you... bin/console gos:websocket:server & bin/console mysensors:daemon:start -vvv
可选配置
安全性:不允许访问api和monithome GUI
默认情况下,所有内容都是公开可访问的,所以要注意这一点。!!! WIP:api应该带有包名称前缀
# config/security.yml access_control: - { path: ^/monithome, roles: ROLE_ADMIN } - { path: ^/api, roles: ROLE_ADMIN }
你可以使用自己的扩展包模板。
# create : template/bundles/ExtrablindMonitHomeBundle/Default/index.html # don't forget parent() twig function
资产构建(vuejs)
在处理项目时,你需要动态构建资产
cd <path_to_the_bundle>/Resources/vue/monithome yarn encore dev --watch
对于生产构建,请执行(请提交构建文件和vue文件)
yarn encore production # Then git commit



