Skip to content
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

Server not work with a real charge point #307

Closed
bdevia opened this issue Jan 23, 2024 · 7 comments
Closed

Server not work with a real charge point #307

bdevia opened this issue Jan 23, 2024 · 7 comments

Comments

@bdevia
Copy link

bdevia commented Jan 23, 2024

Hi, I've been testing with your library to create a mainframe following the examples shown in the quickstart: https://github.com/ChargeTimeEU/Java-OCA-OCPP/wiki/Getting-started

When running the server and the client (simulated), the connection is made perfectly, however, when I try to test between the server and a real charge point (GWJ3004W) the connection is not made.
When analyzing the network traffic, I can notice that the CP sends TCP requests to establish the connection but the server does not respond to them:

image

image

As you can see, it is not a network problem either. My private IP is 172.15.200.101, while the charge point is 172.15.200.100.
I have tried other libraries and it has worked, so I rule out CP as the problem. The charge point operates with OCPP-j 1.6, so the server runs with that version of the protocol.

Server code:
package com.example;

import java.util.UUID;

import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.ServerEvents;
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
import eu.chargetime.ocpp.model.SessionInformation;
import eu.chargetime.ocpp.model.core.AuthorizeConfirmation;
import eu.chargetime.ocpp.model.core.AuthorizeRequest;
import eu.chargetime.ocpp.model.core.BootNotificationConfirmation;
import eu.chargetime.ocpp.model.core.BootNotificationRequest;
import eu.chargetime.ocpp.model.core.DataTransferConfirmation;
import eu.chargetime.ocpp.model.core.DataTransferRequest;
import eu.chargetime.ocpp.model.core.HeartbeatConfirmation;
import eu.chargetime.ocpp.model.core.HeartbeatRequest;
import eu.chargetime.ocpp.model.core.MeterValuesConfirmation;
import eu.chargetime.ocpp.model.core.MeterValuesRequest;
import eu.chargetime.ocpp.model.core.StartTransactionConfirmation;
import eu.chargetime.ocpp.model.core.StartTransactionRequest;
import eu.chargetime.ocpp.model.core.StatusNotificationConfirmation;
import eu.chargetime.ocpp.model.core.StatusNotificationRequest;
import eu.chargetime.ocpp.model.core.StopTransactionConfirmation;
import eu.chargetime.ocpp.model.core.StopTransactionRequest;

public class OCPPServerExample {

public static void main(String[] args) {
        // The core profile is mandatory
    ServerCoreProfile core = new ServerCoreProfile(new ServerCoreEventHandler() {
        @Override
        public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {

            System.out.println(request);
            // ... handle event

            return new AuthorizeConfirmation();
        }

        @Override
        public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }
    });

    try {
        JSONServer server = new JSONServer(core);
        server.open("localhost", 8887, new ServerEvents() {

            @Override
            public void newSession(UUID sessionIndex, SessionInformation information) {

                // sessionIndex is used to send messages.
                System.out.println("New session " + sessionIndex + ": " + information);
            }

            @Override
            public void lostSession(UUID sessionIndex) {

                System.out.println("Session " + sessionIndex + " lost connection");
            }

            @Override
            public void authenticateSession(SessionInformation sessionInformation, String idToken, byte[] leafCertificate) {
                // Implementa la lógica de autenticación aquí
                // Puedes devolver true si la sesión debe ser autenticada y false si no
                System.out.println("idtoken :" + idToken );
            }
        });

        System.out.println("Levantando servidor");
    } catch (Exception e) {
        System.err.println(e);
    }
}

}

It is worth mentioning that the charge point is configured to connect to the central system through the address ws://172.15.200.101:8887/

Am I making some mistake? Has anyone faced this problem?
I hope you can help me, thank you.

@bantu
Copy link
Contributor

bantu commented Jan 24, 2024

You need to implement your own logic where the template code you copied from the wiki says " // ... handle event" and "return null".

@bdevia
Copy link
Author

bdevia commented Jan 24, 2024

hi @bantu, thanks for the answer.

I am doubting if that is really the problem, since the handle event logic that you mention, I understand that it is at the OCPP (application protocol) level, however, looking at the network traffic with wireshark, the handshake at the TCP (transport layer) is not carried out. In this way, the connection to the websocket cannot be made.

I have done more tests. Start a client on another machine with the same library and the result is the same. The client generates TCP requests to establish a connection with the server, but the server does not respond to the TCP requests (the TCP handshake does not take place):

image

On the other hand, when the client and server are on the same machine, the connection is made without problems...

@bantu
Copy link
Contributor

bantu commented Jan 24, 2024

@bdevia Sounds like you have network problems in general.

@bdevia
Copy link
Author

bdevia commented Jan 24, 2024

@bantu the truth is that I don't think it's a network problem, since with the library https://github.com/mobilityhouse/ocpp, the connection works perfectly:
image

Have you performed tests between client and server on different machines? I'm thinking that it may be a problem with my own equipment (architecture for example) that causes the library to not work at the network level.

@bantu
Copy link
Contributor

bantu commented Jan 24, 2024

the truth is that I don't think it's a network problem

it looks like your two tests are on two different ip networks (172.15.200.0/24 vs. 192.168.41.0/24)

Have you performed tests between client and server on different machines?

yes, in the past

@bdevia
Copy link
Author

bdevia commented Jan 24, 2024

it looks like your two tests are on two different ip networks (172.15.200.0/24 vs. 192.168.41.0/24)

Yes, I have two different networks:
172.15.200.0/24 internal test network.
192.168.41.0/24 production network.

I have been carrying out tests on both networks, making sure that both client and server are on the same network to rule out firewall problems.
I have changed the server to the computer with IP 172.15.200.104 (to rule out that the problem is with my machine), while the client (simulated with the library) is 172.15.200.101, however the connection does not work either:
image

Have you performed tests between client and server on different machines?

It is possible that the library is currently failing, so it would be helpful if someone can replicate the examples from the wiki, to see if the problem is with the library.

@bdevia
Copy link
Author

bdevia commented Jan 29, 2024

I have already found the problem, when it set the host as "localhost", the server does not enable the service for the IP of the private network as in other services. In this way, it is advisable to change the host directly to the IP instead of "localhost".

@bdevia bdevia closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants