start_local_demo.bat 1.88 KB
@echo off
rem Dev-machine demo: mock DMS (8765) + server (58000) + local edge (vendor python38 -> mock DMS -> server)
rem Each part runs in its own window; close the windows to stop.
rem The server seeds the mock DMS account (DEMO_MOCK_DMS=true) and pushes it to the edge; the edge only needs the cloud url + token.
rem WARNING: uses the database in .env (repo root). Point it at a dev database, never at production.
rem Python for mock DMS / server: set PY before running, default = the autoRestock conda env.
cd /d "%~dp0..\.."
set ROOT=%cd%
if "%PY%"=="" set PY=D:\software_install\anaconda_env\envs\autoRestock\python.exe
if not exist "%PY%" (
  echo [ERROR] python not found: %PY%   ^(set PY=...\python.exe first^)
  pause
  exit /b 1
)
set EDGE_PY=%ROOT%\edge\vendor\python38\python.exe
if not exist "%EDGE_PY%" (
  echo [ERROR] edge\vendor\python38 not found, see edge\vendor\README.md
  pause
  exit /b 1
)
set PYTHONNOUSERSITE=1
set PYTHONIOENCODING=utf-8
set CLOUD_PORT=58000
set DEMO_MOCK_DMS=true
start "mock DMS :8765" cmd /k ""%PY%" "%ROOT%\edge\dev\mock_dms.py" 8765"
timeout /t 3 /nobreak >nul
start "server :58000" /d "%ROOT%\server" cmd /k ""%PY%" -m app.main"
rem device token for the local edge: the server (demo mode) registers a demo device and writes its token to server\data\demo_edge_token
set TOKEN_FILE=%ROOT%\server\data\demo_edge_token
set /a WAITED=0
:wait_token
if exist "%TOKEN_FILE%" goto have_token
if %WAITED% geq 60 (
  echo [ERROR] %TOKEN_FILE% not created within 60s, check the server window
  pause
  exit /b 1
)
timeout /t 2 /nobreak >nul
set /a WAITED+=2
goto wait_token
:have_token
set /p EDGE_TOKEN=<"%TOKEN_FILE%"
start "edge (mock)" /d "%ROOT%\edge" cmd /k ""%EDGE_PY%" main.py --config dev\config.mock.ini serve"
timeout /t 3 /nobreak >nul
start "" http://127.0.0.1:58000/
echo Started: mock DMS / server / edge. Console: http://127.0.0.1:58000/  (admin / admin123 on first start)