Skip to content

Commit

Permalink
installation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 5, 2021
1 parent 7e64146 commit ce6309c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
33 changes: 24 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
install-python:
install-git:
sudo apt-get update
sudo apt-get install git

install-python:
sudo apt install -y python3-pip
sudo apt-get install -y python3-numpy

Expand Down Expand Up @@ -76,7 +79,7 @@ logging-files:

install-db:
sudo apt-get install -y sqlite3
mkdir /home/pi/db
mkdir -p /home/pi/db
touch /home/pi/db/pioreactor.sqlite
sqlite3 /home/pi/db/pioreactor.sqlite < sql/create_tables.sql

Expand All @@ -91,25 +94,37 @@ install-ui:

# get latest pioreactorUI release from Github.
cd /home/pi/
mkdir /home/pi/pioreactorui
curl -L https://api.github.com/repos/pioreactor/pioreactorui/tarball | tar -zxv -C /home/pi/pioreactorui --strip-components=1
git clone https://github.com/Pioreactor/pioreactorui.git --depth 1
# Use below to not have to use git
# mkdir /home/pi/pioreactorui
# curl -L https://api.github.com/repos/pioreactor/pioreactorui/tarball | tar -zxv -C /home/pi/pioreactorui --strip-components=1

# install required libraries
npm --prefix /home/pi/pioreactorui/client install
npm --prefix /home/pi/pioreactorui/backend install
sudo npm install pm2@latest -g

install-worker: install-python configure-rpi systemd-worker install-i2c install-pioreactor-worker logging-files
install-worker: install-git install-python configure-rpi systemd-worker install-i2c install-pioreactor-worker logging-files

install-leader: install-python install-mqtt configure-mqtt-websockets configure-rpi install-db install-pioreactor-leader systemd-leader logging-files
install-leader: install-git install-python install-mqtt configure-mqtt-websockets configure-rpi install-db install-pioreactor-leader systemd-leader logging-files install-ui
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
sudo apt-get install sshpass

install-leader-as-worker: install-leader install-worker
configure-hostname:
read -e -p "Enter new Pioreactor name: " userEnteredPioName
sudo hostname $$userEnteredPioName
hostname | sudo tee /etc/hostname

wget https://github.com/cbednarski/hostess/releases/download/v0.5.2/hostess_linux_arm
chmod a+x hostess_linux_arm
sudo ./hostess_linux_arm rm raspberry
sudo ./hostess_linux_arm add "$${userEnteredPioName}" 127.0.1.1

install-leader-as-worker: configure-hostname install-leader install-worker
# I had trouble with variables, quotes and dollar signs, so https://stackoverflow.com/questions/10121182/multiline-bash-commands-in-makefile/29085684#29085684
{ \
set -e ;\
unitN=$$(hostname | sed "s/^pioreactor\(.*\)$$/\1/") ;\
touch ~/.pioreactor/config$$unitN.ini ;\
touch ~/.pioreactor/config_$$userEnteredPioName.ini ;\
cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys ;\
}
sudo reboot
8 changes: 1 addition & 7 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pioreactor1=192.168.0.1
# a 1 means available, and a 0 means not available.
# See docs: https://github.com/Pioreactor/pioreactor/wiki/Leaders,-workers-and-inventory
pioreactor1=1
pioreactor2=0
pioreactor3=1
pioreactor4=0
pioreactor5=0


[ui.overview.settings]
# changing these may require a power cycle of the leader unit.
Expand Down Expand Up @@ -89,6 +86,3 @@ Kd=0
Kp=3
Ki=0.1
Kd=0.1

[watchdog]
email_alerts_to[email protected]
1 change: 1 addition & 0 deletions pioreactor/background_jobs/growth_rate_calculating.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def set_od_normalization_factors(self):
if message and not self.ignore_cache:
return self.json_to_sorted_dict(message.payload)
else:
# TODO: assert that od_reading is running
od_normalization(unit=self.unit, experiment=self.experiment)
return self.set_od_normalization_factors()

Expand Down
8 changes: 3 additions & 5 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, unit, experiment):
GPIO.add_event_detect(BUTTON_PIN, GPIO.RISING, callback=self.button_down_and_up)

self.start_passive_listeners()
self.flicker_led()

def turn_on_led(self):
GPIO.output(LED_PIN, GPIO.HIGH)
Expand All @@ -51,10 +52,7 @@ def button_down_and_up(self, *args):

self.turn_on_led()

publish(
f"pioreactor/{self.unit}/{self.experiment}/{self.job_name}/log",
"Pushed tactile button",
)
publish(f"pioreactor/{self.unit}/{self.experiment}/log", "Pushed tactile button")

while GPIO.input(BUTTON_PIN) == GPIO.HIGH:

Expand Down Expand Up @@ -85,7 +83,7 @@ def publish_disk_space(self):
disk_usage_percent,
)

def flicker_led(self, _):
def flicker_led(self, *args):
# TODO: what happens when I hear multiple msgs in quick succession?
self.turn_on_led()
time.sleep(0.2)
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def on_disconnect(self):

def start_stirring(self):
self.pwm.start(100) # get momentum to start
time.sleep(0.25)
time.sleep(0.4)
self.pwm.ChangeDutyCycle(self.duty_cycle)

def stop_stirring(self):
Expand Down
4 changes: 4 additions & 0 deletions pioreactor/pio_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def mqtt():

os.system("mosquitto_sub -v -t 'pioreactor/#'")

if not am_I_leader() and not am_I_active_worker():
print(
"Running `pio` on a non-active Pioreactor. Do you need to add this Pioreactor to `inventory` in `config.ini`?"
)

except Exception as e:
logger.debug(e, exc_info=True)
Expand Down
3 changes: 2 additions & 1 deletion pioreactor/whoami.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import os
import socket

UNIVERSAL_IDENTIFIER = "$broadcast"
UNIVERSAL_EXPERIMENT = "$experiment"
Expand All @@ -21,6 +20,8 @@ def get_latest_experiment_name():


def get_hostname():
import socket

if "pytest" in sys.modules:
return "localhost"
elif os.environ.get("HOSTNAME"):
Expand Down

0 comments on commit ce6309c

Please sign in to comment.