Amarisoft

Python Websocket example

 

Amarisoft ''ltewww'' package come with a Javascript/NodeJS sample program to use directly the Websocket API, called ''ws.js''. Other Amarisoft tools also use Javascript internally.

Amarisoft provide only official support for the tools present in its packages.

However, Websocket can also be used with Python thanks to the ''websockets'' python package.Amarisoft does not offer dedicated support for it but you can find below an example :

 

Prerequisite

Make sure you have Python3 and pip installed with version 3.7 at least.

 

Install the package

Package documentation can be found here : [[https://websockets.readthedocs.io/en/stable/intro.html]]

python3 -m pip install websockets

 

 

Sample code

The following sample code will take one command line argument to adjust the gain of a cell,provided that a ''lteeenb'' program is running on the ''localhost'' and listening on port 9001.

ws_script.py:

import asyncio import websockets import sys async def tx_gain(gain): uri = "ws://localhost:9001 async with websockets.connect(uri, origin="Test") as websocket: ready = await websocket.recv() print(f"< {ready}") msg = f'{{"message":"cell_gain", "cell_id":1, "gain":{gain}}}' await websocket.send(msg) print(f"> {msg}") rsp = await websocket.recv() print(f"< {rsp}") asyncio.run(tx_gain(sys.argv[1]))

 

 

Run

It is run simply with :

python3 ws_script.py -20

The output on command line should be

< {"message":"ready","type":"ENB","name":"ENB","version":"2020-09-14","time":1378.155} > {"message":"cell_gain", "cell_id":1, "gain":-20} < {"message":"cell_gain","time":1378.157} Original page