~n0mn0m/bot_commander

970ba2b5624b9f960bdfac8b3ca2af334c26e5a0 — Alexander Hagerman 10 months ago 40971f9
Lint and auto format updates.

Remove unused packages. Run auto formatter.
3 files changed, 37 insertions(+), 24 deletions(-)

M button_listener.py
M code.py
M sms_listener.py
M button_listener.py => button_listener.py +12 -7
@@ 6,12 6,17 @@ import board
import adafruit_ssd1306
import adafruit_rfm9x

LOG_FORMAT = '%(asctime)s:%(levelname)s:%(message)s'
logging.basicConfig(filename="/home/pi/logs/button.log", level=logging.INFO, format=LOG_FORMAT, datefmt='%m/%d/%Y %I:%M:%S %p')
LOG_FORMAT = "%(asctime)s:%(levelname)s:%(message)s"
logging.basicConfig(
    filename="/home/pi/logs/button.log",
    level=logging.INFO,
    format=LOG_FORMAT,
    datefmt="%m/%d/%Y %I:%M:%S %p",
)
logger = logging.getLogger(__name__)

i2c = busio.I2C(board.SCL, board.SDA)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3C)

# Configure LoRa Radio
CS = DigitalInOut(board.CE1)


@@ 35,7 40,7 @@ dock_button.pull = Pull.UP
logger.info("Starting application")

display.fill(0)
display.text('RasPi LoRa', 35, 0, 1)
display.text("RasPi LoRa", 35, 0, 1)
display.show()

while True:


@@ 43,19 48,19 @@ while True:
        if not start_button.value:
            msg = "Starting Roomba."
            logger.info(msg)
            rfm9x.send(bytes("1","ascii"))
            rfm9x.send(bytes("1", "ascii"))
            display.fill(0)
            display.text(msg, 25, 15, 1)
        elif not stop_button.value:
            msg = "Stopping Roomba."
            logger.info(msg)
            rfm9x.send(bytes("0","ascii"))
            rfm9x.send(bytes("0", "ascii"))
            display.fill(0)
            display.text(msg, 25, 15, 1)
        elif not dock_button.value:
            msg = "Docking Roomba."
            logger.info(msg)
            rfm9x.send(bytes("2","ascii"))
            rfm9x.send(bytes("2", "ascii"))
            display.fill(0)
            display.text(msg, 25, 15, 1)


M code.py => code.py +6 -5
@@ 4,6 4,7 @@ import digitalio
import adafruit_rfm9x
import time


class OpenInterface:
    def __init__(self, tx_pin, rx_pin, brc_pin, baud_rate=115200):
        self._board = busio.UART(tx_pin, rx_pin, baudrate=baud_rate)


@@ 13,16 14,16 @@ class OpenInterface:
        self._brc_pin.direction = digitalio.Direction.OUTPUT
        self._baud_rate = baud_rate
        self._stopped = True
    

    def start(self):
        if self._stopped:
            self.wake_up()

        for command in (b'\x80', b'\x83', b'\x87'):
        for command in (b"\x80", b"\x83", b"\x87"):
            self._board.write(command)

    def stop(self):
        for command in (b'\x85', b'\xAD'):
        for command in (b"\x85", b"\xAD"):
            self._board.write(command)
        self._stopped = True



@@ 55,10 56,10 @@ bot.wake_up()

while True:
    # Wait for a packet to be received (up to 0.5 seconds)
    packet = rfm9x.receive(.5)
    packet = rfm9x.receive(0.5)

    if packet is not None:
        packet_txt = str(packet, 'ascii')
        packet_txt = str(packet, "ascii")

        if packet_txt == "0":
            bot.stop()

M sms_listener.py => sms_listener.py +19 -12
@@ 1,26 1,32 @@
import os
import time
import logging

# Import Blinka Libraries
import busio
from digitalio import DigitalInOut, Direction, Pull
from digitalio import DigitalInOut
import board

# Import the SSD1306 module.
import adafruit_ssd1306

# Import RFM9x
import adafruit_rfm9x

# App dependencies
from flask import Flask, request
from twilio.rest import Client
from twilio.twiml.messaging_response import MessagingResponse

LOG_FORMAT = '%(asctime)s:%(levelname)s:%(message)s'
logging.basicConfig(filename="/home/pi/logs/sms.log", level=logging.INFO, format=LOG_FORMAT, datefmt='%m/%d/%Y %I:%M:%S %p')
LOG_FORMAT = "%(asctime)s:%(levelname)s:%(message)s"
logging.basicConfig(
    filename="/home/pi/logs/sms.log",
    level=logging.INFO,
    format=LOG_FORMAT,
    datefmt="%m/%d/%Y %I:%M:%S %p",
)
logger = logging.getLogger(__name__)

# Initialize and setup
i2c = busio.I2C(board.SCL, board.SDA)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3C)
display.fill(0)
display.show()



@@ 33,7 39,8 @@ rfm9x.tx_power = 23

app = Flask(__name__)

@app.route("/sms", methods=['GET', 'POST'])

@app.route("/sms", methods=["GET", "POST"])
def sms_start_roomba():
    """
    When a message is received determine which


@@ 46,13 53,13 @@ def sms_start_roomba():

    if txt == "start":
        msg = "Starting the Roomba."
        cmd = bytes("1","ascii")
        cmd = bytes("1", "ascii")
    elif txt == "halt":
        msg = "Stopping the Roomba."
        cmd = bytes("0","ascii")
        cmd = bytes("0", "ascii")
    elif txt == "dock":
        msg = "Roomba beginning to dock."
        cmd = bytes("2","ascii")
        cmd = bytes("2", "ascii")
    else:
        msg = "Unknown command. Continuing."
        cmd = None


@@ 72,6 79,7 @@ def sms_start_roomba():

    return str(resp)


if __name__ == "__main__":
    while True:
        try:


@@ 85,4 93,3 @@ if __name__ == "__main__":
        except BaseException as e:
            logger.exception(e)
            pass