-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
network connection profiles #410
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f5eae6b
[wip] add a websocked connected and disconnected callback
SNSubramanya b94f03c
[wip] experiment with promise and future
SNSubramanya 5f03834
make websocket callbacks optional
SNSubramanya cc6d0a3
[wip] Add a future return for the configure network connection callback
SNSubramanya 9169440
[wip] Add a variable to configure the timeout duration
SNSubramanya 0658697
[wip] Add a check for the timeout value and deferred status
SNSubramanya aeb45d2
[wip] Added an on_try_switch function to switch to a specific network…
SNSubramanya 5436951
[wip] Add definition for on_try_switch_network_profile
SNSubramanya 2a71918
[wip] some more PR changes
SNSubramanya b6d22c8
websocket_(dis)connected_callback: Connected callback: NetworkConnect…
f365eb0
Add network profile slot to config network result.
00362ff
Change callback interface and add extra function for when network int…
b6e08cd
Changes on websocket interface to use a new defined enum.
maaikez 9e81cb8
Fixed compiling for new interface
AssemblyJohn 2eee3ed
Change configuration slot to be an int32_t instead of string. Add doc…
maaikez 0dcf551
Implement a bit more of on_try_switch_network_connection_profile.
maaikez 677c2d0
Add connectivity manager.
maaikez 39269f4
Add some callbacks in connectivity manager
maaikez 6cc22b3
Add main thread to connectivity manager.
maaikez 8a5353f
Remove things from ChargePoint that are moved to the ConnectivityMana…
maaikez 6230d9f
Change charge_point so it does not use websocket member anymore. Late…
maaikez 5d5e7ef
On network disconnect: only disconnect if the network that should be …
maaikez 1fa3d07
Fix bug where disconnected network slot was always disconnecting the …
maaikez 28b242d
Add logging for testing and try to fix some bugs.
maaikez 1dad026
Move reconnect timer to connectivity manager. formatting.
maaikez f47488e
Add websocket failed callback. Add functionality in connectivity mana…
maaikez 42fb35a
Strip websocket classes. Add (a lot of!) logging for debugging purposes.
maaikez 062367b
Add documentation. Fix some crashes when websocket is reconnecting.
maaikez fe28ee8
Cleanup. Introduce new mutex to prevent pending, active and requested…
maaikez 65e4f34
Fix after rebase
maaikez e005b18
Removed include for websocket_plain and websocket_tls .hpp from webso…
maaikez 83383e8
Formatting.
maaikez 25c301a
'Fix' some lint issues and clang format issues.
maaikez 10b5ff5
Add some removed code (oops). Move (duplicate) code from chargepoint …
maaikez 9d2e723
Make libwebsockets also work with security profile 1 (so that the url…
maaikez c2f8e29
Add some documentation.
maaikez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Network connection profile interface | ||
|
||
libocpp automatically tries to connect with the given network connection profiles. However, if you want to have more | ||
control, you can use the callbacks that are designated for the network connectivity. | ||
|
||
libocpp will connect automatically with the network profile of the highest priority. If that does not succeed, it will | ||
move on to the network profile with the second highest priority, etc. | ||
|
||
## Set up interface (optional) | ||
|
||
A callback can be implemented to be able to set up the interface. For example if the interface is a modem, it must first | ||
be enabled before it is possible to connect to that interface. To be able to do this, you can implement the callback | ||
`std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(configuration_slot, NetworkConnectionProfile))` | ||
|
||
In the implementation of this callback, you have to create a promise and return the future to the promise: | ||
```cpp | ||
std::promise<ocpp::v201::ConfigNetworkResult> promise(); | ||
std::future<ocpp::v201::ConfigNetworkResult> future = promise.get_future(); | ||
return future; | ||
``` | ||
|
||
If the network was setup successfully, you can set the values in the future with | ||
```cpp | ||
future.set_value(configNetworkResult); | ||
``` | ||
This way libocpp knows it can connect with the given interface and try to do that. A timeout can be configured // TODO which timeout etc??? | ||
to be sure libocpp will not wait forever to connect. | ||
|
||
|
||
### Bind to a specific interface | ||
|
||
In some cases, there are multiple network interfaces available and you might want to connect to a specific interface. | ||
In `ConfigNetworkResult` you can set the interface you want the websocket to bind to. Sometimes an interface has more | ||
than one IP address (in the case of a link local / auto IP address for example). In that case you want the websocket | ||
to bind to a specific IP address. The `interface_address` in ConfigNetworkResult supports both. It will bind using the | ||
given network interface (a string containing the name of the interface) or the given ip address (a string containing | ||
the ip address in human readable format). | ||
|
||
|
||
## Connect to higher network connection profile priority (optional) | ||
|
||
Normally, if libocpp is connected with a network connection profile, it will not disconnect. But a situation might | ||
occur that libocpp is connected with a profile with priority 2 or lower and you find out on system level that an | ||
interface (with a higher priority) changed and is now up. In that case you might want to inform libocpp that the higher | ||
priority interface is up and that it can try to connect with that interface. For example when the modem has 2nd priority, | ||
but you want to avoid high costs because of the data rates and switch back to wired network as soon as it is available. | ||
A call is implemented exactly for this reason: | ||
`bool on_try_switch_network_connection_profile(const int32_t configuration_slot)`. | ||
When you call this function, you inform libocpp that there is a network connection profile available and it might try | ||
to connect to that network connection profile (when indeed the priority of that profile is higher and there might | ||
be some more checks). | ||
|
||
Note: make sure to not ask for switching to another network profile too often, if it turns out that it can not connect | ||
to the backoffice while there is a link available, there might be an 'unstable' connection to the backoffice. | ||
|
||
|
||
## Disconnected / connected callbacks | ||
|
||
libocpp provides two callbacks for when the websocket is connected and disconnected. It will provide the network slot | ||
in those callbacks, so you can keep the used network connection up and running (for example not disabling the modem) or | ||
disable the network connection (example again: disable the modem). | ||
|
||
|
||
## Sequence diagram | ||
|
||
'core' can be read as any application that implements libocpp | ||
|
||
For step 9, ping is one way to check if a CSMS is up, but you of course can implement a way to check this yourself. | ||
|
||
![Sequence diagram](networkconnectivity_libocpp.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
!pragma teoz true | ||
participant csms | ||
autonumber "<b><font color=red>" | ||
skinparam sequenceArrowThickness 2 | ||
|
||
== libocpp wants to connect to network connection profile == | ||
|
||
{start} libocpp -> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(\nconfiguration_slot, NetworkConnectionProfile)) | ||
activate core #DarkSalmon | ||
core -> core: Setup network, e.g. setup modem | ||
{end} core -> libocpp: promise.set_value(status,\nip_address, etc) | ||
|
||
deactivate core | ||
{start} <-> {end}: ... possible delay ... | ||
|
||
alt within timeout | ||
|
||
' core -> libocpp: on_network_update (ip address) | ||
libocpp -> csms: connect websocket (ip address) | ||
csms -> libocpp: ACK | ||
libocpp -> core: websocket_connected_callback(configuration_slot, NetworkConnectionProfile) | ||
core -> core: disable unneeded interfaces, \ne.g. disable modem | ||
else timeout reached, next network connection profile selected | ||
libocpp --> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(\nconfiguration_slot, NetworkConnectionProfile)) (see 1) | ||
end | ||
|
||
|
||
== CSMS is connected via connection profile prio 2 (for example modem) but prio 1 (for example eth0) comes up == | ||
|
||
loop until prio 1 csms is found | ||
core -> csms: ping | ||
end | ||
|
||
core -> libocpp: on_try_switch_networkconnectionprofile(configuration_slot) | ||
libocpp --> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(\nconfiguration_slot, NetworkConnectionProfile)) (see 1) | ||
|
||
|
||
== Network is disconnected (for example networkcable removed) == | ||
|
||
core -> libocpp: disconnect csms (on_network_disconnected(configuration_slot, OCPPInterfaceEnum) | ||
libocpp -> core: websocket_disconnected_callback(configuration_slot, NetworkConnectionProfile) | ||
libocpp --> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(\nconfiguration_slot, NetworkConnectionProfile)) (see 1) | ||
|
||
|
||
== Network is disconnected (websocket timeout) == | ||
|
||
libocpp -> libocpp: disconnect csms | ||
libocpp -> core: websocket_disconnected_callback(configuration_slot, NetworkConnectionProfile) | ||
libocpp --> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(\nconfiguration_slot, NetworkConnectionProfile)) (see 1) | ||
|
||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep the
closed_callback
anddisconnected_callback
for now because they are implicitly used to manage the reconnect behavior, but to reduce complexity of the interface I would prefer to not have the seperated after this refactor is done