andrewcarteruk / node-red-api
A package for communicating with the Node-RED API
v0.1.0
2017-06-02 00:59 UTC
Requires
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: ^4.6
This package is auto-updated.
Last update: 2024-10-19 14:00:47 UTC
README
A set of classes for communicating with the Node-RED API. Supports importing flows.
Authentication
use NodeRED\Instance; use NodeRED\OAuth; $instance = new Instance('http://localhost:1883'); $oAuth = new OAuth($instance); $token = $oAuth->getToken('username', 'password');
Tokens
// Tokens are serializable $serializedToken = serialize($token); $token = unserialize($serializedToken); // Check if a token has expired if ($token->hasExpired()) { // ... }
Instance Methods
// ::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);
Importing Flows
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);