Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env_sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ SLEEP_DATA_PATH=/path/to/sleep/data
DEBUG=False
OWL=False
VIDEO_PATH=/path/to/video
HATCH_IP=192.168.HATCH.IP
HATCH_IP=192.168.HATCH.IP
CAM_STREAM_URL=192.168.1.100:554/h264Preview_01_sub
7 changes: 7 additions & 0 deletions .env_sample_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SLEEP_DATA_PATH=/usr/app/babysleepcoach
DEBUG=False
OWL=False
VIDEO_PATH=/usr/app/babysleepcoach/video
HATCH_IP=192.168.HATCH.IP
CAM_STREAM_URL=192.168.1.100:554/h264Preview_01_sub
REACT_APP_BACKEND_URL=http://10.0.0.2:7081
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ build
!*.ipynb
!requirements.txt
!.env_sample
!.env_sample_docker
!dockerfile
!start_docker.sh
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ And you'll probably get a warning about the app trying to boot on port `80`. You
You'll need to update some paths and IPs in the code.
<br/><br/>
## Someone send me proof you got it all running.

<br/><br/>
## Docker
It is also possible to install the app into a docker container.
Clone the repository. Navigate to the path and build the docker image.
```
docker image build -t babysleepcoach .
```
Run the container (adjust the ports, URLs and path).

With an environment file (for the .env file see env_sample_docker):
```
docker run -d -p7080:80 -p7081:8000 --env-file .env --name babysleepcoach babysleepcoach
```

Or with the parameters direct via command line:
```
docker run -d -p7080:80 -p7081:8000 -e REACT_APP_BACKEND_URL=URL_OF_THE_DOCKER_CONTAINER:7081 -e CAM_STREAM_URL=rtsp://user:password@URL_OF_CAMERA:554/stream1 -e DEBUG=False -e OWL=False -e HATCH_IP=127.0.0.1 -v /PATH_TO_SLEEP_LOGS_ON_HOST/sleep_logs.csv:/usr/app/babysleepcoach/sleep_logs.csv --name babysleepcoach babysleepcoach
Comment thread
vanseforge marked this conversation as resolved.
```

The frontend can be accessed via http://URL_OF_THE_DOCKER_CONTAINER:7080 (or the port you wrote in the run command).

21 changes: 21 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#Deriving the latest base image
FROM node:slim

WORKDIR /usr/app/babysleepcoach

RUN mkdir -p video

#Copy all files in the container
COPY . .

# Install required packages
RUN apt-get update && apt-get install python3-pip libgl1 libglib2.0-0 -y
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

RUN cd webapp && yarn install

ENV SLEEP_DATA_PATH=/usr/app/babysleepcoach
ENV VIDEO_PATH=/usr/app/babysleepcoach/video

CMD ["./start_docker.sh"]
Comment thread
vanseforge marked this conversation as resolved.
9 changes: 4 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def live(self, consumer_q):
w = 800

if img.shape[0] > 1080 and img.shape[1] > 1920: # max res 1080p
img = maintain_aspect_ratio_resize(img, width=self.frame_dim[0], height=self.frame_dim[1])
img = maintain_aspect_ratio_resize(self=self, image=img, width=self.frame_dim[0], height=self.frame_dim[1])

img_to_process = img[y:y+h, x:x+w]

Expand Down Expand Up @@ -545,10 +545,9 @@ def start_server():

def receive(producer_q):
print("Start receiving frames.")
cam_ip = os.environ['CAM_IP']
cam_pw = os.environ['CAM_PW']
connect_str = "rtsp://admin:" + cam_pw + "@" + cam_ip
connect_str2 = connect_str + ":554" + "//h264Preview_01_sub" # this might be different depending on camera used

cam_stream_url = os.environ['CAM_STREAM_URL']
connect_str = cam_stream_url

os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;tcp' # Use tcp instead of udp if stream is unstable
c = cv2.VideoCapture(connect_str)
Expand Down
5 changes: 5 additions & 0 deletions start_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

python3 main.py &
cd /usr/app/babysleepcoach/webapp
yarn start
4 changes: 2 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const createCrazyCircles = (events, forecast) => {
const offset = 50;

const img = new Image();
img.src = "http://this_device_ip:8000//absolute_path_to_project_dir/webapp/public/baby_face_192.png";
img.src = process.env.REACT_APP_BACKEND_URL + "/webapp/public/baby_face_192.png";
img.addEventListener("load", (e) => {
context.save();
context.beginPath();
Expand Down Expand Up @@ -371,7 +371,7 @@ const processSleepLogs = async (forecast) => {

const file = forecast ? 'sleep_logs_forecasted' : 'sleep_logs';
// Request sleep log data from HTTP server on the device (somewhere on LAN) which is running with sleep tracking service
const sleepLogs = await d3.csv(`http://ip_address_of_device_running_sleep_tracker:8000/path_on_device_to_sleep_log_csv_file/${file}.csv`);
const sleepLogs = await d3.csv(process.env.REACT_APP_BACKEND_URL + `/${file}.csv`);

// convert timestamps to date objects
sleepLogs.forEach((d) => {
Expand Down