API¶
balanz includes an API primary focused on supporting external clients (UI, automation, etc.)
The API is a WebSocket based protocol parallel to the OCPP protocol used with Charger/Servers.
The protocol is designed to be simple and easy to use, mimicing OCPP messages. To recap, commands are sent
as JSON messages in the format [2, <messageId>, <command>, <payload>]. Succesful responses sent as
[3, <messageId>, <payload>] while error responses are [4, <messageId>, <errorMessage>].
The client is expected to Authenticate using the Login call before issuing other commands. Otherwise,
they will be rejected. The token string is a concatenation of the user_id and password.
The sha256 value of the token will be validated against users in the users.csv file.
A user type combines the available API methods with the available UI screens/focus. The following user_types are supported:
Status- API read-only access. UI only has status screen
Analysis- API read-only access. Screens available in read-only mode
SessionPriority- AsStatus, except possible to override session priority
Tags- AsAnalysis, ability to override session priority and maintain tags
Admin- All access
The sha256 value of token specified in a list in the balanz configuration file. An online tool may be used, e.g. Coding Tools. Set the tool to generate lower case sha256 values as in the example below (first sha matches the token set in the example UIs).
users.csv file¶user_id,user_type,description,auth_sha
delete-admin,Admin,Initial admin user (admin/admin) - DELETE ME,d82494f05d6917ba02f7aaa29689ccb444bb73f20380876cb05d1f37537b7892
example-ui,Admin,,4a8b74ba66bb2dad068addac37fa6faaa8996ca84a4d94bdc12a54e4e2732a6a
Model commands¶
The protocol supports the following commands for interacting with the balanz model. The resulting payloads are not detailed, but should be quite intiutive. Try the commands - maybe using the included example UI - (see TBD).
Command |
Payload |
Description |
|---|---|---|
|
|
Authenticate |
|
(None) |
Returns balanz version and various status information. |
|
|
Updates a balanz configuration setting live. Use carefully! Note, that the configuration is not saved to disk |
|
(None) |
Returns the current balanz configuration |
|
|
Returns drawing of all groups, chargers, sessions, and states. Optionally omit charging history |
|
|
Update the priority of a session on a connector |
|
|
Update the charger firmware |
|
|
Suspend or resume balanz() for an allocation group |
|
(None) |
Returns all users |
|
|
Create new user. |
|
|
Update user |
|
|
Delete user |
|
|
Create new firmware metadata |
|
|
Update firmware metadata |
|
|
Delete firmware metadata |
|
(None) |
Reload Firmware metadata from CSV file |
|
(None) |
Returns full group structure |
|
(None) |
Rereads groups from CSV file |
|
|
Update existing group. Updates specified field(s) |
|
|
Returns charger(s) matching filter |
|
(None) |
Rereads chargers from CSV file |
|
|
Creates a new charger into the specified group |
|
|
Deletes existing charger from the system |
|
|
Reset the AuthorizationKey for the charger. |
|
|
Update existing charger. Updates specified field(s) |
|
(None) |
Returns all known tags |
|
(None) |
Reread tags from CSV file |
|
|
Update existing tag. Updates specified field(s). status can be |
|
|
Create new tag. status can be |
|
|
Delete a tag |
|
|
Returns all historic sessions matching filter, optionally including live sessions |
|
(None) |
Returns CSV file (as one long text string) with all historic sessions |
|
|
Dynamically update log level. See list of components in the balanz configuration file.
loglevel may be |
|
|
Retrieve system or audit logs. Audit logs have module == |
For example, to return all chargers belonging to the RR2 group, send the following command
setting messageId to 123456:
[2, "123456", "GetChargers", {"group_id": "RR2"}]
OCPP Commands¶
The following commands closely related to OCPP calls are also supported on the API, mostly for debugging and troubleshooting purposes.
WARNING: These commands may be taken out of the API; possibly to be replaced with a single call to allow pass-through of any valid OCPP command.
Most commands (all commands taking charger_id as argument) will result in a single OCPP call towards the charger without involving other balanz logic. As such, care must be taken not to interfeere with balanz.
There is little error checking vs. screening format of the payloads for the commands. Errors may be found only when issued to the charger. Such errors will of course be reported.
Command |
Payload |
Description |
|---|---|---|
|
|
Clears all default charing profiles |
|
|
Clears a specific default charging profile |
|
|
Sets profile for transaction |
|
|
Resets the charge point |
|
|
Starts a transaction remotely |
|
|
Stops a transaction remotely |
|
|
Get charger configuration for key or all |
|
|
Change charger config for key |
|
|
Trigger an OCPP message to be sent by the charger |
Note
In all calls (model or OCPP calls) where a charger is identified using charger_id, it is
possible to instead identify the charger by an alternative alias argument matching the
charger alias. If both are supplied, charger_id is used.