Simple Web Agent Walk-through¶
A simple web enabled agent that will hook up with a VOLTTRON message bus and allow interaction between it via HTTP. This example agent shows a simple file serving agent, a JSON-RPC based call, and a websocket based connection mechanism.
Starting VOLTTRON Platform¶
Starting the VOLTTRON platform requires an Activated Environment. Run the following command from the root directory:
In order to start the simple web agent, we need to bind the VOLTTRON instance to the a web server. We need to specify the address and the port for the web server. For example, if we want to bind the localhost:8080 as the web server we start the VOLTTRON platform as follows:
./start-volttron --bind-web-address http://127.0.0.1:8080
Once the platform is started, we are ready to run the Simple Web Agent.
Running Simple Web Agent¶
The following assumes the shell is located at the VOLTTRON_ROOT.
Copy the following into your shell (save it to a file for executing it again later):
python scripts/install-agent.py \
--agent-source examples/SimpleWebAgent \
--tag simpleWebAgent \
--vip-identity webagent \
This will create a web server on
http://localhost:8080. The index.html file under simpleweb/webroot/simpleweb/
can be any HTML page which binds to the VOLTTRON message bus .This provides a simple example of providing a web endpoint
Path based registration examples¶
Files will need to be in webroot/simpleweb in order for them to be browsed from
Filename is required as we don’t currently auto-redirect to any default pages as shown in
The following two examples show the way to call either a JSON-RPC (default) endpoint and one that returns a different content-type. With the JSON-RPC example from volttron central we only allow post requests, however this is not required.
Endpoint will be available at http://localhost:8080/simple/text
Endpoint will be available at http://localhost:8080/simple/jsonrpc
text/htmlcontent type specified so the browser can act appropriately like
The default response is
application/json so ourendpoint returns appropriately with a JSON based response.