Skip to content

Commit

Permalink
Merge pull request #13 from UniversityOfIdahoCDACS/webapp
Browse files Browse the repository at this point in the history
Webapp 1
  • Loading branch information
Cyberzoid1 authored Apr 21, 2022
2 parents 5a2ce3d + f131600 commit e24f2f4
Show file tree
Hide file tree
Showing 59 changed files with 52,895 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pyController.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ After=multi-user.target

[Service]
# Command to execute when the service is started. Added in override file
WorkingDirectory=/home/factory/Mini-Factory-Python-Controller
ExecStartPre=/usr/bin/git pull
ExecStart=/usr/bin/python3 /home/factory/Mini-Factory-Python-Controller/pyController/pyController.py

# Disable Python's buffering of STDOUT and STDERR, so that output from the
Expand Down
15 changes: 12 additions & 3 deletions pyController/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, URL=None, PORT=None, CLIENT_ID="Unknown Client", TOPIC_SUB=No
self.add_job_callback = None
self.cancel_job_callback = None
self.cancel_order_callback = None
self.factory_command_callback = None


def connect(self):
Expand Down Expand Up @@ -140,33 +141,41 @@ def on_message(self, client, userdata, message):
else: # No error
self.add_job_callback(job_data)


elif mypayload['msg_type'] == 'cancel_job_id':
self.cancel_job_callback(mypayload['job_id'])

elif mypayload['msg_type'] == 'cancel_order_id':
self.cancel_job_callback(mypayload['order_id'])

elif mypayload['msg_type'] == 'reset_inventory':
# reset_inventory is a universal command function for factory related commands
self.factory_command_callback(command='reset_inventory')

else:
self.publish("Factory/Job_notice", f"Invalid message type {mypayload['msg_type']}")
self.logger.error("Message received with invalid message type %s", mypayload['msg_type'])


def set_add_job_callback(self, func):
""" Sets pyController.add_job_callback() function callback"""
self.add_job_callback = func

def set_cancel_job_callback(self, func):
""" Sets pyController.cancel_job_callback() function callback"""
self.cancel_job_callback = func

def set_cancel_order_callback(self, func):
""" Sets pyController.cancel_order_callback() function callback"""
self.cancel_order_callback = func


def set_factory_command_callback(self, func):
""" Sets factory.command() functiion callback"""
self.factory_command_callback = func

def on_disconnect(self):
pass



if __name__ == '__main__':
# Create logger
logger = logging.getLogger("factoryMQTT_test")
Expand Down
13 changes: 13 additions & 0 deletions pyController/pyController.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import webcam
from factory.factory import FACTORY # Real factory
from factory.factory_sim2 import FactorySim2 # Simulated factory
from webapp import webadmin


#*********************************************
Expand Down Expand Up @@ -138,6 +139,12 @@ def cancel_job_order_callback(self, order_id):
self.send_job_notice(notice_msg)


def factory_command_callback(self, command, **args):
""" Calls factory.command with supplied args """
logging.debug("Factory command: %s, args: %r", command, args)
if command == 'reset_inventory':
self.inventory.preset_inventory()

def send_inventory(self):
# Get inventory
if self.mqtt is not None:
Expand Down Expand Up @@ -275,10 +282,16 @@ def main():
# Setup orchastrator object
orchastrator = Orchastrator(mqtt=mqtt, queue=job_queue, inventory=inventory, factory=factory)

# Setup webadmin object
#webadmin.start_webapp()
#webadmin.callbacks.add_order_cb(orchastrator.add_job_callback)
#webadmin.callbacks.set_orchastrator(orchastrator)

# set mqtt orchastrator callbacks
mqtt.set_add_job_callback(orchastrator.add_job_callback)
mqtt.set_cancel_job_callback(orchastrator.cancel_job_id_callback)
mqtt.set_cancel_order_callback(orchastrator.cancel_job_order_callback)
mqtt.set_factory_command_callback(orchastrator.factory_command_callback)

#add_job = JobData(job_id=123, order_id=100, color='white', cook_time=12, sliced=True)
#orchastrator.add_job_callback(add_job)
Expand Down
6 changes: 6 additions & 0 deletions pyController/test_pyController.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from inventory import Inventory
from factory.factory_sim2 import FactorySim2 # Simulated factory
from pyController import Orchastrator
from pyController.webapp import webadmin

logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG) # sets default logging level for this module
Expand All @@ -28,6 +29,11 @@ def main():
# Setup orchastrator object
orchastrator = Orchastrator(mqtt=None, queue=job_queue, inventory=inventory, factory=factory)

# Setup webadmin object
#webadmin.start_webapp()
#webadmin.callbacks.add_order_cb(orchastrator.add_job_callback)


if True:
logger.info("Running Tests")
add_job = JobData(job_id=123, order_id=100, color='red', cook_time=12, sliced=True)
Expand Down
6 changes: 6 additions & 0 deletions pyController/test_webapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

from webapp.webadmin import start_webapp

print("Starting Webapp")
start_webapp()
print("Webapp closed")
Binary file added pyController/webapp/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyController/webapp/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyController/webapp/favicon.ico
Binary file not shown.
Binary file added pyController/webapp/static/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyController/webapp/static/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyController/webapp/static/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e24f2f4

Please sign in to comment.