gogl92 / yii2-teleduino
https://www.teleduino.org/ 的可视化界面模块
Requires
- php: >=5.4.0
- mashape/unirest-php: 2.6.2
- vova07/yii2-select2-widget: 0.1.2
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-bootstrap: *
This package is auto-updated.
Last update: 2024-08-29 03:58:09 UTC
README
概述
Yii2-teleduino 是一个为 Yii2 框架实现的模块,它提供了一个方便的基于 Web 的界面和命令行工具,用于与符合 Teleduino API (v328) 规范的 Web 服务进行交互。
安装
通过 composer 安装此扩展是首选方式。
运行以下命令
php composer.phar require --prefer-dist inquid/yii2-teleduino "*"
或添加
"inquid/yii2-teleduino": "*"
到您的 composer.json
文件的 require 部分。
- 在应用程序的 modules 属性中声明新的模块 ID
teleduino
。在文件config/web.php
中使用以下应用程序配置
return [ ...... 'modules'=>[ 'teleduino'=>[ 'class' => 'inquid\teleduino\Module', 'apiKeys'=>[ [ 'key'=>'00000000000000000000000000000000', 'name'=>'My Key 1', ], [ 'key'=>'11111111111111111111111111111111', 'name'=>'My Key 2', ], ], ], ...... ], ...... ];
- 在浏览器中打开以下 URL:
http://yourdomain.com/path/to/app/index.php?r=teleduino
配置
除了“安装”部分第 2 页中描述的必需模块配置之外,您还可以通过使用 Yii 的依赖注入容器来配置 API 组件属性。
在此示例中,每个选项都分配了其各自的默认值。
<?php Yii::$container->set( \inquid\teleduino\components\Api::className(), [ // Default API Endpoint (Request URL). // You can override this in the web interface "API Options" form. // This parameter is useful for console command, since if set, you can omit setting a corresponding option in the command line. 'apiEndpoint' => 'https://us01.proxy.teleduino.org/api/1.0/328.php', // Default API key. // This parameter is useful for console command, since if set, you can omit setting a corresponding option in the command line. 'apiKey' => null, // User agent string that will be supplied to the API server with each request. 'userAgent' => 'Yii-teleduino/1.0', // Whether to check endpoint's certificate for validity, if the endpoint is a HTTPS server. // Set this to FALSE only if you are using self signed certificates! 'sslVerifyPeer' => true, ] ); $params = require(__DIR__ . '/params.php'); $config = [ ....
请参阅 example-config
目录中的示例配置文件。
访问控制
如果您想为此模块应用一些访问限制,则需要编辑文件 Module.php
。在文件中找到以下方法
public function beforeAction($action) { if (parent::beforeAction($action)) { // Place access checking code here, if needed. return true; } else { return false; } }
并用实际的访问检查代码替换相应的注释。
定制
您可以通过编辑其样式文件轻松地定制模块的 Web 界面外观。请查看 assets
文件夹,您将找到两个包含样式的文件
-
teleduino.less - 这是使用称为 LESS 的语言编写的样式。请考虑编辑此文件,然后生成 CSS 文件,因为 LESS 更方便。
-
teleduino.css - 这是根据 teleduino.less 生成的 CSS 文件。此文件包含在网页中。如果您不希望使用 LESS,则可以直接编辑它。
实际上,这些文件几乎是空的,因为模块依赖于 Bootstrap 进行样式化。但您仍然可以根据需要覆盖一些样式。
控制台命令
Yii2-teleduino 模块包括控制台命令,可以从命令行和 shell 脚本完全访问 API。
为了激活控制台命令,您需要修改您的控制台应用程序配置文件(通常位于 config/console.php
)。您需要以与“安装”部分第 2 页中描述的相同方式声明模块 teleduino
。然后您需要将 teleduino
添加到控制台应用程序的 bootstrap
属性中。
您还可以配置 API 组件的属性
生成的配置应类似于以下内容
<?php Yii::$container->set( \inquid\teleduino\components\Api::className(), [ // Default endpoint URL. Will be used, if no --apiEndpoint was specified in the command line. 'apiEndpoint' => 'https://us01.proxy.teleduino.org/api/1.0/328.php', // Default API Key. Will be used, if no --apiKey was specified in the command line. 'apiKey' => '00000000000000000000000000000000', ] ); $params = require(__DIR__ . '/params.php'); $config = [ ..... 'bootstrap' => ['teleduino'], 'modules'=>[ 'teleduino'=>[ 'class' => 'inquid\teleduino\Module', ], ], ...... ]; ....
请注意,如果您在配置文件中未声明 apiEndpoint
和/或 apiKey
,则每次都需要在命令行中明确指定它们!
现在,您应该可以通过以下方式获取 teleduino
命令的帮助:./yii help teleduino
- 以这种方式运行将显示有关所有可用方法的通用帮助。
要获取特定方法的详细信息,请运行以下命令:./yii help teleduino/api/defineSerial
以下是调用一些方法的示例
-
./yii teleduino/api/getVersion
- 获取可读性高的固件版本 -
./yii teleduino/api/getEeprom --responseFormat=json --offset=0 --byte_count=200
- 获取 EEPROM 的前 200 个字节,以 JSON 格式返回结果。 -
./yii teleduino/api/getAllInputs --apiEndpoint="http://example.com" --apiKey="alternate-key"
- 使用明确的API端点和密钥获取所有数字和模拟引脚的输入值。
赞助商和原始创意
SUOI 开发者 Luis Armando González
- 电子邮件: luisarmando1234@gmail.com
- Twitter: gogl92
作者
Andriy Kmit'
- 电子邮件: dev@madand.net
- Elance: Andriy Kmit'