跳到主要内容

标准预定义类型

创建设备时通常需要在代码中进行多次调用。例如,要创建一个新设备,类型为灯泡 (Lightbulb),参数包括名称 (Name)、功率 (Power) 和亮度 (Brightness),则需代码如下:

esp_rmaker_device_t *device = esp_rmaker_device_create("Light", NULL, NULL);

esp_rmaker_device_add_param(device, esp_rmaker_param_create("name", NULL, esp_rmaker_str("Light"),
PROP_FLAG_READ | PROP_FLAG_WRITE | PROP_FLAG_PERSIST));

esp_rmaker_param_t *power_param = esp_rmaker_param_create("power", NULL, esp_rmaker_bool(true), PROP_FLAG_READ | PROP_FLAG_WRITE);
esp_rmaker_param_add_ui_type(power_param, ESP_RMAKER_UI_TOGGLE);
esp_rmaker_device_add_param(device, power_param);
esp_rmaker_device_assign_primary_param(device, power_param);

esp_rmaker_param_t *brightness_param = esp_rmaker_param_create("brightness", NULL, esp_rmaker_int(100), PROP_FLAG_READ | PROP_FLAG_WRITE);
esp_rmaker_param_add_ui_type(brightness_param, ESP_RMAKER_UI_SLIDER);
esp_rmaker_param_add_bounds(brightness_param, esp_rmaker_int(0), esp_rmaker_int(100), esp_rmaker_int(1));
esp_rmaker_device_add_param(device, brightness_param);

上述代码灵活性较高,允许用户定义任何类型的设备。然而,为了对常见用例进行简化,RainMaker 已经定义了一些标准类型,并为其添加了 API。使用标准类型后可将上述代码简化如下:

light_device = esp_rmaker_lightbulb_device_create("Light", NULL, true);
esp_rmaker_device_add_cb(light_device, write_cb, NULL);

esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create("brightness", 100));

标准类型也有助于在 RainMaker 手机应用或第三方应用(如 Alexa 或谷歌语音助手)中定义一些特殊的处理程序。下文表格列出了目前支持的标准设备类型、服务、参数和 UI 元素,表格内容会随着新类型的添加而不断更新。

设备

加粗参数为必要参数。
* 符号表示该参数为主要参数。

实现其中部分功能的 C 语言 API 可参考 此处。其余功能可通过原始 API 来构建,列在表中是为了表明它们在 Alexa 或谷歌语音助手 (GVA) 等客户端中有特殊处理程序。

名称类型参数GVAAlexa标志
Switchesp.device.switchName, Power*SWITCHSWITCH
Lightbulbesp.device.lightbulbName, Power*, Brightness, Color Temperature, Hue, Saturation, Intensity, Light ModeLIGHTLIGHT
Lightesp.device.lightName, Power*, Brightness, Color Temperature, Hue, Saturation, Intensity, Light ModeLIGHTLIGHTX
Fanesp.device.fanName, Power*, Speed, DirectionFANFAN
Temperature Sensoresp.device.temperature-sensorName, Temperature*XTEMPERATURE
_SENSOR
Outletesp.device.outletName, Power*OUTLETSMARTPLUG
Plugesp.device.plugName, Power*OUTLETSMARTPLUGX
Socketesp.device.socketName, Power*OUTLETSMARTPLUGX
Lockesp.device.lockName,
Lock State*
LOCKSMARTLOCK
Internal Blindsesp.device.blinds-internalName,
Blinds Position*
BLINDSINTERIOR_BLINDX
External Blindsesp.device.blinds-externalName,
Blinds Position*
BLINDSEXTERIOR_BLINDX
Garage Dooresp.device.garage-doorName,
Garage Position*, Lock State
GARAGEGARAGE_DOORX
Speakeresp.device.speakerName, Power*, Media State, Media Control, Volume, MuteSPEAKERSPEAKERX
Air Conditioneresp.device.air-conditionerName, Power*, Setpoint Temperature, Fan Speed, AC ModeAC_UNITAIR_CONDITIONERX
Thermostatesp.device.thermostatName, Setpoint Temperature*, AC Mode, PowerTHERMOSTATTHERMOSTAT
TVesp.device.tvName, Power*, Media State, Media Control App Selector, Input Selector, Volume, MuteTVTVX
Washeresp.device.washerName, ModeWASHERWASHERX
Contact Sensoresp.device.contact-sensorName,
Contact Detection State*
XCONTACT_SENSORX
Motion Sensoresp.device.motion-sensorName,
Motion Detection State*
XMOTION_SENSORX
Door Bellesp.device.doorbellName,
Pressed State*
XDOORBELLX
Security Panelesp.device.security-panelName, Arm State*,
Fire Alarm State,
Water Alarm State,
CO Alarm State,
Burglary Alarm State
XSECURITY_PANELX
Otheresp.device.otherXOTHER

服务

加粗参数为必要参数。

实现这些功能的 C 语言 API 可参考 此处

名称类型参数
OTAesp.service.otaOTA URL, OTA Status, OTA Info
Scheduleesp.service.schedulesSchedules
Timeesp.service.timeTZ, TZ-POSIX
Systemesp.service.systemReboot, Factory-Reset, Wi-Fi-Reset

参数

实现其中部分功能的 C 语言 API 可参考 此处。其余功能可通过原始 API 来构建,列在表中是为了表明它们在 Alexa 或谷歌语音助手 (GVA) 等客户端中有特殊处理程序。

名称类型数据类型UI 类型特性最小值、最大值、步长
Nameesp.param.nameStringRead, Write1, 32, -
Poweresp.param.powerBoolesp.ui.toggleRead, WriteN/A
Brightnessesp.param.brightnessIntesp.ui.sliderRead, Write0, 100, 1
CCTesp.param.cctIntesp.ui.sliderRead, Write2700, 6500, 100
Hueesp.param.hueIntesp.ui.sliderRead, Write0, 360, 1
Saturationesp.param.saturationIntesp.ui.sliderRead, Write0, 100, 1
Intensityesp.param.intensityIntesp.ui.sliderRead, Write0, 100, 1
Speedesp.param.speedIntesp.ui.sliderRead, Write0, 5, 1
Directionesp.param.directionIntesp.ui.dropdownRead, Write0, 1, 1
Temperatureesp.param.temperatureFloatReadN/A
OTA URLesp.param.ota_urlStringN/AWriteN/A
OTA Statusesp.param.ota_statusStringN/AReadN/A
OTA Infoesp.param.ota_infoStringN/AReadN/A
Timezoneesp.param.tzStringN/ARead, WriteN/A
Timezone POSIXesp.param.tz_posixStringN/ARead, WriteN/A
Schedulesesp.param.schedulesArrayN/ARead, Write, PersistN/A
Rebootesp.param.rebootBoolN/ARead, WriteN/A
Factory-Resetesp.param.factory-resetBoolN/ARead, WriteN/A
Wi-Fi-Resetesp.param.wifi-resetBoolN/ARead, WriteN/A
Toggle Controlleresp.param.toggleBool任意类型Read, WriteN/A
Range Controlleresp.param.rangeInt/Float任意类型Read, Write视具体应用而定
Mode Controlleresp.param.modeStringesp.ui.dropdownRead, WriteN/A
Setpoint Temperatureesp.param.setpoint-temperatureInt/Float任意类型Read/WriteN/A
Lock Stateesp.param.lockstateInt任意类型Read, Write0, 2, 1
0: Unlocked
1: Locked
2: Jammed
Blinds Positionesp.param.blinds-positionIntesp.ui.sliderRead/Write0, 100, 1
Garage Positionesp.param.garage-positionIntesp.ui.sliderRead/Write0, 100, 1
Light Modeesp.param.light-modeIntesp.ui.dropdown/
esp.ui.hidden
Read/Write0, 2, 1
0: invalid
1: HSV
2: CCT
AC Modeesp.paran.ac-modeStringesp.ui.dropdownRead/WriteN/A
Media Stateesp.param.media-activity-stateStringesp.ui.dropdownRead/WriteN/A
Media Controlesp.param.media-activity-controlStringesp.ui.dropdownRead/WriteN/A
Volumeesp.param.volumeFloatesp.ui.sliderRead/Write0, 20, 1
Muteesp.param.muteBoolesp.ui.toggleRead/WriteN/A
App Selectoresp.param.app-selectorStringesp.ui.dropdownRead/WriteN/A
Input Selectoresp.param.input-selectorStringesp.ui.dropdownRead/WriteN/A
Contact Detection Stateesp.param.contact-detection-stateboolesp.ui.toggleReadN/A
Motion Detection Stateesp.param.motion-detection-stateboolesp.ui.toggleReadN/A
Arm Stateesp.param.arm-stateboolesp.ui.toggleRead/WriteN/A
Fire Alarm Stateesp.param.fire-alarmboolesp.ui.toggleReadN/A
Water Alarm Stateesp.param.water-alarmboolesp.ui.toggleReadN/A
CO Detection Stateesp.param.carbon-monoxide-alarmboolesp.ui.toggleReadN/A
Burglary Alarm Stateesp.param.burglary-alarmboolesp.ui.toggleReadN/A

UI 元素

下方表格定义了相关参数在手机应用中的呈现方式。

名称类型数据类型要求示例
Text(默认)esp.ui.text所有N/A
Toggle Switchesp.ui.toggleBoolN/A
Slideresp.ui.sliderInt, Float设定边界 (min/max)
Brightness Slideresp.ui.sliderInt参数类型 =
esp.param.brightness
CCT Slideresp.ui.sliderInt参数类型 = esp.param.cct
Saturation Slideresp.ui.sliderInt参数类型 =
esp.param.saturation
Hue Slideresp.ui.hue-sliderInt参数类型 =
esp.param.hue
Hue Circleesp.ui.hue-circleInt参数类型 =
esp.param.hue
Push button (Big)esp.ui.push-btn-bigBoolN/A
Dropdownesp.ui.dropdownInt/StringInt:设定边界 (min/max)
String:有效字符串
Trigger
(仅安卓)
esp.ui.triggerBoolN/A
Hidden
(仅安卓)
esp.ui.hiddenBoolN/A参数隐藏