完整示例
← WiFi 扫描 | API 概述
JavaScript API 客户端封装
class MiBee Cam API {
constructor(baseURL = '') {
this.base = baseURL;
}
get headers() {
return {
'Content-Type': 'application/json'
};
}
async getStatus() {
const resp = await fetch(`${this.base}/api/status`);
return resp.json();
}
async getConfig() {
const resp = await fetch(`${this.base}/api/config`);
return resp.json();
}
async updateConfig(fields) {
const resp = await fetch(`${this.base}/api/config`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(fields)
});
return resp.json();
}
async getFiles() {
const resp = await fetch(`${this.base}/api/files`);
return resp.json();
}
async deleteFile(name) {
const resp = await fetch(
`${this.base}/api/files?name=${encodeURIComponent(name)}`,
{ method: 'DELETE', headers: this.headers }
);
return resp.json();
}
async downloadFile(name) {
const resp = await fetch(
`${this.base}/api/download?name=${encodeURIComponent(name)}`
);
return resp.blob();
}
async scanWifi() {
const resp = await fetch(`${this.base}/api/scan`);
return resp.json();
}
async setTime(date) {
const resp = await fetch(`${this.base}/api/time`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
hour: date.getHours(),
min: date.getMinutes(),
sec: date.getSeconds()
})
});
return resp.json();
}
async startRecording() {
const resp = await fetch(`${this.base}/api/record?action=start`, {
method: 'POST',
headers: this.headers
});
return resp.json();
}
async stopRecording() {
const resp = await fetch(`${this.base}/api/record?action=stop`, {
method: 'POST',
headers: this.headers
});
return resp.json();
}
async factoryReset() {
const resp = await fetch(`${this.base}/api/reset`, {
method: 'POST',
headers: this.headers
});
return resp.json();
}
getStreamURL() {
return `${this.base}/stream`;
}
}
JavaScript 使用示例
const cam = new MiBee CamAPI('http://192.168.4.1', 'admin');
async function showStatus() {
const { data } = await cam.getStatus();
console.log(`录像: ${data.recording}`);
console.log(`WiFi: ${data.wifi_state} (${data.ip})`);
console.log(`存储: ${data.sd_free_percent}% 可用`);
console.log(`运行: ${Math.floor(data.uptime / 3600)}h ${Math.floor((data.uptime % 3600) / 60)}m`);
}
async function quickSetup(ssid, pass) {
await cam.updateConfig({ wifi_ssid: ssid, wifi_pass: pass });
console.log('WiFi 已配置,设备将连接网络');
}
async function downloadAll() {
const { data } = await cam.getFiles();
for (const file of data.files) {
console.log(`正在下载: ${file.name} (${(file.size / 1048576).toFixed(1)} MB)`);
const blob = await cam.downloadFile(file.name);
}
}
cURL 命令手册
设备状态与配置
curl http://192.168.4.1/api/status
curl http://192.168.4.1/api/config
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{"device_name": "KitchenCam"}'
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{"wifi_ssid": "HomeWiFi", "wifi_pass": "wifipassword"}'
录像控制
curl -X POST "http://192.168.4.1/api/record?action=start"
curl -X POST "http://192.168.4.1/api/record?action=stop"
文件管理
curl http://192.168.4.1/api/files
curl -o recording.avi "http://192.168.4.1/api/download?name=20260424_120000.avi"
curl -X DELETE "http://192.168.4.1/api/files?name=20260424_120000.avi"
网络与时间
curl http://192.168.4.1/api/scan
curl -X POST http://192.168.4.1/api/time \
-H "Content-Type: application/json" \
-d '{"year": 2026, "month": 4, "day": 24, "hour": 14, "min": 30, "sec": 0}'
NAS 上传配置
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{
"upload_method": 1,
"webdav_url": "https://dav.example.com/MiBee Cam",
"webdav_user": "davuser",
"webdav_pass": "davsecret",
"webdav_enabled": true
}'
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{
"upload_method": 2,
"http_upload_url": "https://upload.example.com/api/cam",
"http_upload_user": "httpuser",
"http_upload_pass": "httppassword"
}'
摄像头参数
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{"resolution": 2, "fps": 15}'
curl -X POST http://192.168.4.1/api/config \
-H "Content-Type: application/json" \
-d '{"jpeg_quality": 6}'
恢复出厂设置
curl -X POST http://192.168.4.1/api/reset