client.py | processor.py | storage.py | MongoDB.py | LED.py | lib.py |
---|---|---|---|---|---|
sys | sys | sys | sys | Rpi.GPIO | datetime |
argparse | argparse | argparse | pymongo | time | |
json | json | json | gpiozero | ||
pika | pika | bluetooth | |||
uuid | bluetooth | subprocess | |||
struct | threading | ||||
struct |
Vineeth Kirandumkara
This file runs on the client RPi to read in the users desired command, and sends a dictionary of values to the processor. It will also print the results of the request to the screen.
- rpcClient class
- Handles all RabbitMQ requests and response.
- argParse Function
- Establishes all the possible user inputs.
- Main Function
- Creates the appropriate dictionary, and sends the object to the RabbitMQ server. It will then print the response to the screen once a response is recieved.
Mohammad Aarij
This file runs on the processor RPi to connect communications between the client RPi and the server RPi
This program contains two classes:
- BTConnect
- Handles the Bluetooth communication between the processer and the server
- RPCServer
- Acts as the RabbitMQ server to communicate with the client
The BTConnect instance is created within the RPCServer. It communicates with the server in the on_request
function within the RPCServer class.
Sajan Ronvelwala
This file is the highest-level application that runs on the server RPi to respond to queries.
This program consists of two threads:
- Controls the GPIO pins to continuously show the book inventory count on an LED using the API defined in LED.py. The book inventory count is retrieved by using the API defined in MongoDB.py.
- Continuously retrieves queries/commands from the processor over a Bluetooth connection, parses them, uses the API defined in MongoDB.py to modify the book inventory according to the command/query, creates a response payload according to the command/query, and sends the response payload back to the processor over the Bluetooth connection.
Note: Since both threads access the book inventory, it is a shared resource and thus a mutex is used to make it thread-safe.
For more information about this program, open a Python3 interpreter prompt and
type import storage
, followed by help(storage)
.
Mohammad Aarij
This file contains the DataBase() class that storage.py uses to interface with MongoDB.
The hostname and port number are taken in as arguments, but are set for local hosting by default. An example of creating a local MongoDB connection using this class:
example_db = DataBase()
The book
argument is taken in as a dictionary.
- count_book(book)
- Counts stock number of a specified book.
- add_book(book)
- Adds a database entry for the given book.
- Returns an error if there is already an entry for the book.
- buy_book(book, amt)
- Increases stock for specified book by given amount,
amt
. - Returns an error if there is no database entry for the given book.
- Increases stock for specified book by given amount,
- sell_book(book, amt)
- Used after sales are made. Decreases stock for specified book by given amount,
amt
. - Returns an error if there is no database entry for the given book or if there is not enough stock for the sale.
- Used after sales are made. Decreases stock for specified book by given amount,
- del_book(book)
- Deletes the specified book.
- Returns an error if the book does not exist in the database.
- list_books()
- Returns a list of all books in the collection.
Vineeth Kirandumkara
This file takes care of all LED functionality. The storage.py file can access the displayStatus function by sending the number of books as an argument, and the LED will blink the appropriate number of times.
- ConcatenateList(self, list)
- Used for when the number of books is greater than 3 digits. Concatenate the bits greater than the 100s place to find the total number of blinks the Red LED would have to make.
- redBlink(self)
- Used to make the Red LED blink.
- greenBlink(self)
- Used to make the Green LED blink.
- blueBlink(self)
- Used to make the Blue LED blink.
- displayStatus(self, bookAmt)
- Function that the Storage.py utilizes. Send in the
bookAmt
and the LED will blink as required.
- Function that the Storage.py utilizes. Send in the
- Plug the ribbon cable to the Assembled Pi Cobbler
- Notch on ribbon cable go with the notch on the Pi Cobbler
- Plug the other end into the Raspberry Pi GPIO
- Make sure the white wire on the ribbon cable is at the top of the GPIO ports (Opposite of the USB ports).
- Plug Pi Cobbler into a breadboard.
- Plug in wires to the Pi Cobbler ports: 21, 16, and 12
- Run each wire to an individual resistor.
- Run resistors into appropriate LED inputs.
- Check the project requirements slides to find the LED picture
- GPIO 21 : Red
- GPIO 16 : Green
- GPIO 12 : Blue
https://www.adafruit.com/product/2029
This file serves as a central library with classes and functions that can be
used by any of the RPi programs: client.py, processor.py, or storage.py.
Currently the file contains one function print_checkpoint(*msgs)
which
prints the given messages with the current timestamp appended before it. This
function essentially works the same as the built-in print
function except
that it appends the current timestamp at the beginning. This function makes it
very easy to print checkpoints in a format that is consistent with the project
specification and across all three RPi programs.
Sajan Ronvelwala