Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (43 sloc) 1.48 KB
# coding: utf-8
import os
import logging
import serial
import database
import config
from datetime import datetime
# Plant IDs in the order they are connected to the Arduino
format='%(asctime)s %(levelname)s %(message)s',
config.OUT_FOLDER, 'arduino_serial.log'),
def process_line(line):
# Read a line received via serial and return measurements as list
rv = None
kind = line[:line.index(" ")]
msg = line[line.index(" ") + 1:]
if kind == "status":"Arduino: {}".format(msg))
elif kind == "measurement":"Measured {}".format(msg))
rv = msg.split(",")
return rv
def read_serial():"Connecting to Arduino...")
ser = serial.Serial(config.SERIAL_DEVICE, 9600)
while True:
yield ser.readline().decode('ascii').strip()
def run():
for line in read_serial():
msg = process_line(line)
if msg:
dt =
for i, plant in enumerate(config.PLANTS_CONNECTED):
logging.debug("{}: plant {} value {}".format(
msg, plant, msg[i]))
database.store_measurements(plant, msg[i], dt)
except KeyboardInterrupt:"Closing serial monitor")
if __name__ == "__main__":