#!/usr/bin/env python3
import minimalmodbus
import sensor
import time

addr = [103, 104, 105, 106, 107, 108, 110]
baud = 19200
output_file = 'log'

while True:
    for a in addr:
        s = sensor.Sensor(address=a, baudrate=baud)
        values = f'{time.time():.2f} '
        for reg_name, reg_number in sensor.Sensor.input_registers.items():
            # print(f'reading {reg_name} {reg_number}')
            try:
                values += f'{int(s.read_register(reg_number))} '
            except minimalmodbus.IllegalRequestError:
                pass
        values += '\n'
        with open(f'log_{a}', 'a+') as f:
            f.write(values)
    time.sleep(10)
