question

Robert Salita avatar image
Robert Salita asked

Windows Batch Files to Automate Reference Preview Sample

I've create some Windows batch files to automate the Reference Preview Sample. Currently there's only one sample. You need to thoroughly review the documentation for the sample before using the batch files. https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/reference-implementation-guide#Registering%20Your%20Product%20and%20Creating%20a%20Security%20Profile There are five batch files. I run them from C:\Temp. I'm using a Windows 10 system. 1. alexa_set_paths.bat contains path and value settings. YOU MUST MODIFY THE SETTINGS FOR YOUR INSTALLATION. This batch file is called by all other batch files. 2. alexa_install_openssl_cert.bat creates an ssl certificate for your server. Be sure to specify "localhost" in the FQN prompt as Amazon as documented. This is the only batch file that needs Administrator mode. 3. alexa_run_server.bat start the server. 3. alexa_create_config.bat creates the client device config.json file. 4. alexa_run_client.bat starts the client device.
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
@echo off REM alexa_set_paths.bat file REM Set paths and values. REM Be sure the following paths correctly point to your system's directories SET JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_55 SET MAVEN_PATH=C:\sw\samples\apache-maven-3.3.3 SET NODEJS_PATH=C:\Program Files (x86)\nodejs SET OPENSSL_PATH=C:\OpenSSL-Win32 SET REFERENCE_IMPLEMENTATION=C:\sw\samples\AlexaVoiceServiceExamples SET VLC_PATH=C:\Program Files (x86)\VideoLAN\VLC REM not working - unknown path problem - @SET MAVEN_OPTS=-Djna.library.path=%VLC_PATH% REM Sample values. You probably will want to change these. These values are used for client device and server. SET PRODUCT_TYPE_ID=my_device SET UNIQUE_PRODUCT_ID=123456 SET ALEXA_SERVER_URL=https://localhost:3000 REM Fill in your unique authorization values created by Amazon AVS. https://developer.amazon.com/edw/home.html#/avs/list. They are need to run server. SET CLIENT_ID= SET CLIENT_SECRET= REM Following are commands that attempt to validate the above settings. IF NOT DEFINED JAVA_HOME ( echo "JAVA_HOME does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%JAVA_HOME%\bin\java.exe" ( echo "JAVA_HOME directory is invalid - %JAVA_HOME%\bin" goto :EOF ) ) IF NOT DEFINED MAVEN_PATH ( echo "MAVEN_PATH does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%MAVEN_PATH%\bin\mvn" ( echo "MAVEN_PATH directory is invalid - %MAVEN_PATH%\bin" goto :EOF ) ) IF NOT DEFINED NODEJS_PATH ( echo "NODEJS_PATH does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%NODEJS_PATH%\node.exe" ( echo "NODEJS_PATH directory is invalid - %NODEJS_PATH%\bin" goto :EOF ) ) IF NOT DEFINED OPENSSL_PATH ( echo "OPENSSL_PATH does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%OPENSSL_PATH%\bin\openssl.exe" ( echo "OPENSSL_PATH directory is invalid - %OPENSSL_PATH%\bin" goto :EOF ) ) IF NOT DEFINED REFERENCE_IMPLEMENTATION ( echo "REFERENCE_IMPLEMENTATION does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%REFERENCE_IMPLEMENTATION%\samples" ( echo "REFERENCE_IMPLEMENTATION directory is invalid - %REFERENCE_IMPLEMENTATION%\bin" goto :EOF ) ) IF NOT DEFINED VLC_PATH ( echo "VLC_PATH does not exist" goto :EOF ) ELSE ( IF NOT EXIST "%VLC_PATH%\vlc.exe" ( echo "VLC_PATH directory is invalid - %VLC_PATH%\bin" goto :EOF ) ) IF "%CLIENT_ID%"=="" ( echo Missing CLIENT_ID goto :EOF ) IF "%CLIENT_SECRET%"=="" ( echo Missing CLIENT_SECRET goto :EOF ) IF "%PRODUCT_TYPE_ID%"=="" ( echo Missing PRODUCT_TYPE_ID goto :EOF ) IF "%UNIQUE_PRODUCT_ID%"=="" ( echo Missing UNIQUE_PRODUCT_ID goto :EOF ) IF "%ALEXA_SERVER_URL%"=="" ( echo Missing ALEXA_SERVER_URL goto :EOF ) Message was edited by: Robert Salita
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
@echo off REM alexa_install_openssl_cert.bat file REM Install/Reinstall openssl certificate REM Perform test that determines if we are running in Administrative mode. net session >nul 2>&1 if %errorLevel% NEQ 0 ( echo Please run in Administrator mode goto :EOF ) call alexa_set_paths.bat pushd "%REFERENCE_IMPLEMENTATION%\samples\service\ssl" PATH %OPENSSL_PATH%\bin;%JAVA_HOME%\bin;%PATH% openssl genrsa -des3 -out server.key 2048 if errorlevel 1 goto :EOF openssl req -new -key server.key -out server.csr if errorlevel 1 goto :EOF move/Y server.key server.key.passphrase if errorlevel 1 goto :EOF openssl rsa -in server.key.passphrase -out server.key if errorlevel 1 goto :EOF openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt if errorlevel 1 goto :EOF REM First remove any existing certificate. keytool -delete -v -trustcacerts -alias avs-companion-service -file server.crt -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -keypass changeit -storepass changeit keytool -importcert -v -trustcacerts -alias avs-companion-service -file server.crt -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -keypass changeit -storepass changeit if errorlevel 1 goto :EOF popd Message was edited by: Robert Salita
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
rem @echo off REM alexa_run_server.bat file. REM Run server call alexa_set_paths.bat pushd %REFERENCE_IMPLEMENTATION%\samples\service REM execute nodejs npm call npm install if errorlevel 1 goto :EOF echo install finished echo > config.json echo /** >> config.json echo * @module >> config.json echo * This module defines the settings that need to be configured for a new >> config.json echo * environment. >> config.json echo * The clientId and clientSecret are provided when you create >> config.json echo * a new security profile in Login with Amazon. >> config.json echo * >> config.json echo * You will also need to specify >> config.json echo * the redirect url under allowed settings as the return url that LWA >> config.json echo * will call back to with the authorization code. The authresponse endpoint >> config.json echo * is setup in app.js, and should not be changed. >> config.json echo * >> config.json echo * lwaRedirectHost and lwaApiHost are setup for login with Amazon, and you should >> config.json echo * not need to modify those elements. >> config.json echo */ >> config.json echo var config = { >> config.json echo clientId: '', >> config.json echo clientSecret: '', >> config.json echo redirectUrl: '%ALEXA_SERVER_URL%/authresponse', >> config.json echo lwaRedirectHost: ' amazon.com', >> config.json echo lwaApiHost: ' api.amazon.com', >> config.json echo validateCertChain: true, >> config.json echo products: { >> config.json echo "%PRODUCT_TYPE_ID%": ["%UNIQUE_PRODUCT_ID%"], // Fill in with valid device values, eg: "testdevice1": ["DSN1234", "DSN5678"] >> config.json echo }, >> config.json echo }; >> config.json echo >> config.json echo module.exports = config; >> config.json echo Your server's config.json at %CD% contains: type config.json call npm start if errorlevel 1 goto :EOF popd
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
@echo off REM alexa_create_config.bat file REM Create client device config.json file call alexa_set_paths.bat pushd "%REFERENCE_IMPLEMENTATION%\samples\javaclient" echo { "pid":"%PRODUCT_TYPE_ID%", "serial":"%UNIQUE_PRODUCT_ID%", "url":"%ALEXA_SERVER_URL%" } > config.json echo Client device config.json file at %CD% contains: type config.json popd
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
@echo off REM alexa_run_client.bat file REM Create client device config.json file call alexa_set_paths.bat PATH=%MAVEN_PATH%\bin;%VLC_PATH%;%PATH% pushd "%REFERENCE_IMPLEMENTATION%\samples\javaclient" call mvn install if errorlevel 1 goto :EOF call mvn exec:java if errorlevel 1 goto :EOF popd
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Robert Salita avatar image
Robert Salita answered
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.