• Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    jsonrpc get digital input

    Scheduled Pinned Locked Moved Official API - Evok
    12 Posts 2 Posters 6.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Juergen
      last edited by

      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:

      1. start my Programm without loaded Webpage, result is always 0
        2)start Webpage
      2. start program again, result is 0 or 1 depending on DI1 is set or not. Ist working
      3. Close the Webpage while DI1 is set
      4. now result is 1, independed of DI1

      So it looks that the actual state of DI1 is stored

      1 Reply Last reply
      Reply Quote 0
      • T
        TomasKnot
        last edited by TomasKnot

        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.

        1 Reply Last reply
        Reply Quote 0
        • J
          Juergen
          last edited by

          Hi Thomas,

          that is funny.
          I had tested this with an older Installation based on evok 1.0

          With 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'

          1 Reply Last reply
          Reply Quote 0
          • J
            Juergen
            last edited by

            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

            1 Reply Last reply
            Reply Quote 0
            • T
              TomasKnot
              last edited by TomasKnot

              @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.

              1 Reply Last reply
              Reply Quote 0
              • J
                Juergen
                last edited by

                Ok,

                I use your image

                1 Reply Last reply
                Reply Quote 0
                • J
                  Juergen
                  last edited by

                  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.27ms

                  Maybee this could help you with my other problem

                  1 Reply Last reply
                  Reply Quote 0
                  • T
                    TomasKnot
                    last edited by TomasKnot

                    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.

                    1 Reply Last reply
                    Reply Quote 0
                    • J
                      Juergen
                      last edited by

                      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- Finish ;)

                      Thank you very much

                      Jürgen

                      1 Reply Last reply
                      Reply Quote 0
                      • T
                        TomasKnot
                        last edited by TomasKnot

                        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.

                        1 Reply Last reply
                        Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post