Как управлять архитектурой ocpp в приложении Java Spring BootJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как управлять архитектурой ocpp в приложении Java Spring Boot

Сообщение 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());

}

}


Подробнее здесь: https://stackoverflow.com/questions/782 ... g-boot-app
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»