1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
-
- import config
- import logging
- import socket_protocol
-
- import envsens
-
- logger = logging.getLogger('APP')
-
-
-
-
- class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
- # EXECUTE_REQUESTs
- CURRENT_ENVDATA = 0
-
-
- class my_server_protocol_tcp(my_base_protocol_tcp):
- def __init__(self, comm_instance, envsens, secret=None):
- socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
- self.envsens = envsens
- self.register_callback(self.SID_READ_REQUEST, self.CURRENT_ENVDATA, self.rd_temperature)
-
- def rd_temperature(self, msg):
- return self.STATUS_OKAY, self.envsens.get_env_data()
-
-
- class my_client_protocol_tcp(my_base_protocol_tcp):
- START_ROUTINE_DATA_IDS = []
-
- def __init__(self, comm_instance, secret=None):
- socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
- self.register_callback(self.SID_READ_RESPONSE, self.CURRENT_ENVDATA, self.read_current_envdata)
-
- def __authentificate_process_feedback__(self, msg):
- if msg.get_data() is True:
- print("The client is authentificated.")
- else:
- print("AUTHENTIFICATION ERROR")
- return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
-
- def read_current_envdata(self, msg):
- if msg.get_status() == self.STATUS_OKAY:
- env_data = msg.get_data()
- print("Temperature: %6.1f °C" % env_data[envsens.KEY_TEMPERATURE])
- print("Humidity: %6.1f %%" % env_data[envsens.KEY_HUMIDITY])
- return self.STATUS_OKAY, None
- else:
- print('No environmental data received!')
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|