[GLLUG] Reading USB serial port broken
henrik at morsing.cc
Wed Sep 25 09:40:24 UTC 2019
On Tue, Sep 24, 2019 at 09:16:15PM +0100, James Courtier-Dutton wrote:
>Would you be able to post the python script so we can see how you are
>setting up the tty and how you read/write bytes to it?
Sure, little script at the bottom. Looking through this, I have actually managed to solve the problem. Thanks.
I was planning to change the communication from timed to the Arduino saying "READY" and the Python script waiting for "READY" to proceed, but somewhere looking at this, a sleep() after opening the port had disappeared which meant the Python script sent its command too early and they both ended up waiting for each other.
I think the tail command meant the port was already open and the Arduino ready for a command, hance the Python/munin script was flying.
received_data = "begin"
port = serial.Serial('/dev/ttyACM0', 115200, rtscts=0, dsrdtr=True, timeout=5)
received_data = port.readline()
while received_data != "end":
if re.match("arduino_[a-z]+_temp", received_data):
received_data = port.readline().rstrip('\r\n')
print("graph_title MVHR temperature")
print("arduino_extract_temperature.label Extract temp")
#print("arduino_extract_humidity.label Extract humidity")
print("arduino_feed_temperature.label Feed temp")
#print("arduino_feed_humidity.label Feed humidity")
print("arduino_supply_temperature.label Supply temp")
#print("arduino_supply_humidity.label Supply humidity")
print("arduino_loft_temperature.label Loft temp")
#print("arduino_loft_humidity.label Loft humidity")
rc = sys.argv
rc = ""
if rc == "config":
More information about the GLLUG