Skip to content

Real-time scale and weight analytics. Whole architecture with REST-server, MQTT-server, web platform, hardware signal processing.

Notifications You must be signed in to change notification settings

Altishofer/piggyScale-Client

Repository files navigation

paho-mqtt Mosquitto Angular TypeScript

Piggy Scale Client:

🎉 Real-Time Scale and Weight Analytics 🎉

This repository contains all three components of the Piggy Scale system. The Scale component reads data from the load cells and publishes the measurements to the MQTT server. The MQTT server stores these real-time measurements and makes them available to all subscribed web clients. The web client subscribes to these real-time signals and loads previous weights from the database, allowing users to view, visualize, and analyze both current and historical measurements. The server handles requests from the client to read, write, and manipulate stored records.

Table of Contents

Features

  • Real-time visualization of scale data
  • Automatic weight estimation using real-time measurements
  • Manual storage, retrieval, and manipulation of weight data
  • View and analyze the history and trends of different pig batches
  • Export measurement data to Excel

Built With

  • Mosquitto: An open-source message broker that implements the MQTT protocol.
  • Paho: A python library for interacting with the mosquitto MQTT broker.
  • Angular: A platform for building web applications using TypeScript.
  • TypeScript: The Client is written in TypeScript, a more statically typed version of JavaScrippt.

Main Components

  • Scale: Captures data from the hardware and publishes real-time measurements to the MQTT server.
  • Client: An Angular-based web platform that subscribes to real-time updates from the scale and retrieves data from the server's database.
  • MQTT Server: Buffers real-time measurements from the Scale and forwards them to subscribed clients.

Hardware

Prerequisites

Instructions

  • Solder each weight cell to a HX711
  • Connect each HX711 to an individual GPIO

Deployment

Deployment - Client

Software Prerequisites

Setup

  1. Clone this repository to your local machine:
git clone https://github.com/Altishofer/piggyScale-Client.git
  1. Enter newly cloned directory
cd piggyScale-Client 
  1. Install dependencies
yarn install
  1. Deploy Client
ng serve
  1. Open UI in your favorite browser

    http://localhost:4200/login

Deployment - Scale Simulator

Software Prerequisites

Setup

  1. Clone this repository to your local machine:
git clone https://github.com/Altishofer/piggyScale-Client.git
  1. Enter newly cloned directory
cd piggyScale-Client 
  1. Create Virtual Environment
python3.11 -m venv .venv
  1. Activate venv (Linux)
source .venv/bin/activate
  1. Install dependencies
pip install -r requirements
  1. Deploy REST-Server
python ./scale/measure.py

MQTT - Server Setup (Linux)

  1. Update and ugrade all packages:
sudo apt update && sudo apt upgrade
  1. Install mosquitto broker:
sudo apt install -y mosquitto mosquitto-clients
  1. Open mosquitto configuration:
sudo nano /etc/mosquitto/mosquitto.conf
  1. Replace mosquitto configuration:
# replace, save and close file
pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d

listener 1883 0.0.0.0
allow_anonymous true
protocol mqtt

listener 9001 0.0.0.0
allow_anonymous true
protocol websockets

connection_messages true
log_timestamp true
  1. Run MQTT-Broker in the background:
mosquitto -v -d
  1. Open NEW shell and test subscription:
mosquitto _sub -h localhost -t /test/topic
  1. Open NEW shell and test publishing:
# Switch to subscription shell and check if output is visible
mosquitto _pub -h localhost -t /test/topic -m "Hello World!"

Autostart for Raspbberry Pi

Add all script to autostart (optional)

  1. Open Crontab with root rights:
sudo crontab -e
  1. Add automatic reset on reboot
@reboot sleep 60 && bash /home/pi/Desktop/startAll.sh
  1. Create new bash script on Desktop
cd /home/pi/Desktop && nano startAll.sh
  1. Insert Deployment code into bash file
#!/bin/bash

# Activate logger
#exec > /home/pi/Desktop/startAll.log 2>&1

source /home/pi/.nvm/nvm.sh

# Start Angular project
cd /home/pi/Desktop/piggyScale-Client
/usr/bin/git pull
/usr/local/bin/ng serve --configuration production &

# Start .NET project
cd /home/pi/Desktop/piggyScale-Client-Server/Project
/usr/bin/git pull
/home/pi/.dotnet/dotnet run --launch-profile Production &

# Start Python script
/home/pi/Desktop/piggyScale-Client/.venv/bin/python /home/pi/Desktop/piggyScale-Client/scale/measure.py &
  1. Make file executable
sudo chmod +x startAll.sh
  1. Reboot
sudo reboot
  1. If automatic deployment fails, uncomment logger in bash script and open log file after reboot.

About

Real-time scale and weight analytics. Whole architecture with REST-server, MQTT-server, web platform, hardware signal processing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published