wether station protocol
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.

__init__.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import config
  4. import logging
  5. import socket_protocol
  6. import envsens
  7. logger = logging.getLogger('APP')
  8. class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
  9. # EXECUTE_REQUESTs
  10. CURRENT_ENVDATA = 0
  11. class my_server_protocol_tcp(my_base_protocol_tcp):
  12. def __init__(self, comm_instance, envsens, secret=None):
  13. socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
  14. self.envsens = envsens
  15. self.register_callback(self.SID_READ_REQUEST, self.CURRENT_ENVDATA, self.rd_temperature)
  16. def rd_temperature(self, msg):
  17. return self.STATUS_OKAY, self.envsens.get_env_data()
  18. class my_client_protocol_tcp(my_base_protocol_tcp):
  19. START_ROUTINE_DATA_IDS = []
  20. def __init__(self, comm_instance, secret=None):
  21. socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
  22. self.register_callback(self.SID_READ_RESPONSE, self.CURRENT_ENVDATA, self.read_current_envdata)
  23. def __authentificate_process_feedback__(self, msg):
  24. if msg.get_data() is True:
  25. print("The client is authentificated.")
  26. else:
  27. print("AUTHENTIFICATION ERROR")
  28. return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
  29. def read_current_envdata(self, msg):
  30. if msg.get_status() == self.STATUS_OKAY:
  31. env_data = msg.get_data()
  32. print("Temperature: %6.1f °C" % env_data[envsens.KEY_TEMPERATURE])
  33. print("Humidity: %6.1f %%" % env_data[envsens.KEY_HUMIDITY])
  34. return self.STATUS_OKAY, None
  35. else:
  36. print('No environmental data received!')
  37. return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None