jsonrpc get digital input
-
Using python an jsonrpc I can read the digital Input.
But it works only when the Unipi-Control-Panel is running in a browser.Without UniPi-Control-Panel I always get the value 0, without an error.
Setting he digital Outputs works in both cases.
-
That is very odd! There have been some recent changes to the way Tornado handles subroutines, which should be fixed in the latest Github Master version, but they do not manifest in this way.
Could you post the code where you call the RPC procedure, and perhaps some information regarding which image you use?
-
Hi Thomas
atached my code:
Import jsonrpclib
s = jsonrpclib.Server('http://localhost:8088/rpc')
st = Server.input_get_value("1_01")
print("result :", st)My tests where:
- start my Programm without loaded Webpage, result is always 0
2)start Webpage - start program again, result is 0 or 1 depending on DI1 is set or not. Ist working
- Close the Webpage while DI1 is set
- now result is 1, independed of DI1
So it looks that the actual state of DI1 is stored
- start my Programm without loaded Webpage, result is always 0
-
I cannot observe the behavior you describe with the latest image and your code (note that I had to decapitalise "Import" to "import" on line 1 and change "Server" to "s" on line 3).
python rpctest.py
('result :', 0)
python rpctest.py
('result :', 0)
python rpctest.py
('result :', 1)
python rpctest.py
('result :', 0)
python rpctest.py
('result :', 1)
--- At this point I closed the web interface ---
python rpctest.py
('result :', 1)
python rpctest.py
('result :', 0)
python rpctest.py
('result :', 1)This is really terribly awkward. I will try to do some more detailed testing in a few hours.
-
Hi Thomas,
that is funny.
I had tested this with an older Installation based on evok 1.0With the new Image it works!
But if I add
s.relay_set("1_01",1)
to my program I get the message:
Traceback (most recent call last):
File "jhtest2.py", line 5, in <module>
s.relay_set("1_01",1)
File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 288, in call
return self.__send(self.__name, args)
File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 239, in _request
return response['result']
TypeError: 'NoneType' object has no attribute 'getitem' -
Hi Thomas,
I found the Problem in an old Forum Topic from october 2015.
With a modification of jsonrpclib.py it works.
One last question.
Is it possible for you to create an Image with a full raspian strech and only the lite Version
Best regards
Jürgen
-
@Juergen
We cannot provide a full image as it is not fully compatible with our custom drivers. Installing EVOK manually according to the github instructions does not use these drivers though, and as such can be used with Raspbian Stretch full.Keep in mind that running a heavy load on the RPi CPU can cause the device to respond more slowly or less reliably.
-
Ok,
I use your image
-
Hi Thomas,
if I start my program
import jsonrpclib
s=jsonrpclib.Server('http://localhost:8080/rpc')
re="1_01"
s.relay_set("1_01",0)
s.relay_get("1_01")
s.relay_set("1_01",1)
spstatus=s.input_get_value('1_01')
print("sp:", spstatus)It works, I can set the relay and also read the DI, but I found the following error:
relay_set
[I 180314 17:41:14 web:2063] 200 POST /rpc (::1) 4.82ms
[E 180314 17:41:14 concurrent:129] Future exception was never retrieved: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1069, in run
yielded = self.gen.send(value)
File "/usr/local/lib/python2.7/dist-packages/tornadorpc_evok/base.py", line 195, in post
self.finish(response_text)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 962, in finish
raise RuntimeError("finish() called twice")
RuntimeError: finish() called twice
relay_set
[I 180314 17:41:14 web:2063] 200 POST /rpc (::1) 49.89ms
[E 180314 17:41:14 concurrent:129] Future exception was never retrieved: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1069, in run
yielded = self.gen.send(value)
File "/usr/local/lib/python2.7/dist-packages/tornadorpc_evok/base.py", line 195, in post
self.finish(response_text)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 962, in finish
raise RuntimeError("finish() called twice")
RuntimeError: finish() called twice
input_get_value
[I 180314 17:41:14 web:2063] 200 POST /rpc (::1) 45.27msMaybee this could help you with my other problem
-
This is a known issue with some older versions of EVOK, you can use the fix from https://github.com/UniPiTechnology/evok/commit/a19b057ffc3281b1ca807b66bb4c60e0cd62956a (only thing needed is to uncomment one line). I believe that this should be fixed on the newer images - is it not?
It occurs because an update to the Tornado-RPC library we are using broke compatibility, though thankfully only in a minor way.
-
Hi Thomas,
now it works without an error.
I used the the Image from 9. of march.
You should also modify /usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py
to avoid the error "getitem" I postd 3 days ago.1- sudo nano /usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py
2- Press "Strg + w" to search for "return response['result']"
3- edit
def _request(self, methodname, params, rpcid=None):
request = dumps(params, methodname, encoding=self.__encoding, rpcid=rpcid, version=self.__version)
response = self._run_request(request)
check_for_errors(response)
return response['result']to
def _request(self, methodname, params, rpcid=None):
request = dumps(params, methodname, encoding=self.__encoding,
rpcid=rpcid, version=self.__version)
response = self._run_request(request)
check_for_errors(response)
if response == None:
return response
else:
return response['result']5- Press "Strg + x" to exit
6- FinishThank you very much
Jürgen
-
I'm surprised the
check_for_errors(response)
line doesn't catch it. Either way thanks for the fix, we'll include it in the next commit!
Happy to hear that it works for you now.