def test_run_server(self): with mock.patch.dict( os.environ, { "LAN_SERVER_LOG_FILE": "logger.txt", "LOG_DIRECTORY": self.temp_dir.path, "LAN_PORT": "0000", }, ): with LogCapture() as capture: mock_server = mock.MagicMock() mock_server.return_value.server_forever = mock.MagicMock() mock_handler = mock.MagicMock() runServer(mock_server, mock_handler) capture.check( ("LAN_SERVER_LOG_FILE", "INFO", "Starting server on port: 0"), ("LAN_SERVER_LOG_FILE", "INFO", "Stopping\n"), )
def handleComm(): """ Starts up the CommunicationsPi server and starts listening for traffic """ runServer(handler_class=CommPi)
import os import time from hardware.CommunicationsPi.comm_pi import CommPi from hardware.CommunicationsPi.lan_server import runServer from hardware.CommunicationsPi.lan_client import LANClient from hardware.SensorPi.sense_pi import SensePi if os.environ["PI_TYPE"] == "commPi": print("CommunicationsPi") runServer(handler_class=CommPi) else: print("SensePi") sensePi = SensePi() client = LANClient() while True: temp = sensePi.get_temperature() pres = sensePi.get_pressure() hum = sensePi.get_humidity() acc = sensePi.get_acceleration() orie = sensePi.get_orientation() all = sensePi.get_all() data = [temp, pres, hum, acc, orie, all] for i in data: print(i) try: client.ping_lan_server(i) except Exception as err: print("error occurred: {}".format(str(err)))