andrewcarteruk/node-red-api

用于与Node-RED API通信的软件包

v0.1.0 2017-06-02 00:59 UTC

This package is auto-updated.

Last update: 2024-09-19 13:46:36 UTC


README

Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

AndrewCarterUK (Twitter)

一组用于与Node-RED API通信的类。支持导入流程。

身份验证

use NodeRED\Instance;
use NodeRED\OAuth;

$instance = new Instance('http://localhost:1883');

$oAuth = new OAuth($instance);
$token = $oAuth->getToken('username', 'password');

令牌

// Tokens are serializable
$serializedToken = serialize($token);
$token = unserialize($serializedToken);

// Check if a token has expired
if ($token->hasExpired()) {
    // ...
}

实例方法

// ::get($path, ? $token)
$authScheme = $instance->get('auth/login');
$flows = $instance->get('flows', $token);

// ::jsonPost($path, $data, ? $token)
$instance->jsonPost('nodes', ['module' => 'node-red-node-suncalc'], $token);

导入流程

use NodeRed\Importer;

$importer = new Importer($instance, $token);

$flowJson = '[{"id":"38fb694f.83ac86","type":"inject","z":"7578d4d1.ba2e2c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":602.5,"y":298,"wires":[["f8ac9ac8.c76808"]]},{"id":"f8ac9ac8.c76808","type":"debug","z":"7578d4d1.ba2e2c","name":"","active":true,"console":"false","complete":"false","x":794.5,"y":298,"wires":[]}]';

$flowId = $importer->importFlow('My New Flow', $flowJson);