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.

49 lines
1.4 KiB

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