sdo:interface:json

svn://svn.ed-solutions.de/e-design/python/pysdo/trunk/interfaces/json

settings

setting name type meaning values transports
net string defines the ip-net where the interface has to listen on default=0.0.0.0 HTTP | TCP
port int TCP/port default=8000 (TCP)
default=8081 (HTTP)
HTTP | TCP
socket int socket file UNIX
uri_offset string links all objects to another URI,
for accessing the objects the user has to supply more URI parts
uri_prefix string adds some URI components to all requests,
thus reducing the users access to possible objects
debug bool print additional debugging information
transport string define the transport the service uses HTTP | TCP | UNIX | ZMQ
default=TCP

implemented interface functions/methods

  • get(uri)
  • set(uri,data)
  • invoke(uri,data)
    for calls with no arguments it's important to not send the 'data' parameter, in this case 'data' becomes of type None and the driver knows that he has to call the function without arguments
  • list(uri)

request / response structure

request

method = get|set|invoke|list
id = <int>
params =
  uri = <string>
  data = <object>

response

result = <object>
error = <object>
id = <int>

transport types

HTTP

HTTP transport does not evaluate the URL nor any header-fields.

The response „Content-type“ will always be „text/html“.

All necessary json-fields are given in the POST data.

For each json-query there has to be one HTTP/POST request.

example

request
POST / HTTP/1.1

{"method":"get","id":1,"params":{"uri":"_core/runtime"}}
POST / HTTP/1.1

{"method":"set","id":1,"params":{"uri":"/daikin_itc/iu_states/0","data":{"OnOff":"0"}}}
response
HTTP/1.1 200 OK
Content-length: 35
Content-type: text/html

{"result":"12345","id":1,"error":0}
...
{"id": 1, "result": true, "error": null}

example / python

import httplib, urllib
headers = {
	'Content-type': 'text/html',
	'Accept': 'text/plain'
}
 
conn = httplib.HTTPConnection("ss:8081")
conn.request(
	'POST',
	'',
	'{"method":"get","id":1,"params":{"uri":"_core/runtime"}}',
	headers
)
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
print(data)
conn.close()
erazor@rzr64 ~> python2 python_post.py 
(200, 'OK')
{"id": 1, "result": 7.179051876068115, "error": 0}

TCP / UNIX

Unlike with HTTP there is no additional protocol overhead when using the raw TCP or raw UNIX transport. Different json-queries are divided via a new line character („\n“).

This also means that the first query has to end with the new line character too.

There can be multiple json-queries within the same connection.

example

request
{"method":"get","id":1,"params":{"uri":"_core/runtime"}}\n
response
{"result":"12345","id":1,"error":0}\n

php client

svn://ed-solutions.de/e-design/pub/pysdo/trunk/interfaces/json/client/php

#initialisation and connecting
require_once('lib/jsonrpc-raw-stream.php');
 
$rpc=new SDO_COMM_RPC('10.241.1.49');
#poll example via get-call
while (true) {
	/* uptime, 2 words */
	print_r($rpc->call('get',array('uri'=>'/mb_master/00/04/7536:2/verbose')));
	sleep(0.5);
}
#invoke example
$rpc->call(
        'invoke',
        array(
                'uri'=>'/sites/add',
                'data'=>array('site_id'=>'02030405','host'=>'localhost','port'=>12345,'dsx_password'=>'blub')
        )
);

ZMQ

doc/sdo/interfaces/json.txt · Zuletzt geändert: 2018.03.26 - 09:47 von 127.0.0.1
 
Copyright 2021, e-design / Alexander Krause