Files here demostrate how to set up browser event receive for Smartmex events through WebSocket.
- You should have SmartMEX service activated for your company.
- You should have at least one SMARTMEX POST JSON API token created with rights to access "/api/session_keys/create" endpoint.
- You should be able to use this token from the machine you are running this example from.
Optional: For ease of running the example, you should have Docker and docker-compose installed.
- git clone the project,
- go to docker-compose.yml file and modify these lines according to your configuration:
- TOKEN=QR3234872348723423423UIUY0
- SMARTMEX_HOST=service.smartmex.eu
TOKEN - token genearted from SmartMEX selfcare; SMARTMEX_HOST - hostname of the smartmex service - mobili-stotele.tele2.lt or zvanuparvaldnieks.lmt.lv
- run docker-compose:
$docker-compose up --build
- visit http://127.0.0.1:8000 in your browser, open console to see log and make a call
- Install latest versions of python 3.X, and follwong python packages - requests, pyopenssl,service_identity, pycrypto
- Export environment variables:
$export TOKEN=QR3234872348723423423UIUY0
$export SMARTMEX_HOST=service.smartmex.eu
$export PORT=8000
Where: TOKEN - token genearted from SmartMEX selfcare; SMARTMEX_HOST - hostname of the smartmex service - mobili-stotele.tele2.lt or zvanuparvaldnieks.lmt.lv PORT - local port service will listen on
- Run example:
$cd src/
$python3 main3.py
The demonstrated example does following things:
- On a new web page request, this python script requests new temporary token from SMARTMEX JSON POST API endpoint
- It includes this temporary token in a HTML document sent to browser
- This temporary token is used by JavaScript to authenticate WebSocket session and start recieving events.