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

Exception processing OCPP request Heartbeat: #39

Open
gianmarcoodorizzi opened this issue Sep 23, 2021 · 6 comments
Open

Exception processing OCPP request Heartbeat: #39

gianmarcoodorizzi opened this issue Sep 23, 2021 · 6 comments

Comments

@gianmarcoodorizzi
Copy link

gianmarcoodorizzi commented Sep 23, 2021

Hello,

I am new to Scala, so please, excuse me in advance if this sounds like a silly issue.
I added this piece of code in the match case of ExampleServerTestApp.scala.

case req: HeartbeatReq => HeartbeatRes(currentTime = ZonedDateTime.now())

And I get this in response:

Received request HeartbeatReq from client ocppws [scala-execution-context-global-88] WARN com.thenewmotion.ocpp.json.api.CentralSystemOcpp1XConnectionComponent$CentralSystemOcpp1XConnection - Exception processing OCPP request Heartbeat: com.thenewmotion.ocpp.json.api.OcppException: com.thenewmotion.ocpp.json.PayloadErrorCode$NotImplemented$@72712127: Request type not implemented at com.thenewmotion.ocpp.json.api.OcppException$.apply(OcppConnectionComponent.scala:61) at com.thenewmotion.ocpp.json.example.ExampleServerTestApp$$anon$1.$anonfun$handleConnection$2(ExampleServerTestApp.scala:57) at com.thenewmotion.ocpp.json.api.RequestHandler$$anon$4.$anonfun$apply$4(RequestHandler.scala:68) at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659) at scala.util.Success.$anonfun$map$1(Try.scala:255) at scala.util.Success.map(Try.scala:213) at scala.concurrent.Future.$anonfun$map$1(Future.scala:292) at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33) at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64) at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
to a HeartBeat.Req [2,"1383653547","Heartbeat",{}]

Could you please tell me what is wrong with my code?

Thank you in advance.

@azolotko
Copy link
Contributor

azolotko commented Sep 24, 2021

@gianmarcoodorizzi Did you add it before or after case _?

@gianmarcoodorizzi
Copy link
Author

gianmarcoodorizzi commented Sep 24, 2021

Hello, I added before it! Here is the complete code:

package com.thenewmotion.ocpp
package json
package example

import java.time.ZonedDateTime
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.io.Source
import messages.v1x._
import api._
import com.thenewmotion.ocpp.json.v1x.v16.HeartbeatReq

object ExampleServerTestApp extends App {

val server = new Ocpp1XJsonServer(2345, Version.V16) {

override def handleConnection(chargePointIdentity: String, conn: Ocpp1XJsonServer.OutgoingEndpoint): CentralSystemRequestHandler = {

      conn.onClose.foreach(_ => println(s"Disconnected client $chargePointIdentity"))

      {
        (req: CentralSystemReq) =>

          println(s"Received request $req from client $chargePointIdentity")

          req match {
            case req: BootNotificationReq =>
              // let's send a GetConfiguration to see what this charge point is up to
              conn.send(GetConfigurationReq(Nil)) foreach { res =>
                println(s"Charge point $chargePointIdentity responded to GetConfiguration: $res")
              }

              BootNotificationRes(
                status = RegistrationStatus.Accepted,
                currentTime = ZonedDateTime.now(),
                interval = 5.minutes
              )

            case req: HeartbeatReq =>
              HeartbeatRes(currentTime = ZonedDateTime.now())

            case _ =>
              throw OcppException(PayloadErrorCode.NotImplemented, "Request type not implemented")
          }
      }
    }
  }

  server.start()

  println("Example server listening at port 2345. Press ENTER to exit.")
  Source.stdin.bufferedReader.readLine()

  server.stop()
}

Thank you

@azolotko
Copy link
Contributor

@gianmarcoodorizzi The problem is in import com.thenewmotion.ocpp.json.v1x.v16.HeartbeatReq. Just remove it and it should be fine because there's import messages.v1x._ already.

@gianmarcoodorizzi
Copy link
Author

@azolotko thanks, I added that (well, IntelliJ IDEA added it) because without it it would not even compile.
Indeeed I get the error:

ExampleServerTestApp.scala:38:23 not found: type HeartbeatReq case req: HeartbeatReq =>

@azolotko
Copy link
Contributor

azolotko commented Sep 24, 2021

@gianmarcoodorizzi Ok, now I see where the problem comes from. HeartbeatReq is defined as object. This means that if you want to match it, you should either do

case req: HeartbeatReq.type =>
  // ...

or

case HeartbeatReq =>
  // ...

The comment about import com.thenewmotion.ocpp.json.v1x.v16.HeartbeatReq still applies: it's unnecessary.

@gianmarcoodorizzi
Copy link
Author

Thank you very much!

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