@xstbot/cloudku-database 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -0
- package/index.js +41 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Cloudku S3
|
|
2
|
+
npm install cloudku-sdk
|
|
3
|
+
|
|
4
|
+
CONTOH PENGGUNAAN LENGKAP API
|
|
5
|
+
|
|
6
|
+
1. Spesifikasi API
|
|
7
|
+
Endpoint : https://db.cloudku.sbs/api/db/cloudku/sbs
|
|
8
|
+
Method : POST
|
|
9
|
+
Header : Content-Type: application/json
|
|
10
|
+
Fungsi : Menyimpan data JSON apa pun (user, sensor, log, dll) ke database.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
2. Contoh 1 — Kirim Data User
|
|
15
|
+
2.1 Tujuan : Menyimpan data pengguna aplikasi.
|
|
16
|
+
2.2 cURL
|
|
17
|
+
curl -X POST https://db.cloudku.sbs/api/db/cloudku/sbs \
|
|
18
|
+
-H "Content-Type: application/json" \
|
|
19
|
+
-d '{
|
|
20
|
+
"type": "user",
|
|
21
|
+
"username": "dev",
|
|
22
|
+
"role": "admin",
|
|
23
|
+
"created_at": "2025-01-01 10:00:00"
|
|
24
|
+
}'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
3. Contoh 2 — Kirim Data Sensor IoT
|
|
28
|
+
3.1 Tujuan : Menyimpan data pembacaan sensor.
|
|
29
|
+
3.2 cURL
|
|
30
|
+
curl -X POST https://db.cloudku.sbs/api/db/cloudku/sbs \
|
|
31
|
+
-H "Content-Type: application/json" \
|
|
32
|
+
-d '{
|
|
33
|
+
"type": "sensor",
|
|
34
|
+
"device_id": "ESP32-01",
|
|
35
|
+
"sensor": "DHT22",
|
|
36
|
+
"temperature": 24.5,
|
|
37
|
+
"humidity": 60,
|
|
38
|
+
"status": "OK",
|
|
39
|
+
"timestamp": "2025-01-01 10:05:00"
|
|
40
|
+
}'
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
4. Contoh 3 — Penggunaan di ESP32 (Arduino)
|
|
44
|
+
#include <WiFi.h>
|
|
45
|
+
#include <HTTPClient.h>
|
|
46
|
+
|
|
47
|
+
const char* ssid = "NAMA_WIFI";
|
|
48
|
+
const char* password = "PASSWORD_WIFI";
|
|
49
|
+
|
|
50
|
+
void setup() {
|
|
51
|
+
Serial.begin(115200);
|
|
52
|
+
WiFi.begin(ssid, password);
|
|
53
|
+
|
|
54
|
+
while (WiFi.status() != WL_CONNECTED) {
|
|
55
|
+
delay(500);
|
|
56
|
+
Serial.print(".");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (WiFi.status() == WL_CONNECTED) {
|
|
60
|
+
HTTPClient http;
|
|
61
|
+
http.begin("https://db.cloudku.sbs/api/db/cloudku/sbs");
|
|
62
|
+
http.addHeader("Content-Type", "application/json");
|
|
63
|
+
|
|
64
|
+
String jsonData = R"rawliteral(
|
|
65
|
+
{
|
|
66
|
+
"type": "sensor",
|
|
67
|
+
"device_id": "ESP32-01",
|
|
68
|
+
"sensor": "DHT22",
|
|
69
|
+
"temperature": 25.1,
|
|
70
|
+
"humidity": 58,
|
|
71
|
+
"status": "OK"
|
|
72
|
+
}
|
|
73
|
+
)rawliteral";
|
|
74
|
+
|
|
75
|
+
int httpResponseCode = http.POST(jsonData);
|
|
76
|
+
Serial.println(httpResponseCode);
|
|
77
|
+
http.end();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void loop() {
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
5. Contoh 4 — Penggunaan di Node.js
|
|
86
|
+
const axios = require("axios");
|
|
87
|
+
|
|
88
|
+
axios.post("https://db.cloudku.sbs/api/db/cloudku/sbs", {
|
|
89
|
+
type: "sensor",
|
|
90
|
+
device_id: "SERVER-01",
|
|
91
|
+
cpu_usage: 65,
|
|
92
|
+
ram_usage: 70,
|
|
93
|
+
status: "NORMAL"
|
|
94
|
+
})
|
|
95
|
+
.then(res => {
|
|
96
|
+
console.log("Success:", res.data);
|
|
97
|
+
})
|
|
98
|
+
.catch(err => {
|
|
99
|
+
console.error("Error:", err.message);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
6. Contoh 5 — Penggunaan di Python
|
|
105
|
+
import requests
|
|
106
|
+
|
|
107
|
+
url = "https://db.cloudku.sbs/api/db/cloudku/sbs"
|
|
108
|
+
|
|
109
|
+
data = {
|
|
110
|
+
"type": "user",
|
|
111
|
+
"username": "operator1",
|
|
112
|
+
"role": "operator"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
response = requests.post(url, json=data)
|
|
116
|
+
print(response.json())
|
|
117
|
+
|
|
118
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
class CloudkuDB {
|
|
4
|
+
|
|
5
|
+
constructor(baseURL = 'https://db.cloudku.sbs/api/db/cloudku/sbs') {
|
|
6
|
+
this.api = axios.create({
|
|
7
|
+
baseURL: baseURL,
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'Accept': 'application/json'
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async postUser(user, role) {
|
|
16
|
+
try {
|
|
17
|
+
const response = await this.api.post('', { user, role });
|
|
18
|
+
return response.data;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
this._handleError(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async postSensor(id, temp, status) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.api.post('', { id, temp, status });
|
|
27
|
+
return response.data;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
this._handleError(error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_handleError(error) {
|
|
34
|
+
if (error.response) {
|
|
35
|
+
throw new Error(`API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`);
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Network Error: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = CloudkuDB;
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xstbot/cloudku-database",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK DATABASE untuk akses Database Cloudku",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"cloudku",
|
|
11
|
+
"database",
|
|
12
|
+
"iot",
|
|
13
|
+
"sdk"
|
|
14
|
+
],
|
|
15
|
+
"author": "Arsyilla Official",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.13.2"
|
|
19
|
+
}
|
|
20
|
+
}
|