From SmartCore Wiki
Jump to: navigation, search

services

The service module is the machine interface into the system

The service module is accessed through a websocket connection, or locally through the PHP the library.

Websocket interface

A connection is established and kept open for the duration of the client process. To establish a service connection, a session must be established, through a regular HTTP request, providing a valid terminal identification.

Services are provided as a request resulting in an asynchronous response. Multiple requests can be send, before a response is received. Do to there asynchronous processing, responses might be received in an undefined order. Identification of the response can be optained by supplying the request a unique string named cmdId. The string it will be returned with the response. Each response, beginning with an acknowledgement of the establishment of the connection, returns a token, that is to be used in the sub sequent request

The request is either an array (core) or a JSON string containing a request array (remote):

Request
service string Name of the requested service module
func string Name of requested function the the service module.
data string or associative array specification of request. (optional)
cmdId string An identification string, assigned by the client, that will be returned in the response. (Used to link responses to requests in RPC)


Service func data
alert red

yellow
green
blue
mute
off

non
command <command> non
datastore post

get
delete

<record>

search string
search string

echo any string any record og string


The response is either an array (core) or a JSON string containing a request array (remote):

Response
reply string Thin of this a the verbal reply to the user like "ok","failed","working", "access denied"
result array (numeric index) Containing associative arrays with the result of the request, if any. (optional)
error string null or an error message.(optional) If a command fails, this the explanation why.
state string State of an interaction.(optional)
html string HTML representation of the state, used in a tile. (optional)
text string A textual representation of the state.(optional) that can be spoken.
cmdId string A copy of request[cmdId]

Alert

Invoke alarm.

Command

This evoke the command interpreter.

command
page service array = ps.cmd(<command>, function callback(response))

or array = ps.service({“service”:”command”,”func”:”<command>"} [, function callback(response)])

core array = services.command(request, function callback(response))
PHP array $response = services("command", string $command)


Example:

 Page service:
 reply = ps.cmd(”/bedroom/ceiling/light on");
 reply = ps.service({service: ”command”, func: ”/bedroom/ceiling/light on"});
 
 Core:
 response = services.command({service: ”command”, func: ”/bedroom/ceiling/light on"}, function callback(response));
 
 PHP:
 $response = services("command", ”/bedroom/ceiling/light on");


Datastore

Get, post or delete data, from the database.


Echo

A test service, that simply returns the request.

echo
page service array = ps.service({service:”echo”, func: <any sting>, data: <any value>} [, function callback(response)])
core array = services.command(request, function callback(response))
PHP array $response = services("echo", string $function, mixed $data)


Example:

 Page service:
 reply = ps.service({service:”echo”, func: ”foo"});
 
 Core:
 response = services.list.echo({service: ”echo”, func: ”foo"}, function callback(response));
 
 PHP:
 $response = services("echo", ”foo");


Error_report

Retrieve/acknowledge or purge error reports

Event

Subscribe/unsubscribe to event notifications, announce events, or list subscribers.


Reaction

Set/get/remove reaction commands, to events.


Serverinfo

Get information about the server

Timer

Set/get/remove timed commands.