Skip to content

Commit

Permalink
Merge pull request #2 from robervalwalsh/develop
Browse files Browse the repository at this point in the history
dev systemctl
  • Loading branch information
robervalwalsh authored Feb 23, 2021
2 parents 7e42bdf + b6eb00f commit e4fd71d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sensor_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def load_sensors ( self, sensors ) :
try:
loaded_sensors.append ( sensor_class ( *sensor_opts ) )
except:
if sensor_name == 'BME680':
add = 'a'
if hex(sensor_opts[1])=='0x77':
add='b'
ctl_name = f'sensor_monitor_{sensor_opts[0]:02d}{add}'
os.system(f'sudo systemctl stop {ctl_name}')
print(f'\033[93mWarning: The sensor {sensor_name}_i2c-{sensor_opts[0]}_{hex(sensor_opts[1])} does not exist!\033[0m')
if len(loaded_sensors) == 0:
print('\033[91mError: No sensor available!\033[0m')
Expand Down
8 changes: 5 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ def signal_handler(signum, frame):
#Handle stop process siginal
signal.signal(signal.SIGINT, signal_handler)

if len(argv) < 2:
exit("Please input a file path.")
if len(argv) < 3:
exit("Please input a file path and a port number.")
if not isfile(argv[1]):
exit("Not a file: %s" % argv[1])

PORT = int(argv[2])

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
print("Listening on port %i" % PORT)
s.listen(10)
while not finish:
conn, addr = s.accept()
print("Got connection from %s:%i" % addr)
#print("Got connection from %s:%i" % addr)
with conn:
try:
f = open(argv[1], "rb")
Expand Down

0 comments on commit e4fd71d

Please sign in to comment.