Wednesday, August 14, 2019

python

Here is my  python script. Let me know if you have any ideas why it crashes when log_data() is called?

import time
import serial
import smtplib

from email.message import EmailMessage

def log_data(filename, line):
    file_handle = open(filename, 'a+')
    file_handle.write(line)
    file_handle.close()


print('Hello World!')

ser = serial.Serial(
    '/dev/ttyAMA0',
    baudrate=57600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS)

time.sleep(.1)

try:
    ser.write('H\r')
    time.sleep(.25)
    ser.write('2\r')
    time.sleep(.25)
    ser.write('6\r')
    ser.reset_input_buffer()
    kludge = 0
    while True:
        data = ser.read_until('\n', 120)
        if kludge > 2 and len(data) > 12:
            log_data('log.txt', data)
            parse = data.split()
            print(parse[0]
                  + ' ' + parse[1]
                  + ' Amps ' + parse[8]
                  + ' ~ ' + parse[9]
                  + ' Volts ' + str(int(parse[10]) * 9.0 / 5 + 32)
                  + ' ~ ' + str(int(parse[11]) * 9.0 / 5 + 32)
                  + ' degF')
        kludge = kludge + 1

except BaseException:

    # email logged data before quitting
    print("Emailing data...")
    textfile = 'log.txt'
    with open(textfile) as fp:
        # Create a text/plain message
        msg = EmailMessage()
        msg.set_content(fp.read())

    msg['Subject'] = 'The contents of %s' % textfile
    msg['From'] = 'chrisdarilek@gmail.com'
    msg['To'] = 'chrisdarilek@gmail.com'

    username = 'chrisdarilek@gmail.com'

    # Send the message via our own SMTP server.
    s = smtplib.SMTP('smtp.gmail.com:587')
    s.starttls()
    s.login(username, password)
    s.send_message(msg)

    s.quit()
    print('Blow up the spacestation!')


finally:
    ser.close()
    pass

Tuesday, August 13, 2019

pi

I found a use for an old Raspberry Pi I had. I paired it with a small LCD display and wrote a Python script to poll the BMS for battery data.
















I added WiFi to it and now I can SSH into it from my phone to monitor my charge without having to go outside.




















My goal is to have the Pi write the data to a file and email it to me when it detects WiFi.

heat

It is getting hot this summer. The AC is working like a champ. I've run out of charge a handful of times over the past 6 years. Each time it was due to my charger turning Off due to high temperature. The model I have appears to need to be reset to recover from this condition. However, if I don't pay attention I do not notice that I'm heading out with less than full charge.

I picked up a Manzanita Micro PFC20 charger with forced air cooling. It's the green box at the bottom of this picture. The previous charger only had fins for cooling.
















Sure enough, this charger overheats as well. At least it continues to charge, only at a lower rate. The BMS is wired to give it the Off signal when charge is complete.

My water cooled motor controller is overheating as well. I may need a bigger radiator.
















My battery has been at 120 degF by the time I get home from work lately.