Commit 995c2c8b authored by Nelso Jost's avatar Nelso Jost

NEW: sync RTC command

parent 5da41416
......@@ -21,6 +21,8 @@ help:
@ echo " supervisor daemon tool (requires root)"
@ echo ""
@ echo " make tail-exec -- Follow the logger's execution.log"
@ echo ""
@ echo " make sync-rtc -- Send the current system time to the board"
apt-install:
sudo apt-get install python python3-pip supervisor
......@@ -54,3 +56,6 @@ undeploy:
tail-exec:
tail -F logs/execution.log
sync-rtc:
${VENV}/bin/python${PYVER} run.py --syncrtc
......@@ -281,6 +281,40 @@ class Meteorologger:
logging.debug("serial closed")
return None
def sync_rtc(self, port_index=None):
if isinstance(port_index, int):
serial_port = self.SERIAL_PORTS[port_index]
else:
serial_port = self.SERIAL_PORTS[0]
# if present, the board will be reseted
ser = serial.Serial(serial_port, self.CFG['ARDUINO']['BAUD_RATE'],
timeout=self.SERIAL_READ_TIMEOUT, xonxoff=True)
print("Serial open <port='{}', baudrate={}>"
.format(ser.port, ser.baudrate))
time.sleep(self.BOARD_RESET_TIMEOUT)
ser.flush()
command_ser = 'setrtc' + self.SERIAL_CSV_SEP + \
datetime.now().strftime('%Y-%m-%d-%H-%M-%S'
.replace('-', self.SERIAL_CSV_SEP))
result = ser.write(bytes(command_ser, 'utf8'))
print("sent: '{}' ({} bytes)".format(command_ser, result))
time.sleep(self.CFG['ARDUINO']['RESPONSE_DELAY'])
result_line = ser.readline()
print("read: {} ({} bytes)".format(result_line, len(result_line)))
ser.close()
def setup_logging(self):
if self.verbose:
# logging.basicConfig(
......
......@@ -2,4 +2,7 @@ from app import Meteorologger
import sys
if __name__ == '__main__':
Meteorologger(verbose = False if '-s' in sys.argv else True).run()
if '--syncrtc' in sys.argv:
Meteorologger().sync_rtc()
else:
Meteorologger(verbose = False if '-s' in sys.argv else True).run()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment