diff --git a/src/api_communication/api_communication/api_listener.py b/src/api_communication/api_communication/api_listener.py new file mode 100644 index 00000000..e7a1c578 --- /dev/null +++ b/src/api_communication/api_communication/api_listener.py @@ -0,0 +1,38 @@ +import rclpy +from rclpy.node import Node + +import asyncio +import websockets.server + +class ApiListener(Node): + def __init__(self): + super().__init__('api_listener') + self.get_logger().info('ApiListener node started') + asyncio.run(self.run_api()) + + async def run_api(self): + self.get_logger().info('Starting API') + self.server = await websockets.serve(self.api_handler, 'localhost', 8765) + + async def api_handler(self, websocket): + try: + while True: + message = await websocket.recv() + self.get_logger().info('Received message: {0}'.format(message)) + await websocket.send("You sent " + str(message)) + except websockets.exceptions.ConnectionClosed: + self.get_logger().info('Connection closed') + + +def main(args=None): + rclpy.init(args=args) + + api_listener = ApiListener() + + rclpy.spin(api_listener) + + api_listener.destroy_node() + rclpy.shutdown() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/src/api_communication/package.xml b/src/api_communication/package.xml index 8f3e38e2..be9c3731 100644 --- a/src/api_communication/package.xml +++ b/src/api_communication/package.xml @@ -3,9 +3,10 @@ api_communication 0.0.0 - TODO: Package description - ubuntu - TODO: License declaration + package for communicating with edge computer through 5G + sem + Apache License 2.0 + rclpy ament_copyright ament_flake8 diff --git a/src/api_communication/setup.py b/src/api_communication/setup.py index 61eae685..a359b4cc 100644 --- a/src/api_communication/setup.py +++ b/src/api_communication/setup.py @@ -20,6 +20,7 @@ setup( tests_require=['pytest'], entry_points={ 'console_scripts': [ + 'api_listener = api_communication.api_listener:main' ], }, ) diff --git a/src/px4_msgs b/src/px4_msgs index ffc3a4cd..b64ef047 160000 --- a/src/px4_msgs +++ b/src/px4_msgs @@ -1 +1 @@ -Subproject commit ffc3a4cd578776213a444abe17d7eabf9621b266 +Subproject commit b64ef0475c1d44605688f4770899fe453d532be4