0
我有一個帶有jQuery的獨立HTML頁面。 jQuery被用來對Python後端進行AJAX調用。我需要將它與Volttron Central集成。我看過文檔,但沒有討論這個部分。我認爲在文檔中有這種信息會很好。向Volttron Central添加一個新頁面
我目前的做法是將後端Python轉換爲Volttron代理,但我不知道如何將前端HTML頁面與VC集成。
任何建議從哪裏開始?謝謝。
我有一個帶有jQuery的獨立HTML頁面。 jQuery被用來對Python後端進行AJAX調用。我需要將它與Volttron Central集成。我看過文檔,但沒有討論這個部分。我認爲在文檔中有這種信息會很好。向Volttron Central添加一個新頁面
我目前的做法是將後端Python轉換爲Volttron代理,但我不知道如何將前端HTML頁面與VC集成。
任何建議從哪裏開始?謝謝。
當你有一個代理將要註冊自己的端點時,你應該在onstart信號中這樣做。以下是從伏特加中央代理提取的。它顯示瞭如何註冊一個動態端點(使用volttron rpc作爲端點)以及靜態(只需提供html)。我已經刪除了這個例子中不需要的位。
爲了清晰MASTER_WEB和VOLTTRON_CENTRAL是在volttron實例中運行的特定藥物的唯一標識符。
@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)
由於您添加了onstart路由,您還應該在代理停止時將其刪除。 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
Thanks Craig。我會嘗試一下,稍後再回來。 – HNGO
如果有10個不同的應用程序擁有10個不同的UI,這種方法是否會在每個地方創建過多的後端代理,路由,前端資源? – HNGO
這種路線註冊是一種標準的做事方式。這不是新的。前端資源是和應該在客戶端。 – Craig