Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Aug 17, 2022
1 parent fec0de9 commit 6dbad51
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sphinx>=5.1.1
25 changes: 25 additions & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'BEMServer'
copyright = '2022, Nobatek/INEF4'
author = 'Nobatek/INEF4'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
193 changes: 193 additions & 0 deletions source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
=========
BEMServer
=========

**BEMServer** is a free Building Energy Management software platform.

Its purpose it to store data collected in buildings and produce useful
information such as performance indicators or alerts.

BEMServer comes with a set of basic services and is meant to be extended with
external services.

BEMServer uses a relational database to store

- informations about the buildings
- timeseries data (sensors measurements, indicators,...)
- events (alerts, logbook,...)

BEMServer manages data access permissions by groups of users.


Basic concepts
==============

The high-level entity for a project is the campaign. A campaign may span on
several sites and buildings. It has beginning and end dates, although the end
date may be left open to let the campaign last indefinitely.

Users are associated to user groups. User groups provide access to campaigns.

Timeseries and events data in a campaign may be split into separate scopes.
Campaign scopes are used to organize data and to provide more fine-grained
permissions.


Architecture
============

BEMServer is made of several software bricks.

BEMServer Core
--------------

BEMServer Core is the central part. It is responsible for the connection with
the database. It exposes objects that can be used by other blocks.

It implements the authorization and authorization layer.

It is meant to be imported and used by blocks trusted code as it gives direct
acces to the database.

BEMServer API
-------------

BEMServer API is a web REST API that exposes the core. It can be exposed over
the Internet to be accessed by external modules.

It exposes its own documentation in the OpenAPI format for module developers.

BEMServer UI
------------

BEMServer UI is the web interface to BEMServer. It communicates with the core
via BEMServer API.

This is the part that is meant to be exposed to final users.

It provides an interface for both administrative tasks (user management,...)
and data analysis (data visualization).


Installation
============

To get BEMServer up and running, one needs to run both BEMServer API and
BEMServer UI.

All BEMServer blocks are written in Python and require Python 3.9+.

The instructions that follow are tested on a Debian 11 (Bullseye) system.

Prerequisites
-------------

BEMServer relies on PostgreSQL and the TimescaleDB extension.

First, install PostgreSQL 13::

$ aptitude install postgresql

TimescaleDB is not in the Debian repositories. Follow instructions in
https://docs.timescale.com/latest/getting-started/setup

.. note::
There is no need to install PostgreSQL from external repositories as
suggested in TimescaleDB docs.

Create a database and install TimescaleDB extension (should be done after each
TimescaleDB update).

Assuming the user has database creation permission:::

$ createdb bemserver
$ psql -U $USER -d bemserver -c "CREATE EXTENSION IF NOT EXISTS timescaledb"

Install prerequisites for psycopg2 compilation (used by BEMServer Core)::

$ aptitude install python3-dev libpq-dev

BEMServer API
-------------

.. note::
It is advised to work in a dedicated virtual environment.

Install bemserver_api::

$ pip install bemserver_core

Database setup
^^^^^^^^^^^^^^

Set DB URI in an environment variable (adapt line with actual values)::

$ export SQLALCHEMY_DATABASE_URI="postgresql+psycopg2://user:password@localhost:5432/bemserver"

Use `setup_db` command to initialize a clean database::

$ bemserver_setup_db

Create an admin user::

$ bemserver_create_user --name chuck --email chuck@norris.com --admin

API setup
^^^^^^^^^

Create a configuration file (e.g. bemserver-api.cfg). Add API parameters:

.. code-block::
SQLALCHEMY_DATABASE_URI="postgresql+psycopg2://user:password@localhost:5432/bemserver"
Set an environment variable to point to that file::

$ export FLASK_SETTINGS_FILE="/path/to/bemserver-api.cfg"

At this point, the web API can be launched from the command line::

$ flask run

It can be accessed in a local browser at http://localhost:5000.

.. warning::
While this is fine in development mode, production setups should use a real
webserver such as Apache or Nginx.


BEMServer UI
------------

.. note::
It is advised to work in a dedicated virtual environment.

Install bemserver_ui::

$ pip install bemserver_ui

UI setup
^^^^^^^^

Create a configuration file (e.g. bemserver-ui.cfg). Add UI parameters:

.. code-block::
BEMSERVER_API_HOST = "localhost:5000"
BEMSERVER_API_USE_SSL = False
Set an environment variable to point to that file::

$ export FLASK_SETTINGS_FILE="/path/to/bemserver-ui.cfg"

At this point, the web UI can be launched from the command line::

$ flask run -p 5001

.. note::
Flask uses port 5000 by default. Be sure to specify another port for either
bemserver_api or bemserver_ui to avoid a conflict.

.. warning::
While this is fine in development mode, production setups should use a real
webserver such as Apache or Nginx.

0 comments on commit 6dbad51

Please sign in to comment.