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

Fetch raw ocpp message #272

Open
Mayuri-Mense opened this issue Apr 24, 2024 · 4 comments
Open

Fetch raw ocpp message #272

Mayuri-Mense opened this issue Apr 24, 2024 · 4 comments

Comments

@Mayuri-Mense
Copy link

Mayuri-Mense commented Apr 24, 2024

Hello @lorenzodonini Is there a way to fetch received raw ocpp message and sent message for a given charger ?

@Mayuri-Mense
Copy link
Author

Mayuri-Mense commented Apr 24, 2024

// Define your message handling function
func handleMessage(ws ws.Channel, data []byte) error {
	// Handle the incoming message here
	log.Printf("Received message from %s: %s", ws.ID(), string(data))
	return nil
}

func setupCentralSystem() ocpp16.CentralSystem {
	
	server := ws.NewServer()

	//todo remove
	server.SetCheckOriginHandler(func(r *http.Request) bool {
		return true
	})

	server.SetMessageHandler(handleMessage)
	
	server.AddHttpHandler("/v1/chargepoint", handler.HandleFunc(&centralSystem))

	return ocpp16.NewCentralSystem(nil, server)
}

This doesnt seem to work SetMessageHandler

@Atul-Mundlik
Copy link

I need similar functionality to handle the actual message.
It appears that the handler is getting set to the server but during handling of the message it not getting invoked or getting lost

@lorenzodonini can you please check this?

@lorenzodonini
Copy link
Owner

This is working as intended. The SetMessageHandler is exposed via interface to allow swapping out an entire layer with a custom implementation, but it is not meant to be used directly in the provided configuration:

  • if you set it before starting your server, it will be overwritten internally
  • if you set it after starting your server, you will receive the callbacks but you won't get any of the other functionality (i.e. message handling and strongly typed messages)

Raw messages are not directly exposed to the top layer, since that would defeat the purpose of the library.
You can look at the raw incoming/outgoing messages though, by setting your own logger via ocppj.SetLogger(yourLogger). The logger needs to have debug logs enabled. Note that invalid JSON messages will not be logged, as they cannot be parsed.

@Mayuri-Mense
Copy link
Author

Thanks

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

3 participants