Я не понимаю, как сервер и клиент из библиотеки OCA-OCPP для Java работают с EV Charger. Я не понимаю, какой порт мне нужно использовать для запроса WebSocket и как настроить зарядное устройство EV (Mennekes).
Я хочу иметь сервер, который отправляет запросы клиенту, и клиент отправляет запросы зарядному устройству электромобиля. Я не хочу иметь клиента, который должен управлять двумя отдельными соединениями: одним для сервера, а другим для зарядного устройства электромобиля.
public class OCPPClient {
private IClientAPI client;
private ClientCoreProfile core;
private JSONConfiguration configuration;
private WssSocket wssSocket;
public void connect(String ipChargingPoint, String port) throws Exception {
// The core profile is mandatory
core = new ClientCoreProfile(new ClientCoreEventHandler() {})
configuration = JSONConfiguration.get();
configuration.setParameter(JSONConfiguration.USERNAME_PARAMETER, "operator");
configuration.setParameter(JSONConfiguration.PASSWORD_PARAMETER, "CX1zRpdK");
configuration.setParameter(JSONConfiguration.TCP_NO_DELAY_PARAMETER, false);
configuration.setParameter(JSONConfiguration.PROXY_PARAMETER, null);
configuration.setParameter(JSONConfiguration.PING_INTERVAL_PARAMETER, 300);
configuration.setParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, 4);
configuration.setParameter(JSONConfiguration.CONNECT_TIMEOUT_IN_MS_PARAMETER, 10000);
wssSocket = new WssSocket();
wssSocket.uri(new URI("ws://" + ipChargingPoint + ":" + port));
client = new JSONClient(core, "137640200473", wssSocket, configuration);
client.connect("ws://" + ipChargingPoint + ":" + port, null);
}
public void sendBootNotification() throws Exception {
// Use the feature profile to help create event
Request request = core.createBootNotificationRequest("some vendor", "some model");
// Client returns a promise which will be filled once it receives a confirmation.
client.send(request).whenComplete((s, ex) -> System.out.println(s));
}
public IClientAPI getClient() {
return client;
}
public void disconnect() {
client.disconnect();
}
}
@Data
public class OCPPServer {
private JSONServer server;
private ServerCoreProfile core;
private Map clients = new HashMap();
private JSONConfiguration configuration;
public void started() throws Exception
{
if (server != null)
return;
configuration = JSONConfiguration.get();
configuration.setParameter(JSONConfiguration.USERNAME_PARAMETER, "operator");
configuration.setParameter(JSONConfiguration.PASSWORD_PARAMETER, "CX1zRpdK");
configuration.setParameter(JSONConfiguration.TCP_NO_DELAY_PARAMETER, true);
configuration.setParameter(JSONConfiguration.PROXY_PARAMETER, 3000);
configuration.setParameter(JSONConfiguration.PING_INTERVAL_PARAMETER, 300);
configuration.setParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, 4);
configuration.setParameter(JSONConfiguration.CONNECT_TIMEOUT_IN_MS_PARAMETER, 10000);
// The core profile is mandatory
core = new ServerCoreProfile(new ServerCoreEventHandler() {});
server = new JSONServer(core,configuration);
server.open("172.28.2.83", 3000, new ServerEvents() {})
System.out.println("Server started and listening on 172.28.2.83:3000");
}
public void sendClearCacheRequestToClient(String idStation) throws Exception {
// Récupérer le client correspondant à l'ID de la station
OCPPClient client = clients.get(idStation);
if (client != null) {
// Utiliser le profil de fonctionnalité pour aider à créer l'événement
ClearCacheRequest request = core.createClearCacheRequest();
// Le client renvoie une promesse qui sera remplie une fois qu'il recevra une confirmation.
client.getClient().send(request).whenComplete((confirmation, ex) -> {
if (ex != null) {
System.out.println("Failed to send ClearCacheRequest to client: " + ex.getMessage());
} else {
//Le serveur a reçu une confirmation de la station de recharge
System.out.println("ClearCacheRequest sent to client: " + confirmation);
}
});
} else {
System.out.println("No client found for station ID: " + idStation);
}
}
public void stop(){
server.close();
}
public int getActiveSessions() {
return clients.size();
}
public void createSessions(String idStation, String ipStation, String port ) {
OCPPClient client = new OCPPClient();
if(server == null){
try {
started();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
client.connect(ipStation, port); // Assurez-vous que l'adresse IP de la station est correcte
System.out.println("Connected to ws://" + ipStation + " on port " + port);
clients.put(idStation, client);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public OCPPClient getClient(String uuid) {
return clients.get(uuid);
}
}
class OCPPConnectionTest {
@Test
void testClientServerConnection() throws Exception {
OCPPServer server = new OCPPServer();
// Start the server
server.started();
assertEquals(0, server.getActiveSessions());
// Connect the client and send boot notification
server.createSessions("1", "172.28.2.57", "3000");
server.getClient("1").sendBootNotification();
// Verify that the server has an active session
assertEquals(1, server.getActiveSessions());
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... g-boot-app
Как управлять архитектурой ocpp в приложении Java Spring Boot ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1719382135
Anonymous
Я не понимаю, как сервер и клиент из библиотеки OCA-OCPP для Java работают с EV Charger. Я не понимаю, какой порт мне нужно использовать для запроса WebSocket и как настроить зарядное устройство EV (Mennekes).
Я хочу иметь сервер, который отправляет запросы клиенту, и клиент отправляет запросы зарядному устройству электромобиля. Я не хочу иметь клиента, который должен управлять двумя отдельными соединениями: одним для сервера, а другим для зарядного устройства электромобиля.
public class OCPPClient {
private IClientAPI client;
private ClientCoreProfile core;
private JSONConfiguration configuration;
private WssSocket wssSocket;
public void connect(String ipChargingPoint, String port) throws Exception {
// The core profile is mandatory
core = new ClientCoreProfile(new ClientCoreEventHandler() {})
configuration = JSONConfiguration.get();
configuration.setParameter(JSONConfiguration.USERNAME_PARAMETER, "operator");
configuration.setParameter(JSONConfiguration.PASSWORD_PARAMETER, "CX1zRpdK");
configuration.setParameter(JSONConfiguration.TCP_NO_DELAY_PARAMETER, false);
configuration.setParameter(JSONConfiguration.PROXY_PARAMETER, null);
configuration.setParameter(JSONConfiguration.PING_INTERVAL_PARAMETER, 300);
configuration.setParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, 4);
configuration.setParameter(JSONConfiguration.CONNECT_TIMEOUT_IN_MS_PARAMETER, 10000);
wssSocket = new WssSocket();
wssSocket.uri(new URI("ws://" + ipChargingPoint + ":" + port));
client = new JSONClient(core, "137640200473", wssSocket, configuration);
client.connect("ws://" + ipChargingPoint + ":" + port, null);
}
public void sendBootNotification() throws Exception {
// Use the feature profile to help create event
Request request = core.createBootNotificationRequest("some vendor", "some model");
// Client returns a promise which will be filled once it receives a confirmation.
client.send(request).whenComplete((s, ex) -> System.out.println(s));
}
public IClientAPI getClient() {
return client;
}
public void disconnect() {
client.disconnect();
}
}
@Data
public class OCPPServer {
private JSONServer server;
private ServerCoreProfile core;
private Map clients = new HashMap();
private JSONConfiguration configuration;
public void started() throws Exception
{
if (server != null)
return;
configuration = JSONConfiguration.get();
configuration.setParameter(JSONConfiguration.USERNAME_PARAMETER, "operator");
configuration.setParameter(JSONConfiguration.PASSWORD_PARAMETER, "CX1zRpdK");
configuration.setParameter(JSONConfiguration.TCP_NO_DELAY_PARAMETER, true);
configuration.setParameter(JSONConfiguration.PROXY_PARAMETER, 3000);
configuration.setParameter(JSONConfiguration.PING_INTERVAL_PARAMETER, 300);
configuration.setParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, 4);
configuration.setParameter(JSONConfiguration.CONNECT_TIMEOUT_IN_MS_PARAMETER, 10000);
// The core profile is mandatory
core = new ServerCoreProfile(new ServerCoreEventHandler() {});
server = new JSONServer(core,configuration);
server.open("172.28.2.83", 3000, new ServerEvents() {})
System.out.println("Server started and listening on 172.28.2.83:3000");
}
public void sendClearCacheRequestToClient(String idStation) throws Exception {
// Récupérer le client correspondant à l'ID de la station
OCPPClient client = clients.get(idStation);
if (client != null) {
// Utiliser le profil de fonctionnalité pour aider à créer l'événement
ClearCacheRequest request = core.createClearCacheRequest();
// Le client renvoie une promesse qui sera remplie une fois qu'il recevra une confirmation.
client.getClient().send(request).whenComplete((confirmation, ex) -> {
if (ex != null) {
System.out.println("Failed to send ClearCacheRequest to client: " + ex.getMessage());
} else {
//Le serveur a reçu une confirmation de la station de recharge
System.out.println("ClearCacheRequest sent to client: " + confirmation);
}
});
} else {
System.out.println("No client found for station ID: " + idStation);
}
}
public void stop(){
server.close();
}
public int getActiveSessions() {
return clients.size();
}
public void createSessions(String idStation, String ipStation, String port ) {
OCPPClient client = new OCPPClient();
if(server == null){
try {
started();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
client.connect(ipStation, port); // Assurez-vous que l'adresse IP de la station est correcte
System.out.println("Connected to ws://" + ipStation + " on port " + port);
clients.put(idStation, client);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public OCPPClient getClient(String uuid) {
return clients.get(uuid);
}
}
class OCPPConnectionTest {
@Test
void testClientServerConnection() throws Exception {
OCPPServer server = new OCPPServer();
// Start the server
server.started();
assertEquals(0, server.getActiveSessions());
// Connect the client and send boot notification
server.createSessions("1", "172.28.2.57", "3000");
server.getClient("1").sendBootNotification();
// Verify that the server has an active session
assertEquals(1, server.getActiveSessions());
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78298986/how-to-mange-ocpp-architecture-on-java-spring-boot-app[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия