use TCP port announced by SDP instead of static 15118

This commit is contained in:
uhi22 2022-12-01 11:51:11 +01:00
parent 11357e94dc
commit b03e345848
3 changed files with 26 additions and 5 deletions

View file

@ -23,6 +23,7 @@ class addressManager():
self.findLinkLocalIpv6Address() self.findLinkLocalIpv6Address()
self.pevIp="" self.pevIp=""
self.SeccIp="" self.SeccIp=""
self.SeccTcpPort = 15118 # just a default. Will be overwritten during SDP if we are pev.
pass pass
def findLinkLocalIpv6Address(self): def findLinkLocalIpv6Address(self):
@ -160,11 +161,21 @@ class addressManager():
else: else:
# the parameter was a string, assumingly. Just take it over. # the parameter was a string, assumingly. Just take it over.
self.SeccIp = SeccIp self.SeccIp = SeccIp
print("[addressManager] EVCC has IP " + self.SeccIp) print("[addressManager] charger has IP " + self.SeccIp)
def getSeccIp(self): def getSeccIp(self):
# The IPv6 address of the charger. Type is String. # The IPv6 address of the charger. Type is String.
return self.SeccIp return self.SeccIp
def setSeccTcpPort(self, SeccTcpPort):
# During SDP, the TCP port of the charger was found out. Store it, we need it later.
self.SeccTcpPort = SeccTcpPort
print("[addressManager] charger has TCP port " + str(self.SeccTcpPort))
def getSeccTcpPort(self):
# The chargers TCP port, which it announced in the SDP response.
return self.SeccTcpPort
def getLocalMacAddress(self): def getLocalMacAddress(self):
print("[addressManager] will give local MAC " + prettyMac(self.localMac)) print("[addressManager] will give local MAC " + prettyMac(self.localMac))

View file

@ -52,8 +52,9 @@ class fsmPev():
def stateFunctionConnecting(self): def stateFunctionConnecting(self):
if (self.cyclesInState<30): # The first second in the state just do nothing. if (self.cyclesInState<30): # The first second in the state just do nothing.
return return
evseIp = self.addressManager.getSeccIp() # the EVSE IP address which was found out with SDP evseIp = self.addressManager.getSeccIp() # the chargers IP address which was announced in SDP
self.Tcp.connect(evseIp, 15118) # This is a blocking call. If we come back, we are connected, or not. seccTcpPort = self.addressManager.getSeccTcpPort() # the chargers TCP port which was announced in SDP
self.Tcp.connect(evseIp, seccTcpPort) # This is a blocking call. If we come back, we are connected, or not.
if (not self.Tcp.isConnected): if (not self.Tcp.isConnected):
# Bad case: Connection did not work. May happen if we are too fast and the charger needs more # Bad case: Connection did not work. May happen if we are too fast and the charger needs more
# time until the socket is ready. Or the charger is defective. Or somebody pulled the plug. # time until the socket is ready. Or the charger is defective. Or somebody pulled the plug.

View file

@ -109,8 +109,14 @@ class ipv6handler():
self.SdpPayload = bytearray(20) # SDP response has 20 bytes self.SdpPayload = bytearray(20) # SDP response has 20 bytes
for i in range(0, 16): for i in range(0, 16):
self.SdpPayload[i] = self.SeccIp[i] # 16 bytes IP address of the charger self.SdpPayload[i] = self.SeccIp[i] # 16 bytes IP address of the charger
self.SdpPayload[16] = 15118 >> 8 # SECC port high byte. Port is always 15118. # Here the charger decides, on which port he will listen for the TCP communication.
self.SdpPayload[17] = 15118 & 0xFF # SECC port low byte. Port is always 15118. # We use port 15118, same as for the SDP. But also dynamically assigned port would be ok.
# The alpitronics seems to use different ports on different chargers, e.g. 0xC7A7 and 0xC7A6.
# The ABB Triple and ABB HPC are reporting port 0xD121, but in fact (also?) listening
# to the port 15118.
seccPort = 15118
self.SdpPayload[16] = seccPort >> 8 # SECC port high byte.
self.SdpPayload[17] = seccPort & 0xFF # SECC port low byte.
self.SdpPayload[18] = 0x10 # security. We only support "no transport layer security, 0x10". self.SdpPayload[18] = 0x10 # security. We only support "no transport layer security, 0x10".
self.SdpPayload[19] = 0x00 # transport protocol. We only support "TCP, 0x00". self.SdpPayload[19] = 0x00 # transport protocol. We only support "TCP, 0x00".
showAsHex(self.SdpPayload, "SDP payload ") showAsHex(self.SdpPayload, "SDP payload ")
@ -178,7 +184,10 @@ class ipv6handler():
# at byte 8 of the UDP payload starts the IPv6 address of the charger. # at byte 8 of the UDP payload starts the IPv6 address of the charger.
for i in range(0, 16): for i in range(0, 16):
self.SeccIp[i] = self.udpPayload[8+i] # 16 bytes IP address of the charger self.SeccIp[i] = self.udpPayload[8+i] # 16 bytes IP address of the charger
# Extract the TCP port, on which the charger will listen:
seccTcpPort = (self.udpPayload[8+16]*256) + self.udpPayload[8+16+1]
self.addressManager.setSeccIp(self.SeccIp) self.addressManager.setSeccIp(self.SeccIp)
self.addressManager.setSeccTcpPort(seccTcpPort)
return return
print("v2gptPayloadType " + hex(v2gptPayloadType) + " not supported") print("v2gptPayloadType " + hex(v2gptPayloadType) + " not supported")