Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

Functions


newPico

Creates a new pico and returns its id. No parameters are given.

newPico
response = engine:newPico().klog("Response Structure: ")
/*
  Response Structure:
	{
		"id" : <new_pico_id>
	}
*/

Note: newPico does not provide an eci. This function is used in conjunction with engine:createChannel to create a pico with both an id and eci. See wranglerNPE.krl for an example of how to fully create a pico according to a given prototype.


removePico

ParameterDatatypeRequired
<pico_id><string>YES
removePico
response = engine:removePico(id).klog("engine:removePico Response Structure: ")//id is just a string variable
/*
 Response Structure:
	undefined
 //engine:removePico(id) does not return anything
*/



newChannel

Creates a new channel for a pico (identified to the engine by the pico_id parameter).

ParameterDatatypeRequired
<pico_id><string>YES
<name><string>YES
<type><string>YES


newChannel
response = engine:newChannel(id, "channel_name", "channel_type").klog("Response Structure: ")
/*
 Response Structure:
	{
		"id" : id,
		"name": "channel_name",
		"type": "channel_type"
 	}
*/


listChannels

List all the channels for the given pico_id.

ParameterDatatypeRequired
<pico_id><string>YES


newChannel
response = engine:listChannel(id).klog("Response Structure: ")
/*
 Response Structure:
	[
      {
		"id" : "id-0...",
		"name": "name 0",
		"type": "type 0"
 	  },
      {
		"id" : "id-1...",
		"name": "name 1",
		"type": "type 1"
 	  }
    ]
*/



removeChannel

Removes a channel whose eci matches the provided eci. This comparison and deletion takes place on the pico with the provided id.

ParameterDatatypeRequired
<eci><string>YES
removeChannel
response = engine:removeChannel(eci_of_channel).klog("Response Structure: ")
/*
 Response Structure:
	undefined
*/

getPicoIDByECI

Given an eci, get the pico_id that owns that channel.

ParameterDatatypeRequired
<eci><string>YES
removeChannel
pico_id = engine:getPicoIDByECI(eci).klog("Response Structure: ")
/*
 Response Structure:
	"some_pico_id"
*/

registerRuleset

ParameterDatatypeRequired
<url><string>YES
<base><string>NO


Fetch the ruleset krl code given by the `url` and register in the engine.

If you provide `base` then it will be resolved with the url. For example, `base` is  "http://raw.githubusercontent.com" and `url` is "/username/repository1/file.txt" then the engine will register `http://raw.githubusercontent.com/username/repository1/file.txt`

Attempting to register a ruleset with the same rid as a rule that is already registered will pull the ruleset from the given base/url and act as an update action, overwriting the current file with the one from the remote repository.

If you register a ruleset sharing a rid with a system ruleset, the system ruleset will be restored when the engine is restarted.

registerRuleset
response = engine:registerRuleset({"url": url, "base": base}).klog("Response Structure: ")
/*
 Response Structure:
	"myRuleset"
 Simply returns the rulesetID as a string. The rulesetID is the ruleset's name. 
*/


unregisterRuleset

Unregisters the ruleset given by the rid, or list of rids. It will throw an error if the ruleset is installed on any picos, or depended on by another ruleset.

ParameterDatatypeRequired
<rid>string | arrayYES

If your filename is myRuleset.krl, then the ruleset id will be "myRuleset".

unregisterRuleset
response = engine:unregisterRuleset("myRuleset").klog("Response Structure: ")
/*
 Response Structure:
	undefined
 //engine:unregisterRuleset("myRuleset") does not return anything
*/


installRuleset

Installs ruleset(s) into a pico.  

ParameterDatatypeRequired
<pico_id><string> YES
<rid>string | array

NO

<url><string>NO
<base><string>NO


The "base" key will have a value that contains the domain name where your krl file is located. ex:  "http://raw.githubusercontent.com"

The "url" key will complete the path appended to the base. ex: "/repository1/file.txt"

There are three options provided for a successful install with these parameters:
1) You may provide the "rid" (excluding the "base" and "url" keys) if you know that the ruleset is already registered with the engine.
2) Provide the base and url in their respective parts as described above.
3) Just provide the full url (in the "url" key) where your ruleset is located, leaving the "base" undefined or as an empty string.

Do not provide the "rid" key if you want to retrieve the krl file from a remote repository (just provide the "base" and "url" keys). If you provide the "rid" key at all, this function will assume the ruleset is already registered with the engine and will simply throw an error if it is not found, ignoring the "base" and "url" as if they were not submitted. If the "base" and "url" are provided, then the krl file will be registered to the engine (if not already) and then installed on the pico with the given "pico_id".

intall ruleset
response = engine:installRuleset( ent:id, "wrangler" );
response = engine:installRuleset( ent:id, ["wrangler","Pds"] );
response = engine:installRuleset( ent:id ) with base = <base> and url = <url>;
/*
 Response Structure:
	"myRuleset"
 Simply returns the rulesetID as a string. If you passed multiple rids it will return the list of rids installed. 
*/


uninstallRuleset

uninstall a ruleset from a pico.  

ParameterDatatypeRequired
<pico_id><string>YES
<rid>string | array

YES

This does not return anything

listAllEnabledRIDs

List all enabled ruleset ids. No parameters are given.

intall ruleset
response = engine:listAllEnabledRIDs();
/*
 Response Structure:
	["io.picolabs.pico", "io.picolabs.logging"]
*/


describeRuleset

Given a ruleset id, get more information about it.

ParameterDatatypeRequired
<rid><string>YES


intall ruleset
response = engine:describeRuleset("io.picolabs.hello_world");
/*
 Response Structure:
    {
        "rid": "io.picolabs.hello_world",
        "src": "ruleset io.picolabs.hello_world{ ...<cut for brevity> ... }",
        "hash": "a096f2f3bfbd63e54bf4f39081814dbc895f3f003ae9918dbe24aec8acc097b9",
        "url": "https://raw.githubusercontent.com/Picolab/node-pico-engine-core/master/test-rulesets/hello-world.krl",
        "timestamp_stored": "2017-05-17T21:31:21.663Z",
        "timestamp_enable": "2017-05-17T21:31:21.663Z",
        "meta": {
            "name": "Hello World",
            "description": "\nA first ruleset for the Quickstart\n    ",
            "author": "Phil Windley"
        }
    }
*/
  • No labels