0

I have a standalone HTML page with jQuery. The jQuery is used to do AJAX call to the Python backend. I need to integrate it with Volttron Central. I have looked at the documentation but there is no section talking about this. I think it would be nice to have this kind of info in the doc.

My current approach is to convert the backend Python to be a Volttron agent but I don't know how to integrate the front end HTML page with VC.

Any suggestion where to start? Thanks.

HNGO
  • 335
  • 1
  • 5
  • 20

1 Answers1

1

When you have an agent that is going to register its own endpoint you should do that during the onstart signal. The following was extracted from the volttron central agent. It shows how to register an endpoint that is dynamic(uses volttron rpc as the endpoint) as well as static(where the html is simply served). I have removed the un-necessary bits for this example.

onstart volttron central code

For clarity MASTER_WEB and VOLTTRON_CENTRAL are unique identifiers for those specific agents running on the volttron instance.

@Core.receiver('onstart')
def _starting(self, sender, **kwargs):
    """ Starting of the platform
    :param sender:
    :param kwargs:
    :return:
    """

    ...

    # Registers dynamic route.
    self.vip.rpc.call(MASTER_WEB, 'register_agent_route',
                      r'^/jsonrpc.*',
                      self.core.identity,
                      'jsonrpc').get(timeout=30)

    # Registers static route.
    self.vip.rpc.call(MASTER_WEB, 'register_path_route', VOLTTRON_CENTRAL,
                      r'^/.*', self._webroot).get(timeout=30)

Since you added the route onstart you should also remove it when the agent is stopped. onstop referenced code

@Core.receiver("onstop")
def stopping(self, sender, **kwargs):
    '''
    Release subscription to the message bus because we are no longer able
    to respond to messages now.
    '''
    try:
        # unsubscribes to all topics that we are subscribed to.
        self.vip.pubsub.unsubscribe(peer='pubsub', prefix=None, callback=None)
    except KeyError:
        # means that the agent didn't start up properly so the pubsub
        # subscriptions never got finished.
        pass
Craig
  • 949
  • 1
  • 5
  • 13
  • Thanks Craig. I will try it and get back to this later. – HNGO Jul 19 '16 at 23:02
  • If there is 10 different apps having 10 different UI, does this approach create too many backend agents, routes, frontend resources every where? – HNGO Jul 23 '16 at 21:55
  • This registering of routes is a standard way of doing things. It is not new. The frontend resources are and should be on the client side. – Craig Jul 24 '16 at 10:01