Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for youless.bat

(view source code of youless.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%~1"=="" GOTO Syntax
  3.  
  4. SETLOCAL ENABLEDELAYEDEXPANSION
  5.  
  6. :: Get Youless IP address
  7. FOR /F "tokens=2 delims=[]" %%A IN ('PING.EXE youless -n 1 -w 100') DO SET IPAddress=%%A
  8.  
  9. :: Get device data
  10. FOR /F "tokens=1 delims={}[]" %%A IN ('WGET.EXE -q -O - http://youless/d') DO (SET DeviceData=%%A)
  11.  
  12. :: Get actual logging values
  13. FOR /F "tokens=1 delims={}[]" %%A IN ('WGET.EXE -q -O - http://youless/e') DO (SET AllValues=%%A)
  14.  
  15. :: Store collected values in environment variables
  16. SET RemainingValues=%DeviceData%,%AllValues%
  17. :Loop
  18. FOR /F "tokens=1* delims=," %%A IN ("!RemainingValues!") DO (
  19. 	FOR /F "tokens=1* delims=:" %%C IN ('ECHO %%A') DO (
  20. 		SET Values.%%~C=%%~D
  21. 		REM Format date and time to make it more readable
  22. 		IF "%%~C"=="gts" (
  23. 			SET Values.%%~C=20!Values.%%~C:~0,2!-!Values.%%~C:~2,2!-!Values.%%~C:~4,2! !Values.%%~C:~6,2!:!Values.%%~C:~8,2!
  24. 		)
  25. 		REM make uppercase and replace colons by dashes
  26. 		IF "%%~C"=="mac" (
  27. 			SET Values.%%~C=!Values.%%~C::=-!
  28. 			SET Values.%%~C=!Values.%%~C:a=A!
  29. 			SET Values.%%~C=!Values.%%~C:b=B!
  30. 			SET Values.%%~C=!Values.%%~C:c=C!
  31. 			SET Values.%%~C=!Values.%%~C:d=D!
  32. 			SET Values.%%~C=!Values.%%~C:e=E!
  33. 			SET Values.%%~C=!Values.%%~C:f=F!
  34. 		)
  35. 		REM Remove leading spaces
  36. 		FOR /F "tokens=*" %%E IN ("!Values.%%~C!") DO SET Values.%%~C=%%E
  37. 	)
  38. 	IF "%%~B"=="" GOTO EndLoop
  39. 	SET RemainingValues=%%B
  40. 	GOTO Loop
  41. )
  42. :EndLoop
  43.  
  44. ECHO.
  45. ECHO Youless model                :	%Values.model%
  46. ECHO Youless firmware             :	%Values.fw%
  47. ECHO Youless MAC adres            :	%Values.mac%
  48. ECHO Youless IP adres             :	%IPAddress%
  49. ECHO.
  50. ECHO Tijdstip                     :	%Values.gts%
  51. ECHO.
  52. ECHO Vermogen                     :	%Values.pwr% W
  53. ECHO P1 afname hoog tarief        :	%Values.p1% kWh
  54. ECHO P1 afname laag tarief        :	%Values.p2% kWh
  55. ECHO P1 teruglevering hoog tarief :	%Values.n1% kWh
  56. ECHO P1 teruglevering laag tarief :	%Values.n2% kWh
  57. ECHO Netto totaal verbruik        :	%Values.net% kWh
  58. ECHO.
  59. ECHO Gas verbruik                 :	%Values.gas% m3
  60. ECHO.
  61.  
  62. ENDLOCAL
  63. EXIT /B 0
  64.  
  65.  
  66. :Syntax
  67. ECHO.
  68. ECHO Youless.bat,  Version 1.00
  69. ECHO Read data from a Youless LS120 energy monitor device
  70. ECHO.
  71. ECHO Usage:    Youless.exe
  72. ECHO.
  73. ECHO Notes:    This program requires wget.exe, available at:
  74. ECHO           https://gnuwin32.sourceforge.net/packages/wget.htm
  75. ECHO           Return code ("ErrorLevel") equals 1 in case of
  76. ECHO           (command line) errors, otherwise 0.
  77. ECHO.
  78. ECHO Written by Rob van der Woude
  79. ECHO https://www.robvanderwoude.com
  80. EXIT /B 1
  81.  

page last modified: 2024-04-16; loaded in 0.0061 seconds