---
# System prepended metadata

title: MQTT message topic
tags: [' mPOS', NewPOS]

---

---
tags: NewPOS, mPOS
---

# MQTT message topic

## Currently reserved (API Raspberry Pi)
### Receipt printer
- `tk3c/{storeno}/prn/{id}` receipt printer print receipt
- `tk3c/{storeno}/prns` receipt printer status
- `tk3c/{storeno}/prnjob`  receipt printer after receipt print response
- `tk3c/{storeno}/prnwill` receipt printer will

### Usage logging / monitor / pos-keeper
- `tk3c/log/stat/+`
- `tk3c/log/activity/+`
- `tk3c/log/+/+`
- `tk3c/mpos/+` ?

### Device(ipad)
- `tk3c/device/{Serial Number}`
#### Message

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>tk3c/device/{Serial Number}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"pos.in",
  "data": { 
    "sn":"{Serial Number}",
    "ip":"10.1.62.132",
    "iep":"{scope}/dock/{dockUID}"
    "oep":"{scope}/dock/{dockUID}/outbound"
  }
}
```
</td></tr>

</table>



---

## New POS (Dock Raspberry Pi)

```plantuml
@startuml
node "client" as a
node "dock service" as b
circle Message as msg
circle Event as evt

a - msg
msg --> b
evt - b
a <- evt
@enduml
```

> Note
> - Message : incoming
> - Event : outgoing

**Current topics**
- `{scope}/sd` - inbound / outbound(limited)
- `{scope}/sd/svinfo`
- `{scope}/dock/{dockUID}` - inbound
- `{scope}/dock/{dockUID}/outbound` - outbound

**Capabilities**

<table>
<thead><tr><th>Capability</th><th>flag</th></tr></thead>
<tbody>

<tr><td rowspan=3><code>dock</code></td><td><code>dock.info</code></td></tr>
<tr><td><code>dock.allocated</code></td></tr>
<tr><td><code>dock.bindtest</code></td></tr>

<tr><td rowspan=2><code>escpos</code></td><td><code>escpos.print</code></td></tr>
<tr><td><code>escpos.kickdrawer</code></td></tr>

<tr><td><code>edctsb</code></td><td><code>edctsb.req</code></td></tr>

<tr><td><code>codereader</code></td><td><code>codereader.input</code></td></tr>

<tr><td><code>checkusb</code></td><td></td></tr>

</tbody></table>

### service directory

#### Message

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/sd</code></td>
<td>

```json
{
   "verb":"lookup",
   "svctype":"posdock.mqtt",
   "replyTo":"any/topic"
}
```

```json
{
   "verb":"lookup",
   "svcuid": <service uuid>
   "replyTo":"any/topic"
}
```

```json
{
   "verb":"lookup",
   "replyTo":"any/topic"
}
```
</td></tr>
<tr><td><code>{scope}/sd/svcinfo</code></td>
<td></td></tr></tbody>
</table>

#### Event

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>&lt;any/topic&gt;</code></td>
<td>

```json
[
   {
      "uuid":"ba0adc78-f0fd-11eb-acae-dca632d40b19",
      "type":"posdock.mqtt",
      "state":10,
      "active": true,
      "desc":"iep=tk3c/dock/dca632d40b19,oep=tk3c/dock/dca632d40b19/outbound",
      "info":{
        "capabilities": [
          "dock", "escpos", "edctsb", "codereader", "checkusb",
        ]
      },
      "namespace":{
         "name":"ba135538-f0fd-11eb-acae-dca632d40b19@10.1.62.132",
         "sd":"ba135538-f0fd-11eb-acae-dca632d40b19",
         "location":"10.1.62.132"
      },
      "endpoints":[
         {
            "type":"iep",
            "path":"tk3c/dock/dca632d40b19"
         },
         {
            "type":"oep",
            "path":"tk3c/dock/dca632d40b19/outbound"
         }
      ],
   }
]
```
</td></tr>
</tbody>
</table>

### dock service

#### Message
<table>
<thead><tr><th>Topic</th><th>Message</th><th>Note</th></tr></thead>
<tbody>
<tr><td><code>{scope}/dock/{dockUID}/outbound</code></td>
<td>

```json
{
  "flag": "dock.info",
}
```
</td><td>Get dock service and its sub-service(s)' info </td></tr>
</tbody>
</table>

#### Event

<table>
<thead><tr><th>Topic</th><th>Message</th><th>Note</th></tr></thead>
<tbody>
<tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock": "d711fa90-fb3e-11eb-8db3-dca632d40b19",
  "flag": "dock.info",
  "data": {
    "uuid": "d711fa90-fb3e-11eb-8db3-dca632d40b19",
    "type": "posdock.mqtt",
    "state": 10,
    "active": true,
    "desc": "iep=tk3c/dock/dca632d40b19,oep=tk3c/dock/dca632d40b19/outbound",
    "info": {
      "capabilities": [
        "dock",
        "escpos",
        "edctsb",
        "codereader",
        "checkusb"
      ]
    },
    "endpoints": [
      {
        "type": "iep",
        "path": "tk3c/dock/dca632d40b19"
      },
      {
        "type": "oep",
        "path": "tk3c/dock/dca632d40b19/outbound"
      }
    ],
    "subservices": [
      {
        "uuid": "d71abf7c-fb3e-11eb-8db3-dca632d40b19",
        "type": "escpos",
        "state": 2,
        "active": true,
        "info": {
          "id": "2",
          "vendor": "Partner",
          "model": "RP700",
          "state": 2,
          "status_value": 2,
          "status_text": "ONLINE"
        }
      },
      {
        "uuid": "d71ae880-fb3e-11eb-8db3-dca632d40b19",
        "type": "edctsb",
        "state": 10,
        "active": true,
        "desc": "EDC Terminal service (Taishin Bank)",
        "info": {
          "name": "/dev/ttyUSB0",
          "timeout_seconds": 60,
          "active": true,
          "usb": {
            "vid": "0x557",
            "pid": "0x2008"
          }
        }
      },
      {
        "uuid": "d71b208e-fb3e-11eb-8db3-dca632d40b19",
        "type": "codereader",
        "state": 2,
        "active": true
      },
      {
        "uuid": "d71b377c-fb3e-11eb-8db3-dca632d40b19",
        "type": "checkusb",
        "state": 2,
        "active": true
      }
    ]
  }
}
```
</td><td>various status report</td></tr>
</tbody>
</table>

<!-- tk3c/storeNo/dock/dockUID -->



### receipt printer / escpos


#### Message

<!-- <table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/{store}/prn/{prnid}</code></td>
<td>

```json
{ ... }
```
</td></tr>
</tbody>
</table> -->

<table>
<thead><tr><th>Topic</th><th>Message</th><th>Note</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"escpos.print",
  "data": {...}
}
```
</td><td>  

[receipt printing model](https://hackmd.io/@chhuang/BycnYBz5w)
</td></tr>
<tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"escpos.kickdrawer",
  "data": null
}
```
</td><td></td></tr>
</tbody>
</table>

#### Event

<table>
<thead><tr><th>Topic</th><th>Message</th><th>Note</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}/outbound</code></td>
<td>

```json
{
  "dock":"",
  "flag":"escpos.print",
  "data": {...}
}
```
</td><td>

[return model](https://hackmd.io/@chhuang/BycnYBz5w#POSPrinter-return-values)
</td></tr>
</tbody>
</table>

<!-- tk3c/storeNo/dock/dockUID/printer -->

### barcode reader
#### Event

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}/outbound</code></td>
<td>

```json
{
  "dock":"",
  "flag":"codereader.input",
  "data": "..."
}
```
</td></tr>
</tbody>
</table>

<!-- tk3c/storeNo/dock/dockUID/codereader -->
### edc terminal (TSB)

> [Detailed `data` model](https://hackmd.io/@tk3c-mpos/BkRMT4_hO#%E4%BF%A1%E7%94%A8%E5%8D%A1%E4%BA%A4%E6%98%93%E8%A6%81%E6%B1%82-%E5%A4%9A%E5%85%83-%E4%B8%80%E8%88%AC%E5%88%86%E6%9C%9F%E7%B4%85%E5%88%A9)

#### Message

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"edctsb.req",
  "data": {
    ...
  }
}
```
</td></tr>
</tbody>
</table>

#### Event

<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}/outbound</code></td>
<td>

```json
{
   "dock":"9f5f674e-d4ca-11eb-91e2-dca632d40b19",
   "flag":"edctsb.req",
   "data":{ ... }
}
```
</td></tr>
</tbody>
</table>



<!-- tk3c/storeNo/dock/dockUID/edc -->
### Dock Bind

#### inbound
##### 1.Allocated Event
<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"dock.allocated",
  "craft":"DMPDQ256LM95", //Serial Number 
  "data": true/false
}
```
</td></tr>
</tbody>
</table>

##### 2.Allocated Event(測試用 無需插裝置)
<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}</code></td>
<td>

```json
{
  "dock":"",
  "flag":"dock.bindtest",
  "craft":"DMPDQ256LM95", //Serial Number 可自填
  "data": true/false
}
```
</td></tr>
</tbody>
</table>

#### outbound

##### 1.Allocated Event
<table>
<thead><tr><th>Topic</th><th>Message</th></tr></thead>
<tbody><tr><td><code>{scope}/dock/{dockUID}/outbound</code></td>
<td>

```json
{
  "dock":"",
  "flag":"dock.allocated",
  "craft":"DMPDQ256LM95", //Serial Number 
  "data": true/false
}
```
</td></tr>
</tbody>
</table>

<!-- tk3c/storeNo/dock/dockUID/Dock_Bind -->




---
---
---
---
## Suggestion (mPOS)
- serial no
  - publish on server start (retained)
  - publish on user login/logout/settle
  - publish on successful transaction
- invoice no
  - publish on server start (retained)
  - publish on successful transaction
- force logout
  - publish on server start





