IoT · HardwareMOGI ALTIGAH

Smart Lockers

A Python-based IoT agent running on Raspberry Pi that controls Kerong electromagnetic locker locks via RS485 serial communication. Connected to the cloud via MQTT for remote lock/unlock commands.

raspberry-pi ~ agent.py
mqtt.on_message("locker/unlock")
  └─ rs485.send(board_addr, lock_id, UNLOCK)
       └─ KR-CU24 → LockOPEN
       └─ feedback → status: unlocked
PythonRaspberry PiRS485Kerong KR-CU24MQTTSerial CommunicationIoTREST APIs
01

System Architecture

End-to-end signal flow from cloud to physical lock

┌─────────────────┐      ┌─────────────────────┐      ┌──────────────────────┐
│   CLOUD/APP     │      │   RASPBERRY PI       │      │   KERONG HARDWARE    │
│                 │      │                      │      │                      │
│  Mobile App     │ MQTT │  ┌────────────────┐  │ USB  │  ┌────────────────┐  │
│  Backend API ───┼──────┼─>│  Python Agent  │  │──────┼─>│  KR-CU24       │  │
│  Dashboard      │      │  │                │  │      │  │  Control Board │  │
│                 │ pub/ │  │  • MQTT Client │  │ RS485│  │                │  │
│  Commands:      │ sub  │  │  • Serial I/O  │  │ bus  │  │  24 Channels   │  │
│  • unlock(id)   │      │  │  • Lock State  │  │      │  │  Addr: 0x01    │  │
│  • status(id)   │<─────┼──│  • Health Mon  │  │<─────┼──│  Feedback      │  │
│  • lock_all()   │      │  └────────────────┘  │      │  └───────┬────────┘  │
│                 │      │                      │      │          │ 12V       │
└─────────────────┘      └──────────────────────┘      │  ┌───────┴────────┐  │
                                                       │  │ Electromagnetic│  │
                                                       │  │ Locks × 24     │  │
                                                       │  │ (per board)    │  │
                                                       │  │                │  │
                                                       │  │ • KR-S80 lock  │  │
                                                       │  │ • Solenoid 12V │  │
                                                       │  │ • IR Sensor    │  │
                                                       │  │ • LED Status   │  │
                                                       │  └────────────────┘  │
                                                       └──────────────────────┘
02

Signal Flow — From App Tap to Lock Click

What happens in the 200ms between a user tapping "Unlock" and the locker door opening

STEP 1

App / API

User taps "Open Locker" or backend triggers unlock command

STEP 2

MQTT Broker

Command published to topic locker/{machine_id}/unlock with lock_id payload

STEP 3

Python Agent

Raspberry Pi subscribes, receives message, translates to RS485 serial frame

STEP 4

KR-CU24

Board receives RS485 command, validates address, triggers 12V pulse to lock solenoid

STEP 5

Lock Opens

Electromagnetic latch retracts, IR sensor confirms door opened, LED turns green

03

Hardware Stack

Every physical component in the locker system

Raspberry Pi 4

ARM Cortex-A72 · 4GB RAM · Linux

The brain of the system. Runs the Python agent service that bridges MQTT cloud commands to RS485 serial hardware. Headless, auto-starts on boot, with watchdog monitoring.

Kerong KR-CU24 Control Board

DC 12V~24V · RS485 · 24 channels

Centralized lock controller. Receives RS485 commands via USB adapter, controls up to 24 electromagnetic locks per board. FTDI RS485 chip with zero data packet loss. Up to 16 boards can be cascaded for 384 locks.

USB to RS485 Adapter

FTDI chip · /dev/ttyUSB0 · 9600 baud

Converts USB serial from the Raspberry Pi to RS485 differential signaling. Industrial-grade shielded cable prevents EMI interference in electrically noisy environments.

Electromagnetic Solenoid Locks

12V DC · KR-S series · 500K cycles

Kerong KR-S80 electromagnetic latches. When energized, the solenoid retracts the latch bolt, releasing the door. Spring-return auto-locks when power is removed. Rated for 500,000 open/close cycles.

IR Occupancy Sensors

Per-locker · connected to CU board

Infrared sensors mounted inside each locker compartment. Detect whether the locker contains items (occupied) or is empty. Status reported back through the CU board.

LED Status Indicators

Bi-color · Green/Red per locker

Visual feedback on each locker door. Green = available/empty, Red = occupied/locked. Controlled directly by the CU board based on lock state and IR sensor readings.

04

RS485 Serial Protocol

How the Python agent talks to the KR-CU24 board

UNLOCK COMMAND FRAME
0x02
STX
0x01
Board Addr
0x4F
CMD: Open
0x05
Lock #5
0xXX
Checksum
0x03
ETX

Each command frame is sent via pyserial at 9600 baud, 8N1. The board responds with a feedback frame confirming lock state change. Board address is set via rotary switch on the CU board (0x01–0x10 for 16 cascaded boards).

FEEDBACK RESPONSE
0x02
STX
0x01
Board Addr
0x52
Response
0x05
Lock #5
0x01
UNLOCKED
0xXX
Checksum
0x03
ETX

The CU board sends back a status byte: 0x01 = unlocked, 0x00 = locked. The Python agent publishes this to MQTT topic locker/status for the backend to consume.

05

Python Agent — The Brain

Systemd service running 24/7 on Raspberry Pi

MQTT Subscriber

Connects to the cloud MQTT broker (TLS encrypted). Listens on locker/{machine_id}/# topics. Parses JSON payloads with lock_id and action (unlock, lock, status, lock_all).

Serial Controller

Opens /dev/ttyUSB0 via pyserial at 9600 baud. Constructs RS485 command frames. Sends to KR-CU24 board. Reads feedback responses. Handles timeout and retry logic.

State Manager

Maintains an in-memory state map of all 24 locks (locked/unlocked/error). Publishes state changes back to MQTT. Persists last-known state to local SQLite for crash recovery.

Health Monitor

Sends heartbeat every 30s to the backend. Reports CPU temp, memory usage, uptime, connectivity status, and lock board health. Auto-restarts via systemd watchdog on failure.

06

Scalable Architecture

From 24 to 384 locks with cascaded RS485 boards

Raspberry Pi ──USB──> RS485 Bus
                         │
            ┌─────────────┼─────────────┐
            │             │             │
     ┌──────┴──────┐ ┌───┴──────┐ ┌───┴──────┐
     │  KR-CU24    │ │ KR-CU24  │ │ KR-CU24  │
     │  Addr: 0x01 │ │ Addr:0x02│ │ Addr:0x03│
     │  24 Locks   │ │ 24 Locks │ │ 24 Locks │  ... up to 16
     └─────────────┘ └──────────┘ └──────────┘
       Locks 1-24     Locks 25-48  Locks 49-72
24
Locks per board
16
Max cascaded boards
384
Max locks per Pi
<200
ms response time
07

Deployed Use Cases

Where this system is actively running

🥗

Khozama Meals

Smart locker boxes at corporate offices. Meals delivered by catering, employees open locker from the Khozama app via MQTT → Python Agent → RS485 → Lock opens.

📦

Parcel Lockers

Self-service parcel collection points. Delivery driver locks parcel, recipient gets SMS with code, code triggers unlock via backend → MQTT → Agent.

🏥

Wasfty Pharmacy

Medication storage lockers in healthcare facilities. Pharmacist loads prescriptions, patient scans QR, system unlocks the correct compartment.

08

Locker System Solutions

KERONG PCB & intelligent control boards powering our locker infrastructure

KERONG Smart Locker System Solution

Complete Locker Control Ecosystem

Our smart locker infrastructure is built on KERONG's industrial-grade control boards. The system architecture flows from cloud software through a network bridge (BU/SBU) down to individual lock controllers (CU/SCU/NCU), enabling remote management of hundreds of locks from a single Raspberry Pi gateway.

CE CertifiedFCC CertifiedRoHSISO9001500K Cycle Life
KR-BU|KERONG

RS485 Communicator — Network Bridge Unit

RS485 + TCP/IP
KR-BU — PCB Control System Electronic Locker Controller

PCB Control System Electronic Locker Controller

The KR-BU serves as the network bridge between your PC/server software and the downstream CU lock controllers. It converts TCP/IP commands from your application into RS485 serial frames that the lock control boards understand. This is the central communication hub in our locker architecture — every unlock command from the cloud passes through this board.

Key Features

  • Converts TCP/IP commands to RS485 format for CU boards
  • Co-works with PC, tablet, Raspberry Pi (iOS, Windows, Linux)
  • Open development platform — design your own control software
  • Anti-dust protective ABS enclosure for industrial environments
  • Optional Bluetooth mobile app unlock support
  • STM8S103K3T6 microprocessor for reliable operation

Role in Our System

In our system, the KR-BU sits between the Raspberry Pi and the KR-CU24 boards. The Python agent sends TCP/IP commands via LAN, which the BU translates to RS485 frames sent down the serial bus to each lock controller.

RS485 CommunicatorPCB Control BoardNetwork Bridge
KR-SBU|KERONG

Smart Basic Unit — Master Controller for SCU Networks

TCP/IP → RS485
KR-SBU — PCB Control System Parcel Locker Master Controller

PCB Control System Parcel Locker Master Controller

The KR-SBU is the master controller variant specifically designed for parcel locker deployments using KR-SCU standalone units. While architecturally similar to the KR-BU, it's optimized for managing large networks of individual SCU boards — each controlling a single locker compartment. It can manage up to 100 KR-SCU units in series, making it ideal for large-scale parcel delivery installations.

Key Features

  • Master controller for KR-SCU standalone unit ecosystem
  • Manages up to 100 KR-SCU units in series via RS485
  • TCP/IP to RS485 protocol conversion
  • Multi-platform support (iOS, Windows, Linux)
  • Designed for high-volume parcel locker deployments
  • Same robust ABS enclosure as KR-BU platform

Role in Our System

Used in our parcel locker deployments where each compartment has its own SCU board. The SBU aggregates commands from the Raspberry Pi and distributes them to individual SCU units, allowing independent control of each locker door.

PCB Control BoardMaster ControllerParcel Locker
KR-NCU16L|KERONG

Network Control Unit — All-in-One with TCP/IP

TCP/IP
KR-NCU16L — Intelligent Control System Smart Delivery Locker Controller

Intelligent Control System Smart Delivery Locker Controller

The KR-NCU16L is an all-in-one intelligent controller with built-in TCP/IP networking — no separate BU bridge required. It directly controls 16 locks from a single board and connects straight to your network via Ethernet. This makes it the simplest deployment option: just plug in power and Ethernet, and you have a network-connected 16-lock system. Up to 16 boards can be cascaded for 256 total locks.

Key Features

  • All-in-one: built-in TCP/IP networking — no separate BU needed
  • Controls 16 locks directly from one board
  • Up to 16 boards cascaded via RS485 (256 locks total)
  • Integrated infrared sensor and LED support per lock
  • IP67 rated for outdoor/harsh environment deployments
  • Open development platform with multi-OS support

Role in Our System

Ideal for standalone smart delivery locker kiosks. In our Wasfaty Pharmacy deployment, the NCU16L connects directly to the local network — the Raspberry Pi communicates via TCP/IP without needing a separate BU bridge, simplifying the hardware stack.

Intelligent ControlTCP/IPSmart DeliveryIP67
KR-SCU|KERONG

Standalone Control Unit — One Lock, One Board

RS485
KR-SCU — Intelligent Control System Parcel Delivery Locker Controller

Intelligent Control System Parcel Delivery Locker Controller

The KR-SCU is a single-lock standalone controller — one board per locker compartment. This avoids wasting channels on larger 16-way or 24-way boards when you need independent control of individual compartments. Up to 100 SCU units can be daisy-chained via RS485, each with its own infrared sensor and LED indicator. Perfect for mixed-size locker configurations where each door needs independent control logic.

Key Features

  • Single-lock controller — avoids wasting multi-channel boards
  • Up to 100 units daisy-chained via RS485 bus
  • Built-in infrared sensor for occupancy detection (empty/occupied)
  • LED status indicator per locker door
  • RS485-USB/232 converter for direct PC connection
  • Ideal for refrigerators, freezers, and specialty compartments

Role in Our System

Used in our Khozama Meals locker deployment for specialty compartments (heated/cooled). Each meal compartment gets its own SCU, allowing independent temperature-zone control while maintaining unified lock management through the SBU master.

Intelligent ControlParcel DeliveryStandalone
09

KR-CU24 Specifications

Kerong centralized lock control board — technical datasheet

Power SupplyDC 12V ~ 24V (triple-voltage selectable)
Working Current0.8A ~ 2A
Lock Channels24 per board
CommunicationRS485 (FTDI chip) + TCP/IP
CascadingUp to 16 boards in series (rotary switch addressing)
Dimensions218mm x 106mm
Operating Temp-25°C to +65°C
Humidity10% ~ 90% RH
Data IntegrityZero packet loss guarantee
Memory20,000 cards / 100,000 offline transactions
CertificationsCE, FCC, RoHS
Lock CompatibilityKR-S series electromagnetic solenoid locks