A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. import time
  2. from pyad2 import AD2
  3. from pyad2.devices import SocketDevice
  4. def main():
  5. """
  6. Example application that opens a device that has been exposed to the network
  7. with ser2sock and SSL encryption and authentication.
  8. """
  9. try:
  10. # Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
  11. ssl_device = SocketDevice(interface=('localhost', 10000))
  12. # Enable SSL and set the certificates to be used.
  13. #
  14. # The key/cert attributes can either be a filesystem path or an X509/PKey
  15. # object from pyopenssl.
  16. ssl_device.ssl = True
  17. ssl_device.ssl_key = 'cert.key' # Client private key
  18. ssl_device.ssl_certificate = 'cert.pem' # Client certificate
  19. ssl_device.ssl_ca = 'ca.pem' # CA certificate
  20. device = AD2(ssl_device)
  21. # Set up an event handler and open the device
  22. device.on_message += handle_message
  23. device.open()
  24. time.sleep(1) # Allow time for SSL handshake to complete.
  25. device.get_config()
  26. # Wait for events.
  27. while True:
  28. time.sleep(1)
  29. except Exception, ex:
  30. print 'Exception:', ex
  31. finally:
  32. device.close()
  33. def handle_message(sender, *args, **kwargs):
  34. """
  35. Handles message events from the AD2.
  36. """
  37. msg = kwargs['message']
  38. print sender, msg.raw
  39. if __name__ == '__main__':
  40. main()