- C++ 35.9%
- CMake 33.8%
- JavaScript 17.9%
- HTML 10.5%
- SCSS 1.4%
- Other 0.5%
| .yarn | ||
| cmake | ||
| docroot | ||
| fonts/raleway/v37 | ||
| init.d | ||
| src | ||
| webapp | ||
| .clang-format | ||
| .clang-tidy | ||
| .eslintrc.js | ||
| .gitignore | ||
| .yarnrc.yml | ||
| CMakeLists.txt | ||
| db-schema.sql | ||
| energyd.service.in | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| webpack.config.js | ||
| yarn.lock | ||
Energy Usage Monitor
This application is a real world example of a web application built on libzeep. It can be used to enter the current value of multiple usage meters and display the usage of energy over time.
Additionally, this software can monitor the status of one or more Sessy batteries and it will read data from a P1 port of your smart meter, if configured. When you have a Sessy, you should use a splitter and a P1 to USB converter like the one from Cedel.
Installation
To build and install energyd, you first need to install various other packages. Of course first of all you need libzeep. If you successfully installed libzeep, most of the requirements are already met, the remaining requirements are:
- Postgresql including the development files (on Debian use
apt install libpq-dev) - The javascript package manager yarn
- mrc, a resource compiler
Building the software is done by entering the following commands:
git clone https://forge.hekkelman.net/maarten/energyd.git
cd energyd
cmake -B build
cmake --build build
sudo cmake --install build
This should give you an executable called energyd installed in /usr/local/sbin.
Database
The software uses a postgresql database to store data. The following commands are executed as a user that has admin rights on your postgres installation. First create a new user for this database, this command will ask for a password which you will have to add to the connect URL for the database.
createuser -P energie-admin
Then create the database with the newly created user as owner:
createdb -O energie-admin energie
Finally fill the database with tables:
psql -h localhost -f db-schemal.sql energie energie-admin
Configuring
Command line arguments can also be specified using a configuration file called energyd.conf. A
file with this name is searched at startup time in the current working directory and in /etc.
All command line arguments can be specified in this file in the usual ini file format.
A minimal config file might look like this:
databank=postgresql://energie-admin:geheim@localhost/energie
address=localhost
sessy-1=http://192.168.178.25/api/v1/power/status
p1-device-power=/dev/ttyUSB0
p1-device-heat=/dev/ttyUSB1
Running
Now that the database is ready, we can start the application. There are several options you can give:
$ /usr/local/sbin/energyd --help
energyd [options] command
-h [ --help ] Display help message
-v [ --verbose ] Verbose output
--version Show version information
--address arg (=0.0.0.0) External address
--port arg (=10336) Port to listen to
--context arg External web address of this service
-F [ --no-daemon ] Do not fork into background
-u [ --user ] arg (=www-data) User to run the daemon
--web-user-name arg User account
--web-user-password arg User password
--web-secret arg Secret hash for web tokens
--databank arg The Postgresql connection string
--autolog-time arg The time of day to automatically log the status
--p1-device-heat arg (=/dev/ttyUSB0) The name of the device used to communicate with the P1 port
(Stadsverwarming)
--p1-device-power arg (=/dev/ttyUSB1) The name of the device used to communicate with the P1 port
(Elektriciteitsmeter)
--sessy-1 arg URL to fetch the status of sessy number 1
--sessy-2 arg URL to fetch the status of sessy number 2
--sessy-3 arg URL to fetch the status of sessy number 3
--sessy-4 arg URL to fetch the status of sessy number 4
--sessy-5 arg URL to fetch the status of sessy number 5
--sessy-6 arg URL to fetch the status of sessy number 6
--read-only Do not write data into the database (debug option)
Command should be either:
start start a new server
stop stop a running server
status get the status of a running server
reload restart a running server with new options
The option --databank contains the connection string to connect to postgresql in the form of a URL.
The default is to run the application in the background. In that case a daemon process is forked off. This daemon process opens the log files in /var/log/energyd and writes a process ID in /var/run/energyd. Then it starts to listen on the specified address and port.
In case you want to run the server in the foreground for debugging purposes you can use the --no-daemon flag.
The --web-user-name and --web-user-password arguments are optional. The password should be a pkdf2 hash, you
can create that with the (hidden) energyd passwd command.
Usage
This software actually combines two different things. Originally it was used to manually enter the readings of a smart meter and stadsverwarmingsmeter. I've done this for many years and this software can render nice graphs for electricity and warmth usage showing the current year in the context of history.
The meters are hard coded, so this is perhaps not very useful for others. To complicate matters further, all text in the user interface is in Dutch. The idea is that you regularly enter (Voeg toe button, or Invoer) the current values for the various meters. The graph (Grafieken) will then display your usage over time.
The second part was bolted on later when a Sessy battery entered our home. To monitor the loading and unloading of the battery a new graph was added using a new data table. This data is stored every two minutes automatically.