Skip to content

Commit

Permalink
Merge pull request #2 from CDRV/dev
Browse files Browse the repository at this point in the history
Main merge for 1.0.1 release.
  • Loading branch information
SBriere authored Nov 9, 2021
2 parents 9c72b1f + 1d48e34 commit 5c59399
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

config_man = ConfigManager()

version_string = '1.0.0'
version_string = '1.0.1'
2 changes: 1 addition & 1 deletion libs/hardware/PiHubHardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def wait_for_internet_infinite():
# No internet connection... Try to reboot the cellular network
PiHubHardware.reset_cellular_network()
time.sleep(60) # Wait 60 seconds to see if network is coming back online or not
logging.info('Internet is back. All is fine.')
logging.info('Internet is back. All is fine.')
18 changes: 14 additions & 4 deletions libs/servers/BedServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import threading
import os
import socket


class BedServer(BaseServer):
Expand Down Expand Up @@ -63,7 +64,7 @@ def run(self):
logging.critical(str(e))
return

self.server.timeout = 10.0
# self.server.timeout = 10.0
self.is_running = True
logging.info("BedServer started on port " + str(self.port))
try:
Expand Down Expand Up @@ -115,6 +116,7 @@ def handle(self) -> None:

# Loop to transfer data (2 bytes at a time - UINT16 are read from RAM and transmitted by ESP
logging.info('Starting data transfer...')
self.request.settimeout(10)
while self.connection:
try:
d1minidata = self.request.recv(2) # self.rfile.read(2)
Expand All @@ -123,9 +125,16 @@ def handle(self) -> None:
else:
x = int.from_bytes(d1minidata, byteorder='little', signed=False)
file.write(str(x) + "\t")
except TimeoutError as e:
self.rfile.close()
except (socket.timeout, TimeoutError, ConnectionResetError, ConnectionAbortedError, ConnectionError):
logging.error("Timeout receiving data.")
# self.request.settimeout(1.0)
# while 1:
# try:
# self.request.recv(1) # Clear all pending bytes, if available.
# except (TimeoutError, ConnectionResetError, ConnectionAbortedError, ConnectionError):
# break
self.rfile.close()
# logging.error("Remote stream closed")
break
logging.info("Data transfer complete.")
file.write("\n")
Expand All @@ -136,7 +145,8 @@ def handle(self) -> None:
file_server_path = file_server_directory + "/" + str(datetime.now().date()) + ".txt"
temp_file = self.data_path + "/local_only/" + str(greetings) + "/tempData.txt"
file_transferred_directory = self.data_path + "/transferred/" + str(greetings)
logging.info("try to create " + file_transferred_directory + str(not os.path.isdir(file_transferred_directory)))
logging.info("Try to create " + file_transferred_directory + ", dir exists = " +
str(not os.path.isdir(file_transferred_directory)))
if not os.path.isdir(file_transferred_directory):
makedirs(file_transferred_directory)
file_transferred_location = file_transferred_directory + "/" + str(datetime.now().date()) + ".txt"
Expand Down
13 changes: 13 additions & 0 deletions piHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
##################################################
import time
import logging
import sys

from libs.config.ConfigManager import ConfigManager
from libs.servers.BedServer import BedServer
Expand All @@ -14,6 +15,18 @@

from Globals import version_string


def handle_exception(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return

logging.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))


sys.excepthook = handle_exception


if __name__ == '__main__':
# Logging module
################
Expand Down

0 comments on commit 5c59399

Please sign in to comment.