Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Trystan Lea committed Aug 2, 2020
2 parents f2c5878 + 0ef3f19 commit 9500e46
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 71 deletions.
33 changes: 19 additions & 14 deletions EmonPiFileSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ web server | Apache2 |
relational databases | mysql or maria |
key value database | redis-server | data buffering for timeseries and backgroud processing for service-runner
message broker | mosquitto |
data engine language |php with extensions | pear (for pecl needs)<br>libapache2-mod-php<br>mysql<br>gd, opcache, dev, common<br>mbstring<br>mcrypt<br>redis<br>mosquitto (https://github.com/mgdm/Mosquitto-PHP)<br>curl

Nota : mbcrypt DEPRECATED > to be replaced (sodium?)
data engine language |php with extensions | pear (for pecl needs)<br>mysql<br>gd dev, common<br>mbstring<br>redis<br>mosquitto (https://github.com/mgdm/Mosquitto-PHP)<br>curl


### EmonCMS systemd services
Expand All @@ -38,7 +36,7 @@ mysql.service -> /lib/systemd/system/mariadb.service
redis.service -> /lib/systemd/system/redis-server.service
```

phpmqtt input (PHP)|listen to payloads published to the mosquitto broker on topic emon|
phpmqtt input (PHP)|listen to payloads published to the mosquitto broker on topic emon
--|--
scriptpath | EMONCMS_WWW/scripts/services/emoncms_mqtt/emoncms_mqtt.php
Servicepath | EMONCMS_WWW/scripts/services/emoncms_mqtt/emoncms_mqtt.service
Expand All @@ -47,39 +45,46 @@ non globals | $connected, $subscribed, $last_retry, $last_heartbeat, $count
log | uses emoncms main log file <br>`journalctl -f -u emoncms_mqtt`
specific conf file | no

feedwriter (PHP)|writes input datas from redis-buffer to disk in order to feed the timeseries|
feedwriter (PHP)|writes input datas from redis-buffer to disk in order to feed the timeseries
--|--
scriptpath | EMONCMS_WWW/scripts/feedwriter.php
Servicepath | EMONCMS_WWW/scripts/services/feedwriter/feedwriter.service
globals | $log, $feed_settings, $mysqli, $redis <br> $user, $feed
log | uses emoncms main log file <br>`journalctl -f -u feedwriter`
specific conf file | no

Service-runner (Python)|trigger background workers from modules (update, backup, sync, postprocess)|
Service-runner (Python)|trigger background workers from modules (update, backup, sync, postprocess)
--|--
scriptpath | EMONCMS_WWW/scripts/services/service-runner/service-runner.py
Servicepath | EMONCMS_WWW/scripts/services/service-runner/service-runner.service
log | uses systemd log file <br>`journalctl -f -u service-runner`
specific conf file | no

emonhub (Python)| listen on serial port or ethernet and publish to mosquitto broker on topic emon|
emonhub (Python)| listen on serial port or ethernet and publish to mosquitto broker on topic emon
--|--
scriptpath | OPENENERGYMONITOR_DIR/emonhub/src/emonhub.py
Servicepath | OPENENERGYMONITOR_DIR/service/emonhub.service
log | log file is in /var/log/emonhub<br>`journalctl -u emonhub -n 30 –no-pager`
specific conf file | /etc/emonhub/emonhub.conf<br>/etc/emonhub/emonhub.env

emonPiLCD (Python)| manages the emonpi LCD screen
--|--
scriptpath | OPENENERGYMONITOR_DIR/emonpi/lcd/emonPiLCD.py
Servicepath | OPENENERGYMONITOR_DIR/emonpi/lcd/emonPiLCD.service
log | log file is in /var/log/emonpilcd<br>`journalctl -u emonPiLCD`
specific conf file | no

### EmonCMS modules

admin| module integrated in the core package - does not have its own git repo |
admin| module integrated in the core package - does not have its own git repo
--|--
place | EMONCMS_WWW/Modules/admin
globals | $mysqli,$session,$route,$updatelogin,$allow_emonpi_admin, $redis, $openenergymonitor_dir, $admin_show_update, $path <br> $log, $log_location, $log_enabled, $log_level
background workers | none
log | uses emoncms main log file
specific conf file | no

config|web interface to supervise and configure emonhub|
config|web interface to supervise and configure emonhub
--|--
place | EMONCMS_WWW/Modules/config
globals | $route, $session, $redis, $homedir
Expand All @@ -88,39 +93,39 @@ background workers | restart.sh
log | /var/log/emoncms/emonhub-restart.log
specific conf file | no

dashboard|Dashboard Module|
dashboard|Dashboard Module
--|--
place | EMONCMS_WWW/Modules/dashboard
globals | $mysqli, $session, $route, $path
background workers | no
log | no
specific conf file | no

graph|main graph module with averaging on the fly|
graph|main graph module with averaging on the fly
--|--
place | EMONCMS_WWW/Modules/graph
globals | $session,$route,$mysqli,$redis, $path
background workers | no
log | no
specific conf file | no

backup|import/export all timeseries+mysql database|
backup|import/export all timeseries+mysql database
--|--
place | EMONCMS_DIR/modules/backup
globals | $route, $session, $path, $redis, $linked_modules_dir, $log_location
background workers | emoncms-import.sh<br>emoncms-export.sh<br>emoncms-copy.sh ?<br>service-runner bash file why ? All things related to service-runner are in controller
log | EMONCMS_LOG_LOCATION/exportbackup.log <br>EMONCMS_LOG_LOCATION/importbackup.log
specific conf file | config.cfg which has to be set up during installation

sync|connect to distant EmonCMS machines to retrieve feeds <br> IOT flavoured alternative to backup|
sync|connect to distant EmonCMS machines to retrieve feeds <br> IOT flavoured alternative to backup
--|--
place | EMONCMS_DIR/modules/sync
globals | $linked_modules_dir,$path,$session,$route<br>$mysqli,$redis,$user,$feed_settings,$log_location<br> $log in model
background workers | emoncms-sync.sh launching sync_run.php in CLI
log | EMONCMS_LOG_LOCATION/sync.log <br> also uses emoncms main log file
specific conf file | no

postprocess|postprocess feeds - calculation module|
postprocess|postprocess feeds - calculation module
--|--
place |EMONCMS_DIR/modules/postprocess
globals | $linked_modules_dir,$session,$route,$mysqli,$redis,$feed_settings, $log_location
Expand Down
52 changes: 12 additions & 40 deletions install/emonpilcd.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
#!/bin/bash
source load_config.sh

sudo apt-get install -y python-smbus i2c-tools python-rpi.gpio python-gpiozero
sudo pip install xmltodict
echo "-------------------------------------------------------------"
echo "emonpiLCD install"
echo "-------------------------------------------------------------"
cd $openenergymonitor_dir

# Uncomment dtparam=i2c_arm=on
sudo sed -i "s/^#dtparam=i2c_arm=on/dtparam=i2c_arm=on/" /boot/config.txt
# Append line i2c-dev to /etc/modules
sudo sed -i -n '/i2c-dev/!p;$a i2c-dev' /etc/modules

if [ ! -d /var/log/emonpilcd ]; then
# emonPiLCD Logger
sudo mkdir /var/log/emonpilcd
sudo chown $user /var/log/emonpilcd
# Permissions?
touch /var/log/emonpilcd/emonpilcd.log
fi

# ---------------------------------------------------------
# Install service
# ---------------------------------------------------------
service=emonPiLCD

if [ -f /lib/systemd/system/$service.service ]; then
echo "- reinstalling $service.service"
sudo systemctl stop $service.service
sudo systemctl disable $service.service
sudo rm /lib/systemd/system/$service.service
else
echo "- installing $service.service"
fi

# Install emonpi repo if it doesnt already exist
if [ ! -d $openenergymonitor_dir/emonpi ]; then
echo "Installing emonpi repository"
cd $openenergymonitor_dir
git clone ${git_repo[emonpi]}
else
echo "- emonpi repository already installed"
git pull
fi

sudo cp $openenergymonitor_dir/emonpi/lcd/$service.service /lib/systemd/system
sudo sed -i "s~ExecStart=.*~ExecStart=/usr/bin/python $openenergymonitor_dir/emonpi/lcd/emonPiLCD.py~" /lib/systemd/system/$service.service
sudo systemctl enable $service.service
sudo systemctl restart $service.service

state=$(systemctl show $service | grep ActiveState)
echo "- Service $state"
# ---------------------------------------------------------
if [ -f $openenergymonitor_dir/emonpi/lcd/install.sh ]; then
$openenergymonitor_dir/emonpi/lcd/install.sh
else
echo "ERROR: $openenergymonitor_dir/emonpi/lcd/install.sh script does not exist"
fi
5 changes: 2 additions & 3 deletions update/emonpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo "-------------------------------------------------------------"
echo "EmonPi Firmware Update"
echo "-------------------------------------------------------------"

sudo service emonhub stop
sudo systemctl stop emonhub

echo "Start ATmega328 serial upload using avrdude with latest.hex"

Expand All @@ -15,5 +15,4 @@ echo "avrdude -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:$ope

avrdude -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:$openenergymonitor_dir/emonpi/firmware/compiled/latest.hex

sudo service emonhub start

sudo systemctl start emonhub
9 changes: 9 additions & 0 deletions update/emonsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
source load_config.sh

echo "-------------------------------------------------------------"
echo "EmonPi LCD Update"
echo "-------------------------------------------------------------"
if [ -f $openenergymonitor_dir/emonpi/lcd/install.sh ]; then
$openenergymonitor_dir/emonpi/lcd/./install.sh
fi
21 changes: 8 additions & 13 deletions update/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ if [ "$EUID" = "0" ] ; then
exit 0
fi

if [ "$type" == "all" ] || [ "$type" == "emonhub" ]; then
echo "Running apt-get update"
sudo apt-get update
fi

if [ "$emonSD_pi_env" = "1" ]; then
# Check if we have an emonpi LCD connected,
# if we do assume EmonPi hardware else assume RFM69Pi
Expand All @@ -46,7 +41,7 @@ if [ "$emonSD_pi_env" = "1" ]; then
if [ "$hardware" == "EmonPi" ]; then
# Stop emonPi LCD servcice
echo "Stopping emonPiLCD service"
sudo service emonPiLCD stop
sudo systemctl stop emonPiLCD

# Display update message on LCD
echo "Display update message on LCD"
Expand All @@ -58,6 +53,11 @@ if [ "$emonSD_pi_env" = "1" ]; then

fi

if [ "$type" == "all" ] || [ "$type" == "emonhub" ]; then
echo "Running apt-get update"
sudo apt-get update
fi

# -----------------------------------------------------------------

if [ "$type" == "all" ]; then
Expand Down Expand Up @@ -116,13 +116,8 @@ fi

# -----------------------------------------------------------------

if [ "$hardware" == "EmonPi" ]; then
echo
# Wait for update to finish
echo "Starting emonPi LCD service.."
sleep 5
sudo service emonPiLCD restart
echo
if [ "$type" == "all" ] && [ "$emonSD_pi_env" = "1" ]; then
$openenergymonitor_dir/EmonScripts/update/emonsd.sh
fi

# -----------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions update/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,26 @@ This script is triggered from emoncms via service-runner.

./service-runner-update.sh UPDATE_TYPE FIRMWARE
./service-runner-update.sh all emonpi

# How do the automatic update process work in practise ?

The automatic update process is managed from the admin module of emoncms.
It consists of 2 main steps, launched by two different shell scripts located in the `/opt/openenergymonitor/EmonScripts` folder :

1) [update/service-runner-update.sh](service-runner-update.sh)
2) [update/main.sh](main.sh)

## step 1 : update/service-runner-update.sh

- version check and comparison to labels stored in the safe-update file of the EmonScripts repository
- pull the latest version of the EmonScripts repository
- if version check is successfull, goto step 2

## step 2 : update/main.sh

### emonPiLCD & al example

- stop the emonPiLCD service
- launch the lcd/emonPiLCD_update.py from the emonpi repo (to display the "UPDATING..." message on the LCD)
- pull the emonpi repo
- run the update/emonpi.sh script of the EmonScripts repo, which runs the lcd/install.sh from the emonpi repo
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.9-beta
1.1.0-beta

0 comments on commit 9500e46

Please sign in to comment.