The problem I'm facing is that the ROS framework uses normal callbacks while aiohttp+socket.io uses asyncio. I wish to call an async function from within a ROS callback. Example:
#!/usr/bin/env python3
import asyncio
import socketio
import rospy
from aiohttp import web
from rosgraph_msgs.msg import Log
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
def on_rosout(msg):
sio.emit("message", msg.msg) # THIS DOES NOT WORK
@sio.on('connect', namespace='/')
def connect(sid, environ):
print("connect", sid)
@sio.on('disconnect', namespace='/')
def disconnect(sid):
print("disconnect", sid)
app.router.add_static('/', 'html', show_index = True)
if __name__ == "__main__":
rospy.init_node("foo_node")
rospy.Subscriber("/rosout_agg", Log, on_rosout)
web.run_app(app)