Gashapon Machine Integration

Machine Communication Protocol

Machine Communication Flow

The protocol for communicating with the gashapon machine follows a specific command sequence. This section outlines the steps and commands involved in the interaction.

Machine Command Sequence

1. Device Login

The machine logs in to the server using the l command and receives device status information.

Command: l Already Implemented No Action Required

2. QR Code Scanning

The machine scans the QR code from the app and sends it to the machine backend for validation. The backend will call your API to validate the QR code.

Integration Required API Implementation

3. Point Deduction

The backend verifies the user has sufficient points and deducts the appropriate amount.

Backend Implementation Integration Required

4. Machine Activation

After point verification, a command is sent to the physical machine to dispense an item.

Important Commands

The following JSON commands are used to control the gashapon machine:

SE Command (Start Execution)

Sent from the machine backend to the gashapon machine to start the dispensing process.

{
  "cmd": "se",
  "mid": "MB001", // Mainboard ID
  "pid": "P1", // Position ID
  "cn": 1 // Number of coins to deduct
}
SER Command (Start Execution Response)

Sent from the gashapon machine to acknowledge receipt of the SE command.

{
  "cmd": "ser",
  "mid": "MB001",
  "pid": "P1",
  "result": "OK" // or "ERROR" with error code
}
ESR Command (Execution Result)

Sent from the gashapon machine after attempting to dispense an item, indicating success or failure.

{
  "cmd": "esr",
  "mid": "MB001",
  "pid": "P1",
  "result": "SUCCESS", // or "FAILURE" with error code
  "error_code": "", // Only present if result is FAILURE
  "timestamp": "2023-07-14T12:34:56Z"
}

Machine Communication Sequence

This diagram shows the machine communication sequence after QR code validation:

sequenceDiagram participant MB as Machine Backend participant GM as Gashapon Machine Note over MB,GM: After QR Code Validation MB->>GM: SE Command (Start Execution) GM->>MB: SER Command (Acknowledgment) GM->>GM: Execute Dispensing GM->>MB: ESR Command (Execution Result) Note over MB,GM: Transaction Complete
Machine Communication Diagram