---
# System prepended metadata

title: Dokumentasi API Smart Stove
tags: [documentation, xirka]

---

###### tags : `xirka` `documentation`

---
title: "Dokumentasi API Smart Stove"
---

# Dokumentasi API Smart Stove

# A. Daftar Isi

[toc]

# B. Petunjuk Umum

| Item               | Nilai                    |
| ------------------ | ------------------------ |
| `{baseUrl}`        | http://202.148.1.57:8701 |
| Metode Autentikasi | Bearer Authentication    |

# C. Spesifikasi API

## 0. Auth

### 0.1 API List

url : `{baseUrl}/api/v1/auth`
| Metode | Auth | Endpoint | Query | Body | Deskripsi |
| -------- | -------- |-------- | -------- | -------- | -------- |
| Post | - |`{url}/token` | - | username*, password* | Mendapatkan Token |

> `*` : required field

### 0.2 Deskripsi Body

| Field    | Tipe   | Deskripsi      |
| -------- | ------ | -------------- |
| username | string | username klien |
| password | string | password klien |

### 0.3 Contoh Request

#### a. Mendapatkan Token

```curl
// request
curl --location --request POST 'http://localhost:8081/api/v1/auth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=klien-1' \
--data-urlencode 'password=bandung123'
```

```json
// response
{
  "status": "success",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImtsaWVuLTEiLCJyb2xlIjoiY2xpZW50IiwiaWF0IjoxNjQ2OTY4ODMxLCJleHAiOjE2NDY5Nzk2MzF9.V3p8KYnVhJ-hmCLDSMaYOy7wC91ardHam-0vLpAXoKU",
  "max_age": "3h",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImtsaWVuLTEiLCJyb2xlIjoiY2xpZW50IiwiaWF0IjoxNjQ2OTY4ODMxLCJleHAiOjE2NDY5OTA0MzF9.R-_0HKzfK2ml7fqd0KKNGxhcptgwfzX3tqPk_AHgwZM"
}
```

## 1. User

### 1.1 API List

url : `{baseUrl}/api/v1/user`
| Metode | Auth | Endpoint | Query | Body | Deskripsi |
| -------- | -------- |-------- | -------- | -------- | -------- |
| Post | - |`{url}` | - | username*, password*, password_confirmation\* | Daftar pelanggan baru |
| Get | - |`{url}/client` | limit, offset | - | Mendapatkan pelanggan |
| Delete | - |`{url}/client/{username}` | - | - | Menghapus pelanggan + data payload |

> `*` : required field

### 1.2 Deskripsi Body

| Field                 | Tipe   | Deskripsi                 |
| --------------------- | ------ | ------------------------- |
| username              | string | username klien            |
| password              | string | password klien            |
| password_confirmation | string | konfirmasi password klien |
| limit                 | number | jumlah data yang diminta  |
| offset                | number | banyak data yang dilewati |

### 1.3 Contoh Request

#### a. Daftar pelanggan baru

```curl
// request
curl --location --request POST 'http://localhost:8081/api/v1/user' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=klien-3' \
--data-urlencode 'password=bandung123' \
--data-urlencode 'password_confirmation=bandung123'
```

```json
// response
{
  "message": "created",
  "result": {
    "username": "klien-3"
  }
}
```

#### b. Mendapatkan list pelanggan

```curl
// request
curl --location --request GET 'http://localhost:8081/api/v1/user/client?limit=2' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0NjcyMjQ1NSwiZXhwIjoxNjQ2NzMzMjU1fQ.iL8-_YOkfDiic41CWjQD0AI9d8sXYmRBqvfI3uUiazI'
```

```json
// response
{
  "result": [
    {
      "_id": "621f300f7109c2110752f219",
      "username": "klien-1",
      "createdAt": "2022-03-02T08:51:27.946Z"
    },
    {
      "_id": "62258d0fc0c1a98d310abded",
      "username": "klien-3",
      "createdAt": "2022-03-07T04:41:51.849Z"
    }
  ],
  "count": 2
}
```

#### c. Menghapus pelanggan

```curl
// request
curl --location --request DELETE 'http://192.168.2.7:8081/api/v1/user/client/klien-1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0ODAwNTIwMiwiZXhwIjoxNjQ4MDE2MDAyfQ.dt6SZMES2shQXH3QagIE1Gv6DQHxqdC2GYwgEZb-uM4'
```

## 2. Stove

### 2.1 API List

url : `{baseUrl}/api/v1/stove`
| Metode | Auth | Endpoint | Query | Body | Deskripsi |
| -------- | -------- |-------- | -------- | -------- | -------- |
| Post | True |`{url}` | - | `_id`_, key _ | Daftar perangkat kompor baru oleh admin |
| Post | True |`{url}/submission` | - | `_id`_, username _ | Pengajuan kompor oleh klien / admin |
| Post | True |`{url}/inactivate` | - | `_id`_, username _ | Menonaktifkan kompor oleh admin |
| Get | True |`{url}/active/{username}` | - | - | Mendapatkan data kompor aktif + payload terakhir |
| Delete | True |`{url}/{_id}` | - | - | Menghapus kompor + payload |

> `*` : required field

### 2.2 Deskripsi Body

| Field    | Tipe   | Deskripsi                                 |
| -------- | ------ | ----------------------------------------- |
| `_id`    | string | id kompor                                 |
| key      | string | kunci untuk generate JWT pembacaan sensor |
| username | string | username klien                            |

### 2.3 Contoh Request

#### a. Daftar kompor baru

```curl
// request
curl --location --request POST 'http://localhost:8081/api/v1/stove' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0NjYyNjg5OCwiZXhwIjoxNjQ2NjM3Njk4fQ.eNF5Ysa01Hmxs9aWQvUEyAesrd0cIMsgGI8UTN-7pTQ' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=00000000001' \
--data-urlencode 'key=spat9uv8choh4pl2lhewA3otrabldrUqasep'

```

```json
// response
{
  "message": "created"
}
```

#### b. Pengajuan kompor oleh klien / admin

```curl
// request
curl --location --request POST 'http://localhost:8081/api/v1/stove/submission' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0NjYyNjg5OCwiZXhwIjoxNjQ2NjM3Njk4fQ.eNF5Ysa01Hmxs9aWQvUEyAesrd0cIMsgGI8UTN-7pTQ' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=00000000001' \
--data-urlencode 'username=klien-1'
```

#### c. Menonaktifkan kompor

```curl
// request
curl --location --request POST 'http://localhost:8081/api/v1/stove/inactive' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0NjcyMjQ1NSwiZXhwIjoxNjQ2NzMzMjU1fQ.iL8-_YOkfDiic41CWjQD0AI9d8sXYmRBqvfI3uUiazI' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_id=00000000001' \
--data-urlencode 'username=klien-1'
```

#### d. Mendapatkan data kompor aktif

```curl
// request
curl --location --request GET 'http://localhost:8081/api/v1/stove/active/klien-1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImtsaWVuLTEiLCJyb2xlIjoiY2xpZW50IiwiaWF0IjoxNjQ2NjMyNjM2LCJleHAiOjE2NDY2NDM0MzZ9.ZTeg5f-s4fe4oHi6sb78VVc1-irlSEC4TPt3KrQZwxM'
```

```json
// response
{
  "message": "ok",
  "result": {
    "_id": "00000000001",
    "createdAt": "2022-03-08T02:42:46.266Z",
    "payload": {
      "data": {
        "vs": "v10",
        "t": 1646882044,
        "E": 10,
        "EM": 21.3
      }
    }
  }
}
```

#### e. Menghapus kompor
```curl
curl --location --request DELETE 'http://192.168.2.7:8081/api/v1/stove/12345678901' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0ODAwNTIwMiwiZXhwIjoxNjQ4MDE2MDAyfQ.dt6SZMES2shQXH3QagIE1Gv6DQHxqdC2GYwgEZb-uM4'
```

## 3. Stove Payload

### 3.1 API List

url : `{baseUrl}/stove-payload`
| Metode | Auth | Endpoint | Query | Body | Deskripsi |
| -------- | -------- |-------- | -------- | -------- | -------- |
| Post | True |`{url}` | - | username*, payload*, method\* | Mengirim data pengukuran kompor harian oleh admin / klien |
| Get | True |`{url}/{stove}` | limit, offset | - | Mendapatkan data kompor berdasarkan id kompor |

> `*` : required field

### 3.2 Deskripsi Body

| Field    | Tipe   | Deskripsi                                                                 |
| -------- | ------ | ------------------------------------------------------------------------- |
| username | string | username klien                                                            |
| payload  | string | data pengukuran kompor yang telah dikonversi menjadi JWT (body+signature) |
| method   | string | metode pengukuran (bluetooth / qrcode)                                    |
| limit    | number | jumlah data yang diminta                                                  |
| offset   | number | banyak data yang dilewati                                                 |

### 3.3 Contoh Request

#### a. Mengirim data kompor harian

> catatan : Data kompor akan disimpan pada database berdasarkan tanggal. Jika klien mengirimkan data lebih dari 1 kali pada tanggal yang sama, maka server akan menyimpan data terakhir (parameter `t` pada payload).

```curl
// request
curl --location --request POST 'http://192.168.2.7:8081/api/v1/stove-payload' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0Njk2ODk1MCwiZXhwIjoxNjQ2OTc5NzUwfQ.UVV8yQKTOQtdhmgPUR9jhyprPi-gnxuz-WCzUybHASQ' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=klien-1' \
--data-urlencode 'payload=djEwOzAwMDAwMDAwMDAxOzE2NDY4ODIwNDQ7MDAxMC4wMDA7MDAwMjEuMzAwO0FQSUtFWTAx.1I_oLhJKehB_zKZCdKcJWF_yWBAcQUMZuNID67BFjek' \
--data-urlencode 'method=qrcode'
```

#### b. Mendapatkan data kompor berdasarkan id kompor

```curl
// request
curl --location --request GET 'http://localhost:8081/api/v1/stove-payload/00000000001?limit=2' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6InN1cGVydXNlciIsImlhdCI6MTY0NjcxODA2MSwiZXhwIjoxNjQ2NzI4ODYxfQ.74q1WBcRb7HB95MKib8y5vwU965MYXYHrocvVmtNh9I'
```

```json
// response
{
  "result": [
    {
      "_id": "62298c793651c1eccbaa5b6e",
      "data": {
        "vs": "v10",
        "t": 1646882044,
        "E": 10,
        "EM": 21.3
      }
    }
  ],
  "count": 1
}
```

# D. Demo Akun

- User

| Username | Role   | Password      |
| -------- | ------ | ------------- |
| admin    | admin  | bandung123abc |
| klien-1  | client | bandung123    |
| klien-3  | client | bandung123    |

- Kompor

| Stove Id    | Key                                  | User    |
| ----------- | ------------------------------------ | ------- |
| 00000000001 | spat9uv8choh4pl2lhewA3otrabldrUqasep | klien-1 |
| 00000000002 | daAt9uv8c3ol2asQlhewA3otrabl3rUUastk | -       |

> Silakan menambahkan kompor beserta key jika diperlukan dengan menggunakan akun `admin`.

# E. Halaman QR Code Generator

Pada web ini disediakan QR Code generator yang disesuaikan dengan spesifikasi yang telah dikeluarkan oleh PLN untuk mempermudah simulasi pembacaan qrcode.
Akses halaman tersebut di : `http://202.148.1.57:8701/qr-code`

- Halaman Generate QR Code
  ![](https://i.imgur.com/bv6TL5Q.png)

- Hasil Generate QR Code
  ![](https://i.imgur.com/zlsSDvB.png)

- Membaca QR Code
  ![](https://i.imgur.com/mVMZAO3.png)
