lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
262 stars 125 forks source link

websocket: bad handshake for OCPP 2.0 #27

Closed nikunjtilva closed 4 years ago

nikunjtilva commented 4 years ago

Hi,

I try to create and example for OCPP 2.0 with ocpp2.0-features branch. When i try to connect to CSMS from CS it throws websocket: bad handshake error.

Here is sample CSMS and CS code

cs.go

package main

import (
    "fmt"
    "github.com/lorenzodonini/ocpp-go/ocpp2.0"
)

func main() {
    fmt.Println("Charging Station")
    cs := ocpp2.NewChargingStation("uniqueFox", nil, nil)
    err := cs.Start("ws://127.0.0.1:8080")
    fmt.Println(err)
}

csms.go

package main

import (
    "fmt"
    "github.com/lorenzodonini/ocpp-go/ocpp2.0"
)

func main() {
    csms := ocpp2.NewCSMS(nil, nil)
    csms.SetNewChargingStationHandler(func(chargePointId string) {
        fmt.Println("Charge point connected ", chargePointId)
    })
    csms.Start(8080, "")
}

I have not set any handler yet. But i assume it should connect without handler.

I am able to run ocpp1.6 example without any issue.

lorenzodonini commented 4 years ago

You need to set a non-empty listenPath when starting the CSMS server.

There is no default handler if you pass an empty string. I recommend doing it exactly as in the 1.6 example, so pass /{ws}. Worked for me.

Btw, I just rebased the branch on master, since there are a few improvements in the ws package, such as basic auth and certificate handling (check out the docs for more info).

The branch you are testing on is a WIP, so use it at your own risk! Several features are still missing and need to be thoroughly tested. You are very welcome to contribute though 😄

nikunjtilva commented 4 years ago

Hooray... It worked... Thanks a lot for super fast response... Yes i am fully aware of this branch is WIP. We will be in a position to contribute after sometime. If you have any roadmap where we can see completed and missing features we can plan accordingly to contribute.