/Lab-Manager

The new Lab management and access control system to implement pay-per-use concept for the Fab Lab Siegen

Primary LanguagePythonMIT LicenseMIT

Lab-Manager

The new Lab management software to implement pay-per-use concept for the Fab Lab Siegen

Disclaimer

This project is prototype and still in development. There is no setup script or so. The code is just a snapshot to show how the concept could work.

Project Status

Lab Manager

Key features

  • Monitor and Assign available printer to visiting customers in the lab
  • Access control via ESP8266 and RFID-reader by connecting/disconnecting OctoPrint to printer
  • Store and retrieve print usage details
  • Calculate, view and manage cost of each print
  • Manage Maintenance of each printer by tracking print hours

Project Links

Setup

ESP_RFID

Implementation for the ESP8266 that controls the RFID-Reader, interprets OctoPrint events and publishes MQTT commands to the broker

Path : ESP_RFID/ESP_RFID.ino

  • Open the file ESP_RFID.ino in Arduino IDE (or) any preferred IDE
  • Add required libraries (ArduinoJson, MFRC522, PubSubClient) to the IDE
  • Search for the string "# WARNING", then Add Wi-Fi credentials and MQTT connection details
  • Search for "# WARNING add RFID tag" and add RFID tag corresponding to the printer
  • Setup NodeMCU with RFID
  • Upload the code

Lab-Manager (Django rest framework + Postgres-DB)

Back-End of the application is a REST api built using Django rest framework with Postgres-DB.

Installation

  • If you wish to run your own build, first ensure you have python globally installed in your computer. If not, you can get python here.

  • After doing this, confirm that you have installed virtualenv globally as well. If not, run this:

        $ pip install virtualenv
  • Then, Git clone this repo to your PC

        $ git clone https://github.com/FabLabSiegen/Lab-Manager.git
  • Dependencies

    1. Cd into your the cloned repo as such:

          $ cd Lab-Manager
      
    2. Create and fire up your virtual environment:

          $ virtualenv  venv -p python3
          $ source venv/bin/activate
    3. Dependencies such as django-rest-framework a powerful and flexible toolkit for building Web APIs, psycopg2 (PostgreSQL database adapter for Python), django-cors-headers (for allowing resources to be accessed on other domains), simplejson as json encoder/decoder are used to build the API. Install the dependencies needed to run the app:

          $ pip install -r requirements.txt
    4. Setup local Postgres-DB

      • Add credentials and db name in settings.py
    5. paho-mqtt as MQTT client is used to connect to an MQTT broker to publish messages, and to subscribe to topics and receive published messages. In the file lab_manager\mqttservice.py, search for "WARNING add MQTT Host" and add MQTT host details

    6. Make those migrations work

          $ python manage.py makemigrations
          $ python manage.py migrate
  • Run It

    Fire up the server using this one simple command:

        $ python manage.py runserver 8080

    You can now access the api endpoints on your browser.

  • End points of REST API:

    • GET, POST printers detail available in Lab: api/printers
    • GET, PUT each printer detail available in Lab: api/printers/{string:id}
    • GET, POST user detail available in Lab: api/user
    • GET, PUT each user detail available in Lab: api/user/{string:user}
    • GET, POST, DELETE usage detail available in Lab: api/usage
    • GET, PUT, DELETE each usage detail available in Lab: api/usage/{string:id}
    • GET filament detail available in Lab: api/filament
    • GET, PUT each filament detail available in Lab: api/filament/{string:filamentname}
    • GET, PUT default material usage details: /api/material/{string:id}
    • GET, PUT default printer usage details: /api/printer/{string:id}
    • GET, PUT default operating usage details: /api/operating/{string:id}

Front-End (React App)

Application view

Path : Lab-manager/Front-End

To get the Front-End application running locally:

  • Install Node JS. Refer to https://nodejs.org/en/ to install nodejs.

  • Install create-react-app npm package globally. This will help to easily run the project and also build the source files easily. Use the following command to install create-react-app

         $ npm install -g create-react-app
  • Navigate to folder Lab-Manager/Front-End from command line
         $ cd Lab-Manager/Front-End
  • Install all required dependencies. The Front-end is built using packages Bootstrap as css framework, React-Hooks for state management, Axios as HTTP client,
         $ npm install
         $ npm start

Local web server will use port 8081 instead of standard React's port 3000 to prevent conflicts with some backends like Node. Port can be onfigured in scripts section of package.json. Once the Django API is running, Front-end starts interacting with the API.

OctoPrint Setup for testing

OctoPrint is used to control and monitor every aspect of your 3D printer and your printing jobs right from within your browser.