Skip to content

Failure to read data yields a 0 instead of error or NoneType #23

@SWalt567

Description

@SWalt567

I currently have 2 max3155 thermocouples amps on a raspberry pi. 1 amp is fully wired and has no thermocouple (intentional) and another has a thermocouple and faulty wiring on the MISO and SCLK pin (intentional) for the purpose of testing failures to read temperature data.

I'm using a script with an up-to-date version of this repo to record the temperature, expecting an error/None but instead getting a 0.

Script for reference:
`
class thermocouple():
""" thermocouple class

thermocouple class creates a connection to the probe,
and houses a generator that when called, returns/yields datetime,
temperature, and a status message. Under circumstances when
the thermocouple shorts, or has any other error, the message will contain
said error and flag the data so it wont be graphed.

ARGS:
    probe_id: each probe has its own CS/SS (chip select/slave select)
    pin, the probe_id will tell the class which CS/SS pin to assign it to
    spi:
    running:
"""
def __init__(self, probe_id, spi=None, running=False):

    if spi == None:
        spi = busio.SPI(board.D11, MOSI=board.MOSI)
    # create property to later return to other thermocouples
    self.__spi = spi

    # self.__cs = digitalio.DigitalInOut(board.D6) #previous solution

    cs_dict = {'probe1': digitalio.DigitalInOut(board.D5),
               'probe2': digitalio.DigitalInOut(board.D6),
               'probe3': digitalio.DigitalInOut(board.D13),
               'probe4': digitalio.DigitalInOut(board.D19)}

    try:
        self.__cs = cs_dict[probe_id]
        #print(probe_id+" 5" if probe_id=='probe1' else " 6")
    except KeyError:
        logger.critical('{} not found in cs_dict'.format(probe_id))
        # exit??

    # construct thermocouple object
    self.thermo = self.__thermo(self.__spi, self.__cs)
    if __name__ == "__main__":
        logger.debug("created {}".format(probe_id))

def __thermo(self, spi, cs):
    return adafruit_max31855.MAX31855(spi, cs)

@property
def spi(self):
    return self.__spi

@spi.setter
def spi(self, spi):
    self.__spi = spi
    self.thermo = __thermo(self.__spi, self.__cs)

def get_temperature(self):  # asks for current temp of thermocouple
    """
    yield `probe.temperature` (might have to be a return)
    """
    return self.thermo.temperature

def get_data(self):
    """
    call `temperature()` if possible

    get datetime,temperature,msg (msg would be "ok" or None)

    catch `RuntimeError` and yield None,msg

    if return_msg is True, return the two things
    """
    msg = 'ok'  # status message that will be returned when there is no error
    try:
        temp = self.get_temperature()
    except RuntimeError as m:  # calls for temperature and catches short errors instead of stopping
        msg = m
        temp = None
    utc = datetime.datetime.now()
    utc = utc.replace(tzinfo=from_zone)
    local = utc.astimezone(to_zone)
    return local, temp, msg

def yield_data(self):
    yield self.get_data()

`

Output after running:

0.0 probe1, DT: 2021-04-01 11:28:11.490445-08:00 T: 0.0 MSG: 'ok' 0.0 probe2, DT: 2021-04-01 11:28:11.493411-08:00 T: 0.0 MSG: 'ok'

I currently can't find any reason why I'm getting this output. Any feedback is appreciated :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions