Skip to content

Remove Device Dependency in Logging Script #47

@anushadatar

Description

@anushadatar

Quite a few errors/pockets of unreliability seem to arise from the fact that we currently rely on a synchronous and somewhat precisely defined set of operations within the log_and_switch function: we get some data from the MCPC, then we check to see if it's time to switch the valve (and if it's time we kick that off). When then sleep for a while (dependent on the pre-configured sampling period) and then run this process again. As a result, if we miss the reading (as is sometimes the case over the MCPC serial interface), we get caught in a pretty unfortunate reset loop that causes failures for both accurate logging and switching.

While it's likely I wont be the one to implement this in full (and sincerely hope that whoever does take this on feels free to do what they think is best), I would propose that using two threads is potentially the best way to do this. The other (also probably super valid) way to do this would be to run two separate python programs straight from systemd and either very carefully update the same file or have two separate files with matched timestamps (i.e. a "valve position" and "raspi timestamps" file and a
"cpc data" and "raspi timestamp" file).

The threaded approach would likely be super simple. I think that we'd want to kick off a single thread that continually logs data from the CPC to a file at some sampling interval, and we want to kick off another single thread that continually checks if its time to switch the valve and moves accordingly. This would be especially great if it could be robust to cases where we don't have one of the devices running; if we could figure it out at runtime and only run the code we need, we avoid many problematic error paths.

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