Hi,
Im new to python
I have this code found of youtube, it works fine and print the temperature in a loop (until I do CTRL C)
I have tried this code (just print it once, no email yet):
/Martin
Im new to python
I have this code found of youtube, it works fine and print the temperature in a loop (until I do CTRL C)
#!/usr/bin/python
import sys, time, signal, serial, datetime
from socket import *
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
#parity=serial.PARITY_ODD,
#stopbits=serial.STOPBITS_TWO,
#bytesize=serial.SEVENBITS
)
ser.isOpen()
while True:
ser.write('T\r')
time.sleep(1)
serial_input = ''
while ser.inWaiting() > 0:
serial_input += ser.read(1)
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print now + ", " + serial_input
ser.close()
sys.exit()But If I want to print it only once and optional also sent it by email?I have tried this code (just print it once, no email yet):
#!/usr/bin/python
import sys, time, signal, serial, datetime
from socket import *
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
#parity=serial.PARITY_ODD,
#stopbits=serial.STOPBITS_TWO,
#bytesize=serial.SEVENBITS
)
ser.isOpen()
ser.write('T\r')
serial_input = ''
serial_input = ser.read(1)
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print now + serial_input
ser.close()
sys.exit()But it just print the date and time and a " + " no temp - what am I missing?/Martin
