(view source code of youlessbar.bat as plain text)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
ProgressBar.exe /? >NUL 2>&1
IF %ErrorLevel% NEQ -1 (
ECHO.
ECHO ERROR: ProgressBar.exe not found
ECHO.
GOTO Syntax
)
wget.exe >NUL 2>&1
IF %ErrorLevel% NEQ 1 (
ECHO.
ECHO ERROR: wget.exe not found
ECHO.
GOTO Syntax
)
SET Interval=5
SET Scale=
IF NOT "%~2"=="" GOTO Syntax
IF NOT "%~1"=="" (
ECHO."%~1"| FINDSTR.EXE /R /X /C:".[0-9][0-9]*." >NUL
IF ERRORLEVEL 1 (
GOTO Syntax
) ELSE (
SET Interval=%~1
)
)
IF %Interval% LSS 1 GOTO Syntax
IF %Interval% GTR 120 GOTO Syntax
FOR /F "tokens=2 delims=:" %%A IN ('MODE CON: ^| FIND.EXE ":" ^| FIND.EXE /N ":" ^| FIND.EXE "[3]"') DO (
REM Remove leading and trailing spaces
FOR %%B IN (%%A) DO SET ConsoleWidth=%%B
)
CLS
ECHO.
ECHO.
ECHO.
:: Center text
SET /A StartPos = %ConsoleWidth% / 2 - 11
FOR /L %%A IN (1,1,%StartPos%) DO (
SET /P "=^ " < NUL
)
ECHO Youless power monitor
:: Underline centered text
SET /A StartPos = %ConsoleWidth% / 2 - 11
FOR /L %%A IN (1,1,%StartPos%) DO (
SET /P "=^ " < NUL
)
ECHO.=====================
ECHO.
ECHO.
:Start
:: Get actual logging values
FOR /F "tokens=1 delims={}[]" %%A IN ('WGET.EXE -q -O - http://youless/e') DO (SET AllValues=%%A)
:: Store collected values in environment variables
SET RemainingValues=%DeviceData%,%AllValues%
:Loop
FOR /F "tokens=1* delims=," %%A IN ("!RemainingValues!") DO (
FOR /F "tokens=1* delims=:" %%C IN ('ECHO %%A') DO (
SET Values.%%~C=%%~D
REM Format date and time to make it more readable
IF "%%~C"=="gts" (
SET Values.%%~C=20!Values.%%~C:~0,2!-!Values.%%~C:~2,2!-!Values.%%~C:~4,2! !Values.%%~C:~6,2!:!Values.%%~C:~8,2!
)
REM make uppercase and replace colons by dashes
IF "%%~C"=="mac" (
SET Values.%%~C=!Values.%%~C::=-!
SET Values.%%~C=!Values.%%~C:a=A!
SET Values.%%~C=!Values.%%~C:b=B!
SET Values.%%~C=!Values.%%~C:c=C!
SET Values.%%~C=!Values.%%~C:d=D!
SET Values.%%~C=!Values.%%~C:e=E!
SET Values.%%~C=!Values.%%~C:f=F!
)
REM Remove leading spaces
FOR /F "tokens=*" %%E IN ("!Values.%%~C!") DO SET Values.%%~C=%%E
)
IF "%%~B"=="" GOTO EndLoop
SET RemainingValues=%%B
GOTO Loop
)
:EndLoop
ProgressBar.exe %Values.pwr% -2000 2000 Yellow Green %Scale%
IF ERRORLEVEL 1 (
ENDLOCAL
EXIT /B 1
)
SET Scale=/NS
:: Wait a number of seconds
Timeout.exe /T %Interval% >NUL
GOTO :Start
:End
ENDLOCAL
EXIT /B 0
:Syntax
ECHO.
ECHO YoulessBar.bat, Version 1.00
ECHO Read data from a Youless LS120 device and show result in a progress bar
ECHO.
ECHO Usage: Youless.exe [ seconds ]
ECHO.
ECHO Where: seconds interval between log queries (1..120)
ECHO.
ECHO Notes: This program requires wget.exe, available at:
ECHO https://gnuwin32.sourceforge.net/packages/wget.htm
ECHO and ProgressBar.exe, available at:
ECHO https://www.robvanderwoude.com/files/progressbar.zip
ECHO Return code ("ErrorLevel") equals 1 in case of
ECHO (command line) errors, otherwise 0.
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
ENDLOCAL
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0066 seconds