From 1b5af0d2e2218cdc9bcb59d10206139bb02fa06d Mon Sep 17 00:00:00 2001 From: uhi22 Date: Sat, 13 May 2023 20:27:08 +0200 Subject: [PATCH] feature: exit if connectionLevel decreases from full. Raspberry docu improved. --- connMgr.py | 11 +++++++++++ doc/installation_on_raspberry.md | 13 +++++++++++-- doc/pyPlc.ini.template | 7 +++++-- starter.sh | 8 +++++--- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/connMgr.py b/connMgr.py index bd73bb1..795bb83 100644 --- a/connMgr.py +++ b/connMgr.py @@ -13,6 +13,9 @@ # the lower-layer state machine can stay silent as long as the upper layers are working # fine. +from configmodule import getConfigValue, getConfigValueBool +import sys # For exit_on_session_end hack + CONNLEVEL_100_APPL_RUNNING = 100 CONNLEVEL_80_TCP_RUNNING = 80 CONNLEVEL_50_SDP_DONE = 50 @@ -98,6 +101,14 @@ class connMgr(): self.ConnectionLevel=0 if (self.ConnectionLevelOld!=self.ConnectionLevel): self.addToTrace("[CONNMGR] ConnectionLevel changed from " + str(self.ConnectionLevelOld) + " to " + str(self.ConnectionLevel)) + if ((self.ConnectionLevelOld==100) and (self.ConnectionLevel<100)): + # We had a charging session, and now it is gone. + # Depending on configuration option, we may end the script here. + if getConfigValueBool("exit_on_session_end"): + # TODO: This is a hack. Do this in fsmPev instead? + self.addToTrace("[CONNMGR] Terminating the application.") + sys.exit(0) + self.ConnectionLevelOld = self.ConnectionLevel if ((self.cycles % 33)==0): # once per second diff --git a/doc/installation_on_raspberry.md b/doc/installation_on_raspberry.md index 3325b96..d23a436 100644 --- a/doc/installation_on_raspberry.md +++ b/doc/installation_on_raspberry.md @@ -83,6 +83,15 @@ Try-out the cooperation of Python with the EXI encoder/decoder: ``` This should run some decoder/encoder tests and report in the end "Number of fails: 0". +Copy the pyPlc.ini.template into the same directory where pyPlc.py is, and rename it to pyPlc.ini. Edit the settings in this file as you need. + +Make some files executable: +``` + chmod 744 c55* + chmod 744 pevNoGui.py + chmod 744 starter.sh +``` + As first test, use the simulation mode (no need for modems or other hardware). Start the EVSE in simulation mode `sudo python pyPlc.py E S`. Open a second console window, and start here the pev in simulation mode @@ -111,8 +120,8 @@ In this file, we write the following, to configure the new service: [Service] Type=simple - ExecStart=/home/pi/myprogs/pyPlc/starter.sh - Restart=on-abort + ExecStart=/home/pi/myprogs/pyPLC/starter.sh + Restart=always [Install] WantedBy=multi-user.target diff --git a/doc/pyPlc.ini.template b/doc/pyPlc.ini.template index 1b92147..21c82ac 100644 --- a/doc/pyPlc.ini.template +++ b/doc/pyPlc.ini.template @@ -66,8 +66,11 @@ u_delta_max_for_end_of_precharge = 10 # The serial port and baud rate used for communication. Used # for serial devices like Dieter, OLED-Display and # celeron55's measuring and switching device -serial_port = /dev/ttyS1 -serial_baud = 115200 +# Examples: +# /dev/ttyS1 +# auto +serial_port = auto +serial_baud = 19200 # The target voltage used in the CurrentDemandRequest. # This is a value for first try-outs. Better would diff --git a/starter.sh b/starter.sh index f543319..07273e3 100755 --- a/starter.sh +++ b/starter.sh @@ -29,13 +29,15 @@ set -euv # Keep all IPv6 addresses on the interface down event. # Todo: flexible interface name. +# Todo: On raspberry, without NetworkManager, this option does not help. After the down and up (see below), the IPv6 is missing. sysctl net.ipv6.conf.eth0.keep_addr_on_down=1 # Shut down and activate the interface. -# Todo: Why this needed? -ip link set eth0 down +# Todo: Why this needed? On raspberry, where the NetworkManager is not runnning, this disturbs, because +# afterwards the pyPlc does not see the interfaces IPv6 address. +# ip link set eth0 down sleep 1 -ip link set eth0 up +# ip link set eth0 up sleep 1 # show the addresses