~n0mn0m/bot_commander

33b06b44dc318e87a6c39718f4eeb9b7589a638d — n0mn0m 4 months ago 6bf034b master
Refactor dir and add services.

Move code into directory specific spaces for clarity and add systemd services.
15 files changed, 100 insertions(+), 42 deletions(-)

M Makefile
M README.md
D crontab.bak
R button_listener.py => pi/button_listener.py
A pi/button_listener.service
R font5x8.bin => pi/font5x8.bin
A pi/ngrok.service
A pi/requirements.txt
R sms_listener.py => pi/sms_listener.py
A pi/sms_listener.service
R code.py => roomba/code.py
A roomba/lib/adafruit_bus_device/__init__.py
A roomba/lib/adafruit_bus_device/i2c_device.mpy
A roomba/lib/adafruit_bus_device/spi_device.mpy
A roomba/lib/adafruit_rfm9x.mpy
M Makefile => Makefile +24 -9
@@ 1,15 1,30 @@
USER := $(shell whoami)

all: transfer transferd

init:
	mdutil -i off /Volumes/CIRCUITPY
	cd /Volumes/CIRCUITPY
	rm -rf {fseventsd,Trashes}
	mkdir .fseventsd
	touch .fseventsd/no_log .metadata_never_index .Trashes
	cd -
init-feather:
	@mdutil -i off /Volumes/CIRCUITPY
	@pushd /Volumes/CIRCUITPY && \
	rm -rf {fseventsd,Trashes} && \
	mkdir .fseventsd && \
	touch .fseventsd/no_log .metadata_never_index .Trashes && \
	cd -;

scppi:
	@scp pi/sms_listener ${USER}@c3:/projects/roomba_supervisor/
	@scp pi/button_listener ${USER}@c3:/projects/roomba_supervisor/

scpdpi:
	@scp -r ${USER}@c3:/projects/roomba_supervisor/  /pi/

services:
	@scp pi/*.service ${USER}@c3:/etc/systemd/system

transfer:
	cp -X code.py /Volumes/CIRCUITPY
	@cp -X ./roomba/code.py /Volumes/CIRCUITPY

transferd:
	cp -rX lib /Volumes/CIRCUITPY
	@cp -rX lib ./roomba/Volumes/CIRCUITPY

user:
	@echo ${USER}

M README.md => README.md +10 -6
@@ 3,26 3,30 @@
This project contains `python` scripts and `cron` task for operating a Roomba
615 locally or remotely.

### `/pi`

- `sms_listener.py` runs a web server that monitors a [Twilio](https://www.twilio.com/docs/sms/quickstart/python#allow-twilio-to-talk-to-your-flask-application)
end point waiting for a message to send a start signal to a connected
device (in my scenario a Roomba 615).

- `button_listener.py` is meant for use with an Adafruit [RFM LoRa](https://www.adafruit.com/product/3179)
 shield.

- `code.py` is the application that runs on the Adafruit Feather listening for different signals to process
and send to the Roomba Open Interface.

- `crontab.bak` is a backup of my `crontab` setup that starts the services
on the RaspberryPi Zero W after reboot.
 
- `*.service` systemd unit files for managing ngrok and the Python application scripts.

- `requirements.txt` are the packages that the virtual environment requires
for the scripts above to run.

### `/roomba`

- `code.py` is the application that runs on the Adafruit Feather listening for different signals to process and send to the Roomba Open Interface.

### Notes

This is currently built and running with Python 3.7 and Raspbian.

Service files are provided in `/pi` for managing Python on the zero with systemd


### Hardware


D crontab.bak => crontab.bak +0 -27
@@ 1,27 0,0 @@
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

@reboot cd /home/pi/ && /home/pi/.virtualenvs/lora-pi/bin/python /home/pi/projects/roomba_supervisor/button_listener.py 2>&1 >> /home/pi/logs/button.log
@reboot cd /home/pi/ && /home/pi/.virtualenvs/lora-pi/bin/python /home/pi/projects/roomba_supervisor/sms_listener.py 2>&1 >> /home/pi/logs/sms.log
@reboot sleep 10 && cd /home/pi/ && /home/pi/ngrok http 5000 2>&1 >> /home/pi/logs/ngrok.log
@reboot sleep 20 && curl http://127.0.0.1:4040/api/tunnels 2>&1 > /home/pi/logs/ngrok_details.log

R button_listener.py => pi/button_listener.py +0 -0

A pi/button_listener.service => pi/button_listener.service +13 -0
@@ 0,0 1,13 @@
[Unit]
Description=shield button listener
After=ngrok.service

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/.virtualenvs/lora-pi/bin/python /home/pi/projects/roomba_supervisor/button_listener.py
Restart=on-failure

[Install]
WantedBy=multi-user.target/
\ No newline at end of file

R font5x8.bin => pi/font5x8.bin +0 -0

A pi/ngrok.service => pi/ngrok.service +13 -0
@@ 0,0 1,13 @@
[Unit]
Description=ngrok
After=network.service

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/ngrok start --all --config="/home/pi/.ngrok2/ngrok.yml"
Restart=on-failure

[Install]
WantedBy=multi-user.target
\ No newline at end of file

A pi/requirements.txt => pi/requirements.txt +27 -0
@@ 0,0 1,27 @@
Adafruit-Blinka==2.1.4
adafruit-circuitpython-busdevice==3.0.0
adafruit-circuitpython-framebuf==1.1.0
adafruit-circuitpython-rfm9x==1.1.6
adafruit-circuitpython-ssd1306==2.6.3
Adafruit-PlatformDetect==1.0.6
Adafruit-PureIO==0.2.3
certifi==2019.6.16
chardet==3.0.4
Click==7.0
Flask==1.1.1
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
PyJWT==1.7.1
PySocks==1.7.0
pytz==2019.1
requests==2.22.0
rpi-ws281x==4.1.0
RPi.GPIO==0.6.5
six==1.12.0
spidev==3.4
sysv-ipc==1.0.0
twilio==6.29.2
urllib3==1.25.3
Werkzeug==0.15.5

R sms_listener.py => pi/sms_listener.py +0 -0

A pi/sms_listener.service => pi/sms_listener.service +13 -0
@@ 0,0 1,13 @@
[Unit]
Description=sms listener
After=ngrok.service

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/.virtualenvs/lora-pi/bin/python /home/pi/projects/roomba_supervisor/sms_listener.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
\ No newline at end of file

R code.py => roomba/code.py +0 -0

A roomba/lib/adafruit_bus_device/__init__.py => roomba/lib/adafruit_bus_device/__init__.py +0 -0

A roomba/lib/adafruit_bus_device/i2c_device.mpy => roomba/lib/adafruit_bus_device/i2c_device.mpy +0 -0

A roomba/lib/adafruit_bus_device/spi_device.mpy => roomba/lib/adafruit_bus_device/spi_device.mpy +0 -0

A roomba/lib/adafruit_rfm9x.mpy => roomba/lib/adafruit_rfm9x.mpy +0 -0