📄 Weight Scale - local network (Without IoT)

Weight Scale - local network (Without IoT)


Step 1: Install PyInstaller [In Windows]

pip install pyinstaller

If you have multiple Python versions, use:

py -m pip install pyinstaller


Step 2: Run PyInstaller using Python (correct way)

python -m PyInstaller --onefile weight_new.py

🔧 Step 3: After build completes

dist/weight_new.exe

METHOD 1 — Run EXE from CMD (shows the error)

This is the easiest way.

  1. Open Command Prompt

  2. Go to the folder where your EXE is located:

  3. cd C:\Users\setue\Downloads\pelican\dist
    Run exe: .\weight_new.exe

If get ModuleNotFoundError: No module named 'serial'


STEP 1 — Verify pyserial is installed

pip install pyserial
or
py -m pip install pyserial

STEP 2 — Rebuild EXE with hidden imports

if it is PowerShell

python -m PyInstaller --onefile --hidden-import=serial --hidden-import=serial.tools.list_ports weight_new.py

📌 If you also use Flask-CORS

python -m PyInstaller --onefile --hidden-import=serial --hidden-import=serial.tools.list_ports --hidden-import=flask_cors weight_new.py

🎉 After build finishes

cd dist
.\weight_new.exe




How to test your API correctly

http://127.0.0.1:8000/connection

Result:
Connection Successful
Please press W to weight a product.

✔ Weight test

http://127.0.0.1:8000/weight



Convert the script into a Windows Service (auto-start on boot)?


Remove any input type from weight.py file

Step 1: Download NSSM

Download NSSM (64-bit version): https://nssm.cc/download

C:\nssm\win64\nssm.exe

Step 2: Install Your Weighing EXE as a Windows Service

Run PowerShell as Administrator and execute:

C:\nssm\win64\nssm.exe install WeightService

or

go to: cd C:\Users\setue\Downloads\nssm-2.24\nssm-2.24\win64 then RUN .\nssm.exe install WeightService

A window will pop up:

You must fill:

Application → Path:

C:\Users\setue\Downloads\pelican\dist\weight_new.exe

Application → Startup directory:

C:\Users\setue\Downloads\pelican\dist

Arguments: (leave empty)


VERY IMPORTANT

NSSM needs the service to run in the background without any user prompts.


Step 4: Configure Service Settings in NSSM

In the NSSM GUI:

✓ Set "Startup type" to Automatic

(Service → Startup: Automatic)

✓ Set "Shutdown method" to Process tree kill

(to avoid zombie processes)

✓ Set "AppStdout" and "AppStderr" logs

(example):

C:\weight_logs\stdout.log
C:\weight_logs\stderr.log

NSSM will create them automatically. If not found create manually

This helps you debug the service if something fails.

Step 5: Install and Start the Service

Click Install service in the NSSM GUI.

sc start WeightService
or
C:\nssm\win64\nssm.exe start WeightService ​

🚀 Your Flask/Serial EXE is now running as a Windows service!

Your API is accessible at:

http://127.0.0.1:8000/connection
http://127.0.0.1:8000/weight

Reboot system

🔍 Step 6: Verify the service is running

services.msc

Status should be → Running
Startup Type → Automatic

🚀 Start the service

After installation: Run shell as Administrator

.\nssm.exe start WeightService

or

cd C:\Users\setue\Downloads\nssm-2.24\nssm-2.24\win64
.\nssm.exe start WeightService

Restart service

.\nssm.exe restart WeightService