Skip to content

Software explenation

Jan-Paulussen edited this page Nov 5, 2023 · 2 revisions

The software is mostly in Python, and partial in ansi-C. And of course the webpages are written in HTML or PHP. There is an SQL database that keeps all data, accessed and written to by the various programs.

The details on the software files are in teh explenation.html file (accessible also on the webserver), and the code holds a lot of expenation in the source code. Here below is a copy of that, but it might not be up to date...

Structure, I/O assignement & Bugs:

LAMP-server --index.html (Main page, with links to the other pages) Subpages from the menu

MQTT-client -- Is separate packet must be installed (e.g. with pip, MQTT-server en MQTT-clients installing)

--slow.py - in crontab Records values, every minute, in the SQL table Battery_log (Not programmed yet!)

Python controls:

--main.py : Should NOT be run as root. (Just 'python main.py' Program that first loads all python scrips, and runs the initial ones once. Then it start a loop for all recursive modules. They controls physical GPIO, the triacs/optocouplers for the resistorbanks only (at fast speed!), It only reads the status for the 3 resistors from the database, and sets them accordingly on/off or at a percentage. (:HeatResistor1/2/C) It therefore does not matter if the system is manual or not, only the values written in the database for each output matter It does control the fan (the fan is controlled in the slower control-program in the sudo crontab!

Subroutines from main:

--fan.py Program that controles the fan, so reads the database and sets GPIO pin accordingly

--afterheating.py Program that controles the afterheating (no accumulation), so reads the database and sets GPIO pin accordingly

--batterytemperature.py Program that reads the temperature inside the battery (PT100) and writes it in the database

--mqtt.py Program thats is triggered every time a message from the smart meter is received |-- This is initiated in the main.py program, but on called on a message as an interupt

--percentage_to_control.py Program that calculates from total percentage to individual powers, and writes this in the database

--bank.py Program that sets GPIO to individual resistorbanks, written in python, replaced by program below --bankc.py Old Python program that sets GPIO to individual resistorbanks by calling the C-program dytycycle every second |-- dutycycle C-program that sets GPIO to individual resistorbanks, called by the Python program bankc.py every second it has 3 command line arguments: percentage for each bank for the dutycycle || The dutycycle program (both the source and the compiled program) is in the directory ./home/pi, so not in the webserver directory! ||-- to be compiled with the additional library like so: gcc -o dutycycle dutycycle.c -lwiringPi

--mqtt.py mqtt.py will interrups and calculate new percentage when message is received from smart meter (in auto)

--banktest.py Program that tests the power a resistor bank is using. It's done by switching on and off the bank and read the difference from the smart metering. By doing this a number of times, a reasonable measurement is achieved (but it is somewhat depending on the temperature of the bank/resistor) It should NOT go in the crontab, but only be run from the command line at startup, to establish the constants.

Crontab: to start below programs at boot (and with some delays) ---main.py Script that reads the initialisation and then does the cyclec program ---slow.py still to be written: Does slow control / Records all values every minute, for graphs and calculations (not programmed yet)

//Here blow the IO pin assignement of the hardware-----------------------------------------------------------------------------------------------------------------------------------------------

I/O definition GPIO20 (pin38) = Zero detection input wPi=26 (for C-programmaing)

GPIO21 (pin 40)= Resistorbank1 (Red) wPi=29 GPIO12 (pin32) = Resistorbank2 (Red) wPi=26 GPIO16 (pin36) = Resistorbank3 (Red) wPi=27 GPIO26 (pin37) = Fan (yellow) GPIO19 (pin35) = after heating (Blue) Power Led = (Green)

Todo/Bugs:

  • Berekenen en sturen weerstanden batterij
  • Gaat bij volledige overschot niet verder dan 'on/on/30%'?!
  • Zelfs bij stroomtekort gaat rode led nog lichtjes knipperen
  • Setup tables in database in logging?
  • inbouwen en inlezen PT100 DONE!
  • BACKUPS!!!(HeatBattery)
Clone this wiki locally