overthesun / simoc-sam

Back-end system to support SIMOC Live air quality monitor sensor array as used at the SAM Mars habitat analog.
https://samb2.space/
2 stars 1 forks source link

Here is a revised set of scripts for reading live sensor data #3

Closed GregRRoss closed 2 years ago

GregRRoss commented 2 years ago

I looked at your comments on my commit here: https://github.com/GregRRoss/simoc-sam/commit/cc1c7b2179063af3f57ca8423d3b918f1b22998e

This is a new branch. I started by doing a commit to rename the file mocksensor.py to sensor.py Then I did a new commit where the contents of sensor.py were altered to allow either fake or live data to feed into it. This avoids repeated code like I had in the previous commit when I duplicated fakesensor.py as the starting point for my live data script which was nearly identical except for a couple of spots.

To run the live sensor, you just run sensor.py 8081 live If 'live' is omitted, it starts a fake sensor as before.

I updated the readme and tmux.sh so that it still works with the new file names. I tested the ./tmux.sh and it still works

I had to change the text format in the javascript file as well as in the python files because on the javascript side when running a live sensor it was reporting temperatures with maybe a dozen decimal points which was too much, and on the python side it was truncating all values to the nearest number. So I made the initial values into floating points and changed the print statement on the python side to use the same basic formatting as the javascript side.

ezio-melotti commented 2 years ago

In https://github.com/overthesun/simoc-sam/issues/1#issuecomment-994098011 I described what I want to implement next. I think I'll just look into it once I get the actual sensor set up and can do some testing locally, so you don't need to update this PR for now.

GregRRoss commented 2 years ago

I just added a new commit to add argparse, so it can run by using the --live flag. The first parameter is still set to be a positional parameter for the port. I also fixed an error that was being thrown by the fake data being an int and the live data being a float.

I'm not sure why, but I also had to change the cors_allowed_origins to port 8081 in the siosever.py. I am not sure why because it was working before when it was set to 8080. I was getting some error in tmux about 8081 not being an allowed port.

Also, I merged the latest version of the master branch into this one. Maybe that had something to do with it?

GregRRoss commented 2 years ago

Ah, yes it was the previous pull request that was merged I think. The last merged request ( https://github.com/overthesun/simoc-sam/pull/4 ) added: cors_allowed_origins='http://localhost:8080' to allow connection with simoc-web but it seemed to have broken the alternate 8081 front end, so I fixed it by making sure the list has both 8080 and 8081 as allowed origins.

Now to run the live mode you will type sensor.py 8081 --live

The only difference is the -- before live which is necessary for an argparse optional argument. The port remains optional also and will still revert to the port 5000 specified in the script if not provided, although it is a positional argument. I did it this way to retain the same functionality as before.

ezio-melotti commented 2 years ago

I'm just going to merge this and create a new PR with some refactoring, following the architecture described in #1 .

GregRRoss commented 2 years ago

I have improved the argparse code per suggestions.