rasProject_01 / weSweetHome
R. 240
process control / RasPi software by weinert-automation
|
Common types, values and functions for a smart home project. More...
Data Structures | |
struct | cmdLookUp_t |
Structure for a defined remote command. More... | |
struct | dayStrtVal_t |
Day start values. More... | |
struct | meterVal_t |
One smart meter's readings. More... | |
struct | phPckSwSet_t |
Simple Structure for phase packet switch setting. More... | |
struct | valFilVal_t |
Smart meters' and other process values. More... | |
struct | valsSharMem_t |
Structure for shared memory. More... | |
Macros | |
#define | Amsk |
would give away | |
#define | ANZ_SEMAS |
Standard semaphore set size. More... | |
#define | ANZmodSLAVES |
Number of smart Modbus meters. More... | |
#define | AUTO_PPSWI_COMMAND |
auto control (ON=manual) | |
#define | BALL_CARLOAD_COMMAND |
car load as PV surplus ballast | |
#define | BAT_COMMANDS |
battery commands mask | |
#define | BATLOAD_COMMANDS |
battery loading commands mask | |
#define | BATUNL_COMMANDS |
battery unloading commands mask | |
#define | Bmsk |
Controlled load battery (as ballast) | |
#define | C250W_COMMANDS |
give 250 W command mask | |
#define | CARLOAD_COMMANDS |
car load command mask | |
#define | CHSBmsk |
CHS mode ballast (1: on at 0.. max power at surplus) | |
#define | CHScarC |
CHS loading station: car connected to EVSE. | |
#define | CHScPow |
CHS loading station: power line connected to car. | |
#define | CHSiLhi |
CHS current limit at hi border. | |
#define | CHSiLiM |
CHS current limit at one border mask. | |
#define | CHSiLlo |
CHS current limit at lo border (usually 6A fixed) | |
#define | CHSMmsk |
CHS mode manual (1: on at max power) | |
#define | CHSphas |
CHS number of phases: 1..6; 0, 7 not used; 3 default. | |
#define | CHSphHi |
CHS number of phases at hi limit (1..6) | |
#define | CHSphLo |
CHS number of phases at lo limit (usually 1 fixed) | |
#define | CHSphMs |
CHS number of phases at limit mask. | |
#define | cmdBits_t |
Type for command bits. More... | |
#define | DEC_CARLOAD_COMMAND |
car load decrease max. current | |
#define | DECLIM_PPSWI_COMMAND |
reduce PPSWI limit (by 300W) | |
#define | DECR_PPSWI_COMMAND |
decrement (-1) PPSWI power | |
#define | getNoPhas() |
Get number of phases. More... | |
#define | GIVE250_COMMANDS |
commands concerning Plg01 & Rel5 | |
#define | Gmsk |
Give away: Alarm / add ballast / etc. | |
#define | HIPPO_COMMANDS |
Mask for all Hippogreiff commands. More... | |
#define | HWPUMP_COMMANDS |
comfort pump command mask | |
#define | INC_CARLOAD_COMMAND |
car load increase max. current | |
#define | INC_PPSWI_COMMAND |
increment (+1) PPSWI power | |
#define | INCLIM_PPSWI_COMMAND |
increase PPSWI limit (by 200W) | |
#define | inv2Panel(x) |
Inverter (mJ) is connected to panel. | |
#define | Kmsk |
Keep battery (minimal load voltage) | |
#define | Lmsk |
Load battery (normal program) | |
#define | LOWER_BATLOAD_COMMAND |
lower battery loading power | |
#define | LOWER_PPSWI_COMMAND |
lower PPSWI power | |
#define | OFF_C250W_COMMAND |
off control give 250 W | |
#define | OFF_CARLOAD_COMMAND |
E-car load off. | |
#define | OFF_HIPPO_COMMAND |
off Hippogreiff | |
#define | OFF_PLG1_COMMAND |
off Plug01 give 250 W | |
#define | OFF_PLG2_COMMAND |
off Plug02 | |
#define | OFF_PLG3_COMMAND |
off Plug03 | |
#define | OFF_PLG4_COMMAND |
off Plug04 | |
#define | OFF_PPSWI_COMMAND |
off PPSWI (Power packet switching) | |
#define | ON_C250W_COMMAND |
on control give 250 W | |
#define | ON_CARLOAD_COMMAND |
E-car load on. | |
#define | ON_HIPPO_COMMAND |
on Hippogreiff | |
#define | ON_PLG1_COMMAND |
on Plug01 give 250 W | |
#define | ON_PLG2_COMMAND |
on Plug02 | |
#define | ON_PLG3_COMMAND |
on Plug03 | |
#define | ON_PLG4_COMMAND |
on Plug04 | |
#define | ONMAN_PPSWI_COMMAND |
on and manual PPSWI PPSWI | |
#define | P2sPmsk |
PPS element 2 power * 50% (0:0% .. 2:100%) | |
#define | PCK100PERC_POWER |
Phase packet switching device. More... | |
#define | PCK1PERC_POWER |
phase packet switch 1% power / W | |
#define | PCK50PRC_POWER |
phase packet switch 50% power / W | |
#define | PHDEC_CARLD_COMMAND |
assume E-cars using 1 phase less | |
#define | PHINC_CARLD_COMMAND |
assume E-cars using 1 phase more | |
#define | PLG1_COMMANDS |
Plug01 command mask. | |
#define | PLG2_COMMANDS |
Plug02 command mask. | |
#define | PLG3_COMMANDS |
Plug03 command mask. | |
#define | PLG4_COMMANDS |
Plug04 command mask. | |
#define | PPSLmsk |
PPS max at limit (1: at 0.0 or PCK_POWER_LIM_MAX) | |
#define | PPSMmsk |
PPS mode manual (0: automatic, default) | |
#define | PPSUmsk |
PPS power at limit PCK_POWER_LIM_MAX. | |
#define | PPSWI_COMMANDS |
Power packet switching commands. | |
#define | PUMP_STRT_POWR |
Pump start heating power; see PUMP_STRT_TEMP. | |
#define | PUMP_STRT_TEMP |
Water (tank) temperature to start comfort pump when heating. More... | |
#define | RAISE_BATLOAD_COMMAND |
raise battery loading power | |
#define | RAISE_PPSWI_COMMAND |
raise PPSWI power | |
#define | SAFE_TEMP_WAT |
Upper limit of safe water (tank) temperature. More... | |
#define | SEMAPHORE_KEY |
Semaphore unique key "KÇÏfig24". | |
#define | SHARED_MEM_DATA_SIZE |
Size of defined master slave communication data in shared memory. More... | |
#define | SHARED_MEM_FILL_SIZE |
Size of extra fill array to have a standard shared memory size. | |
#define | SHARED_MEMORY_KEY |
Shared memory key "Buffer24". | |
#define | SHARED_MEMORY_SIZE |
Shared memory size 256 byte. | |
#define | Smsk |
Solar power is generated. | |
#define | START_BATKEEP_COMMAND |
start battery keep alive (with load) | |
#define | START_BATLOAD_COMMAND |
start battery loading | |
#define | START_BATUNL_COMMAND |
start battery unloading | |
#define | START_HWPUMP_COMMAND |
start hot water comfort pump | |
#define | STD_CARLOAD_COMMAND |
set 3 phases and 16A (11kW) | |
#define | STOP_BAT_COMMAND |
stop battery unloading & loading | |
#define | STOP_HWPUMP_COMMAND |
stop hot water comfort pump | |
#define | Umsk |
Unload battery commanded. | |
#define | UNUSED_COMMANDS |
4 unused command bits (June 2023) | |
#define | Wmsk |
Would give away 250W or more. | |
Functions | |
float | pwmToVolt (uint8_t const pwm) |
Output voltage of battery load module by PWM signal. More... | |
Variables | |
cmdLookUp_t | cmdLookUp [] |
The common command look up table. More... | |
volatile float | fLine |
Last valid power line frequency. More... | |
float const | loadModUlookup [256] |
Output voltage of electronic battery load module. More... | |
float const | phPckSwPow [101] |
First (or only) phase packet switching device power look up. | |
phPckSwSet_t const | phPckSwSets [101] |
The packet switch control values. More... | |
smdX30modbus_t | smdX30modbus [2] |
Descriptive and state array for smart meters on Modbus. More... | |
volatile int | tempTankWater |
Last value of tank water temperature. More... | |
volatile uint8_t | tempWaterBadCnt |
Tank water temperature bad read count. More... | |
valFilVal_t | valFilVal |
All process values relevant for log files and HMI. | |
Common types, values and functions for a smart home project.
Revision history
In the smart home's PV under control, we assume one smart meter for the whole house's (public) electricity supply and one for solar generators and battery storage. The (two, cf. ANZmodSLAVES) meters are Modbus controlled.
Additionally we have home and PV related process control.
The process IO related definitions are mostly in include/sweetHome2.h
This include file collects some configuration and naming common to
a) the process control program
b) a console HMI program and the
c) server side program(s) (CGI) for the web interfaces
All those programs, running on the system for process control and I/O, are written in C. The client side programming for the web HMI is in Javascript.
The server side programs communicate via shared memory and a set of three (ANZ_SEMAS) semaphores.
#define ANZ_SEMAS |
Standard semaphore set size.
Usually three (3..10)
#define ANZmodSLAVES |
Number of smart Modbus meters.
Usually two.
#define cmdBits_t |
Type for command bits.
Commands to the process control program from outside are transferred via shared memory as one bit set for every command to be executed. The bit position (0..31, as of May 2018) defines a concrete command.
"From outside" usually means from a web interface (html page with Javascript) and AJAX to a C written GCI program communicating via shared memory with the process control program. In this schema the CGI program sets bits for commands to be executed and the process control program clears the bit(s) in question on commands executed (or rejected).
Remark: On contradictory commands, ONyxz and OFFxyz, one will be executed and both will be cleared. In cases like this OFF... usually gets priority.
Remark 2: When exceeding 32 distinct commands we may switch to a uint64_t as wasdone from 16_t to 32_t in May 2018.
#define HIPPO_COMMANDS |
Mask for all Hippogreiff commands.
Hippogreiff stands for a relay controlled 12V supply from storage battery. It should be ON at night, or more precisely either between sunset and sunrise or from dusk to dawn.
One consumer on this rail is a green LED beam to a little Hippogreiff sculpture. Hence the name.
The Hippogreiff is mythical beast with similarities to Harry Potter's Hippogreif, as long as looked at from the front. Seen from side one realises him being another species.
#define PCK100PERC_POWER |
Phase packet switching device.
Since Rev. 157 (07-2018) we have one single phase heating device with then 950 W power, raised 03.2020 to 1267W and 02.2023 to 1845. It is actuated by a zero crossing electronic switch (SSR) at pin PH_P_SSR1 controlling the amount of power in 1% (PCK1PERC_POWER) steps.
For robustness and safety this electronic relay sits behind a 10A relay.
Since march 2023 we have two heater elements of 2kW each:
heater element 1 phase packet switch SSR1 PH_P_SSR1) 0..100%
heater element 1 phase packet switch SSR1 PH_P_SSR1) 0, 50, 100%
While the first one is controlled in 101 steps as before, the second one got three states: off, half and full power. This effectively gives a range of 0 to about 4kW in 201 steps. In the present configuration any PV surplus can be handled as in-house-consumption (Eigenverbrauch).
#define SAFE_TEMP_WAT |
Upper limit of safe water (tank) temperature.
The integer value for safe water (tank) temperature sensor reading is +68950 m°C respectively 69 °C. Above this value all (electric) heating must stop.
#define PUMP_STRT_TEMP |
Water (tank) temperature to start comfort pump when heating.
The integer value for pump start water (tank) temperature sensor reading is +58950 m°C respectively 59 °C. Above this value electric heating with >= 1kW (surplus) power shall start the (comfort) circulation pump while heating with electrical (surplus) power.
This is done in the hope to disturb the temperature layers in the tank and, hence, reduce hot water outlet temperature.
#define getNoPhas | ( | ) |
Get number of phases.
#define SHARED_MEM_DATA_SIZE |
Size of defined master slave communication data in shared memory.
This macro calculates the size in bytes of the shared memory area, see valsSharMem_t. The size of the shared memory SHARED_MEMORY_SIZE should be chosen as a multiple of 256 (512) bytes. The extra bytes are usable as an array uint8_t fill[] of size SHARED_MEM_FILL_SIZE.
float pwmToVolt | ( | uint8_t const | pwm | ) |
Output voltage of battery load module by PWM signal.
Note: Currently, this function is used for the user interface - not for process control.
pwm | PWM signal 0 (lowest) .. 255 (highest output voltage) |
|
extern |
Output voltage of electronic battery load module.
Depending on the (400Hz) PMW signal width 0..255 (/255 * 100% width) the battery load module will deliver about 11 to 15V. If the battery voltage is higher than the output voltage no current will flow (i.e. nothing happens). If the battery voltage is lower, up to 15A will be delivered. This current limit is implemented / fixed by the power module used. Hence, getting less current respectively power requires a fine control of the PWM signal (see POWH).
This array gives the module output voltage as function of the PWM width (=index) in the usable range 0..141.
|
extern |
Descriptive and state array for smart meters on Modbus.
The number of meters is ANZmodSLAVES.
|
extern |
The common command look up table.
It must end with an entry {"", 0}.
The current (CGI) program uses linear search for the command mnemonic. Hence, and cause of structure, alphabetic sorting is of no avail.
|
extern |
The packet switch control values.
The array holds the number of on and off phases (i.e. 20 ms periods at 50 Hz line frequency) for each percentage of full power. The array length is 101; the index [0..100] is, hence, directly the percentage wanted.
To avoid too visible flicker, for no set (phPckSwSets[i].onPhases, phPckSwSets[i].offPhases) the smaller of the two values would be greater than 4 (80 ms); in most cases it is 1 or 2 (40 ms).
|
extern |
Last valid power line frequency.
The measurement is taken from the more precise home three phase meter if communicative via Modbus. Otherwise the other meter's value is taken if available. Due to slow Modbus communication the values may be older than two seconds worst case.
This low sampling rate won't comply with VDE-AR-N 4105 cut off rules requiring a 0.1s reaction outside 47.5..51.5Hz. Nevertheless the current experimental set-up is a working proof-of-concept implementation (with very low power) — and a faster frequency measurement could easily be implemented.
Last valid power line frequency.
|
extern |
Last value of tank water temperature.
This value will be the last good .tempTankTop (see valFilVal_t) or the last good .tempPipe. If neither is good for 251 measurements BAD_TEMP_READ (an incredibly high value) will be set.
This last tank water temperature will be checked against a safety limit to allow electric heating as ballast.
The value is in units of 1/1000 grdC.
|
extern |
Tank water temperature bad read count.
This last tank water temperature will be checked against a safety limit to allow electric heating as ballast.
In case of too many bad reads the value must be fixed at 253