![]() |
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||
|
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||
|
Inhaltsverzeichnissdo:interface:jsonsvn://svn.ed-solutions.de/e-design/python/pysdo/trunk/interfaces/json settings
implemented interface functions/methods
request / response structurerequestmethod = get|set|invoke|list id = <int> params = uri = <string> data = <object> responseresult = <object> error = <object> id = <int> transport typesHTTPHTTP 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. examplerequestPOST / 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"}}} responseHTTP/1.1 200 OK Content-length: 35 Content-type: text/html {"result":"12345","id":1,"error":0} ... {"id": 1, "result": true, "error": null} example / pythonimport 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 / UNIXUnlike 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. examplerequest{"method":"get","id":1,"params":{"uri":"_core/runtime"}}\n response{"result":"12345","id":1,"error":0}\n php clientsvn://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 |
|||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|
|
![]() |
|||||||||||||||||||||||||||||||||||||||||||||
![]() |
Copyright 2021, e-design / Alexander Krause |