Skip to content

Commit

Permalink
v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Jul 18, 2021
1 parent a015a3b commit 7868b5e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ Based on [@noelhibbard's script](https://gist.github.com/noelhibbard/03703f55129
Should work on most x64 systems as well as on some arm-based systems like the Raspberry Pi.
[See here](#armraspberry-pi-support) for instructions to run on arm.

## Changes in v0.3.2
## Changes in v0.4.0

- 🆕 Multi-Factor Authentication Support. [See here](#Multi-Factor-Authentication)
**Upgrading from v0.3.x to v0.4 may require a new docker-compose.yml**

- Combined rtsp-simple server into one container.
- Fixes to allow `network_mode: host` for a completely local stream on linux systems

## Usage

Expand Down Expand Up @@ -105,14 +108,14 @@ environment:

Two-factor authentication ("Two-Step Verification" in the wyze app) is supported and will automatically be detected, however additional steps are required to enter your verification code.

- Echo the verification code directly to `/opt/wyzecam/tokens/mfa_token`:
- Echo the verification code directly to `/tokens/mfa_token`:
```bash
docker exec -it wyze-bridge sh -c 'echo "123456" > /opt/wyzecam/tokens/mfa_token'
docker exec -it wyze-bridge sh -c 'echo "123456" > /tokens/mfa_token'
```
- Mount `/opt/wyzecam/tokens/` locally and add your verification code to a new file `mfa_token`:
- Mount `/tokens/` locally and add your verification code to a new file `mfa_token`:
```YAML
volumes:
- ./tokens:/opt/wyzecam/tokens/
- ./tokens:/tokens/
```


Expand Down
13 changes: 7 additions & 6 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM python:3.9-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install ffmpeg unzip g++ -y && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install requests wyzecam wyze_sdk
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install ffmpeg tar unzip g++ -y && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install requests wyzecam wyze_sdk supervisor
ADD https://github.com/nblavoie/wyzecam-api/raw/master/wyzecam-sdk/TUTK_IOTC_Platform_14W42P1.zip /tmp/tutk.zip
RUN unzip /tmp/tutk.zip -d /tmp/tutk/ && cd /tmp/tutk/Lib/Linux/x64/ && g++ -fpic -shared -Wl,--whole-archive libAVAPIs.a libIOTCAPIs.a -Wl,--no-whole-archive -o libIOTCAPIs_ALL.so && cp libIOTCAPIs_ALL.so /usr/local/lib/ && rm -rf /tmp/*
RUN mkdir -p /opt/wyzecam/tokens
COPY cameras.py /opt/wyzecam/cameras.py
CMD [ "python3", "/opt/wyzecam/cameras.py" ]
ADD https://github.com/aler9/rtsp-simple-server/releases/download/v0.16.4/rtsp-simple-server_v0.16.4_linux_amd64.tar.gz /tmp/rtsp.tar.gz
RUN mkdir -p /app /tokens && tar -xzf /tmp/rtsp.tar.gz -C /app && rm -rf /tmp/*
COPY wyze_bridge.py supervisord.conf /app/
CMD ["supervisord", "-c", "/app/supervisord.conf" ]
11 changes: 6 additions & 5 deletions app/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM arm32v7/python:3.9-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install ffmpeg unzip g++ -y && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install requests wyzecam wyze_sdk
RUN apt-get update && apt-get install ffmpeg tar unzip g++ -y && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install requests wyzecam wyze_sdk supervisor
ADD https://github.com/nblavoie/wyzecam-api/raw/master/wyzecam-sdk/TUTK_IOTC_Platform_14W42P1.zip /tmp/tutk.zip
RUN unzip /tmp/tutk.zip -d /tmp/tutk/ && cd /tmp/tutk/Lib/Linux/Arm11_BCM2835_4.8.3/ && g++ -fpic -shared -Wl,--whole-archive libAVAPIs.a libIOTCAPIs.a -Wl,--no-whole-archive -o libIOTCAPIs_ALL.so && cp libIOTCAPIs_ALL.so /usr/local/lib/ && rm -rf /tmp/*
RUN mkdir -p /opt/wyzecam/tokens
COPY cameras.py /opt/wyzecam/cameras.py
CMD [ "python3", "/opt/wyzecam/cameras.py" ]
ADD https://github.com/aler9/rtsp-simple-server/releases/download/v0.16.4/rtsp-simple-server_v0.16.4_linux_armv7.tar.gz /tmp/rtsp.tar.gz
RUN mkdir -p /app /tokens && tar -xzf /tmp/rtsp.tar.gz -C /app && rm -rf /tmp/*
COPY wyze_bridge.py supervisord.conf /app/
CMD ["supervisord", "-c", "/app/supervisord.conf" ]
18 changes: 18 additions & 0 deletions app/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true
user=root
loglevel=warn

[program:wyze-bridge]
command=python3 /app/wyze_bridge.py
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autostart=true
autorestart=true

[program:rtsp-simple-server]
command=/app/rtsp-simple-server /app/rtsp-simple-server.yml
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
13 changes: 7 additions & 6 deletions app/cameras.py → app/wyze_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class wyze_bridge:
def __init__(self):
print('STARTING DOCKER-WYZE-BRIDGE v0.3.2.2', flush=True)
print('STARTING DOCKER-WYZE-BRIDGE v0.4.0', flush=True)

if 'DEBUG_FFMPEG' not in os.environ:
warnings.filterwarnings("ignore")
Expand All @@ -16,7 +16,7 @@ def env_filter(self,cam):
return True if cam.nickname.upper() in self.get_env('FILTER_NAMES') or cam.mac in self.get_env('FILTER_MACS') or cam.product_model in self.get_env('FILTER_MODEL') or self.model_names.get(cam.product_model) in self.get_env('FILTER_MODEL') else False

def twofactor(self):
mfa_token = '/opt/wyzecam/tokens/mfa_token'
mfa_token = '/tokens/mfa_token'
print(f'MFA Token Required\nAdd token to {mfa_token}',flush=True)
while True:
if os.path.exists(mfa_token) and os.path.getsize(mfa_token) > 0:
Expand All @@ -33,7 +33,7 @@ def twofactor(self):
time.sleep(2)

def authWyze(self,name):
pkl_data = f'/opt/wyzecam/tokens/{name}.pickle'
pkl_data = f'/tokens/{name}.pickle'
if os.path.exists(pkl_data) and os.path.getsize(pkl_data) > 0:
if os.environ.get('FRESH_DATA') and ('auth' not in name or not hasattr(self,'auth')):
print(f'[FORCED REFRESH] Removing local cache for {name}!',flush=True)
Expand Down Expand Up @@ -101,8 +101,9 @@ def start_stream(self,camera):
# bitrate = min([30,60,120,150,240], key=lambda x:abs(x-int(os.environ['QUALITY'][2:])))
bitrate = int(os.environ['QUALITY'][2:])
wyzecam.tutk.tutk.iotc_initialize(tutk_library)
# wyzecam.tutk.tutk.iotc_initialize(tutk_library,udp_port=8285)
wyzecam.tutk.tutk.av_initialize(tutk_library)
wyzecam.tutk.tutk.av_client_set_max_buf_size(tutk_library, 5 * 1024 * 1024)
wyzecam.tutk.tutk.av_client_set_max_buf_size(tutk_library, 5000)
with wyzecam.iotc.WyzeIOTCSession(tutk_library,self.user,camera,resolution,bitrate) as sess:
print(f'{datetime.datetime.now().strftime("%Y/%m/%d %X")} [{camera.nickname}] Starting {res} {bitrate}kb/s Stream for WyzeCam {self.model_names.get(camera.product_model)} ({camera.product_model}) running FW: {sess.camera.camera_info["basicInfo"]["firmware"]} from {camera.ip} "{"P2P mode" if sess.session_check().mode ==0 else "Relay mode" if sess.session_check().mode == 1 else "LAN mode"}" (WiFi Quality: {sess.camera.camera_info["basicInfo"]["wifidb"]}%)...',flush=True)
cmd = ('ffmpeg ' + os.environ['FFMPEG_CMD'].strip("\'").strip('\"') + camera.nickname.replace(' ', '-').replace('#', '').lower()).split() if os.environ.get('FFMPEG_CMD') else ['ffmpeg',
Expand All @@ -118,8 +119,8 @@ def start_stream(self,camera):
'-i', '-',
'-map','0:v:0',
'-vcodec', 'copy',
'-rtsp_transport','tcp',
'-f','rtsp', 'rtsp://rtsp-server:8554/' + camera.nickname.replace(' ', '-').replace('#', '').lower()]
'-rtsp_transport','udp',
'-f','rtsp', 'rtsp://localhost:8554/' + camera.nickname.replace(' ', '-').replace('#', '').lower()]
ffmpeg = subprocess.Popen(cmd,stdin=subprocess.PIPE)
while ffmpeg.poll() is None:
for (frame,_) in sess.recv_video_data():
Expand Down
15 changes: 3 additions & 12 deletions docker-compose.sample.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
version: '3'
version: '3.8'
services:
rtsp-server:
container_name: rtsp-server
image: aler9/rtsp-simple-server
wyze-bridge:
restart: always
environment:
- RTSP_PROTOCOLS=tcp
# network_mode: host
ports:
- 1935:1935
- 8554:8554
- 8888:8888
volumes:
- ./app/rtsp-simple-server.yml:/rtsp-simple-server.yml

wyze-bridge:
container_name: wyze-bridge
restart: always
build:
context: ./app
# dockerfile: Dockerfile.arm
Expand Down

0 comments on commit 7868b5e

Please sign in to comment.