Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 01f3627

Browse files
committedSep 16, 2022
Added Docs for Rainmaker
1 parent 55d608e commit 01f3627

File tree

1 file changed

+672
-3
lines changed

1 file changed

+672
-3
lines changed
 

‎docs/source/api/rainmaker.rst

Lines changed: 672 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,672 @@
1-
#########
2-
RainMaker
3-
#########
1+
#############
2+
ESP Rainmaker
3+
#############
4+
5+
About
6+
-----
7+
8+
This library allows to work with ESP RainMaker.
9+
10+
ESP RainMaker is an end-to-end solution offered by Espressif to enable remote control and monitoring for ESP32-S2 and ESP32 based products without any configuration required in the Cloud. The primary components of this solution are:
11+
12+
- Claiming Service (to get the Cloud connectivity credentials)
13+
- RainMaker library (i.e. this library, to develop the firmware)
14+
- RainMaker Cloud (backend, offering remote connectivity)
15+
- RainMaker Phone App/CLI (Client utilities for remote access)
16+
17+
The key features of ESP RainMaker are:
18+
19+
1. Ability to define own devices and parameters, of any type, in the firmware.
20+
2. Zero configuration required on the Cloud.
21+
3. Phone apps that dynamically render the UI as per the device information.
22+
23+
Additional information about ESP RainMaker can be found `here <https://rainmaker.espressif.com/>`__.
24+
25+
#########################
26+
Arduino ESP Rainmaker API
27+
#########################
28+
29+
30+
ESP RainMaker Agent API
31+
-----------------------
32+
33+
34+
RMaker.initNode
35+
***************
36+
37+
This initializes the ESP RainMaker agent, wifi and creates the node.
38+
39+
You can also set the configuration of the node using the following API
40+
41+
``RMaker.setTimeSync(bool val)``
42+
43+
**NOTE**: If you want to set the configuration for the node then these configuration API must be called before `RMaker.initNode()`.
44+
45+
.. code-block:: arduino
46+
47+
Node initNode(const char *name, const char *type);
48+
49+
* ``name`` Name of the node
50+
* ``type`` Type of the node
51+
52+
This function will return object of Node.
53+
54+
55+
RMaker.start
56+
************
57+
58+
It starts the ESP RainMaker agent.
59+
60+
**NOTE**:
61+
62+
1. ESP RainMaker agent should be initialized before this call.
63+
2. Once ESP RainMaker agent starts, compulsorily call WiFi.beginProvision() API.
64+
65+
.. code-block:: arduino
66+
67+
esp_err_t start();
68+
69+
This function will return `ESP_OK` on success or `Error` in case of failure.
70+
71+
72+
RMaker.stop
73+
***********
74+
75+
It stops the ESP RainMaker agent which was started using `RMaker.start()`.
76+
77+
.. code-block:: arduino
78+
79+
esp_err_t stop()
80+
81+
This function will return
82+
83+
1. `ESP_OK` : On success
84+
2. Error in case of failure.
85+
86+
87+
RMaker.deinitNode
88+
*****************
89+
90+
It deinitializes the ESP RainMaker agent and the node created using `RMaker.initNode()`.
91+
92+
93+
.. code-block:: arduino
94+
95+
esp_err_t deinitNode(Node node)
96+
97+
* ``node`` : Node object created using `RMaker.initNode()`
98+
99+
This function will return
100+
101+
1. `ESP_OK` : On success
102+
2. Error in case of failure
103+
104+
105+
RMaker.enableOTA
106+
****************
107+
108+
It enables OTA as per the ESP RainMaker Specification. For more details refer ESP RainMaker documentation. check `here <https://rainmaker.espressif.com/docs/ota.html>`__.
109+
110+
.. code-block:: arduino
111+
112+
esp_err_t enableOTA(ota_type_t type);
113+
114+
* ``type`` : The OTA workflow type.
115+
- OTA_USING_PARAMS
116+
- OTA_USING_TOPICS
117+
118+
This function will return
119+
120+
1. `ESP_OK` : On success
121+
2. Error in case of failure
122+
123+
124+
RMaker.enableSchedule
125+
*********************
126+
127+
This API enables the scheduling service for the node. For more information, check `here <https://rainmaker.espressif.com/docs/scheduling.html>`__.
128+
129+
.. code-block:: arduino
130+
131+
esp_err_t enableSchedule();
132+
133+
134+
This function will return
135+
136+
1. `ESP_OK` : On success
137+
2. Error in case of failure
138+
139+
140+
RMaker.setTimeZone
141+
******************
142+
143+
This API set's the timezone as a user friendly location string. Check
144+
`here <https://rainmaker.espressif.com/docs/time-service.html>`__ for a list of valid values.
145+
146+
**NOTE** : default value is "Asia/Shanghai".
147+
148+
This API comes into picture only when working with scheduling.
149+
150+
.. code-block:: arduino
151+
152+
esp_err_t setTimeZone(const char *tz);
153+
154+
* ``tz`` : Valid values as specified in documentation.
155+
156+
This function will return
157+
158+
1. `ESP_OK` : On success
159+
2. Error in case of failure
160+
161+
162+
ESP RainMaker Node API
163+
-----------------------
164+
165+
`Node` class expose API's for node.
166+
167+
**NOTE** : my_node is the object of Node class.
168+
169+
170+
my_node.getNodeID
171+
*****************
172+
173+
It returns the unique node_id assigned to the node. This node_id is usually the MAC address of the board.
174+
175+
.. code-block:: arduino
176+
177+
char * getNodeID()
178+
179+
* ``tz`` : Valid values as specified in documentation.
180+
181+
This function will return
182+
183+
1. `char *` : Pointer to a NULL terminated node_id string.
184+
185+
186+
my_node.getNodeInfo
187+
*******************
188+
189+
It returns pointer to the node_info_t as configured during node initialisation.
190+
191+
.. code-block:: arduino
192+
193+
node_info_t * getNodeInfo();
194+
195+
This function will return
196+
197+
1. `node_info_t` : Pointer to the structure node_info_t on success.
198+
2. `NULL` : On failure.
199+
200+
**ESP RainMaker node info**
201+
202+
It has following data member
203+
204+
1. char * name
205+
2. char * type
206+
3. char * fw_version
207+
4. char * model
208+
209+
210+
my_node.addNodeAttr
211+
*******************
212+
213+
It adds a new attribute as the metadata to the node.
214+
215+
**NOTE** : Only string values are allowed.
216+
217+
.. code-block:: arduino
218+
219+
esp_err_t addNodeAttr(const char *attr_name, const char *val);
220+
221+
* ``attr_name`` : Name of the attribute
222+
* ``val`` : Value of the attribute
223+
224+
This function will return
225+
226+
1. `ESP_OK` : On success
227+
2. Error in case of failure
228+
229+
230+
my_node.addDevice
231+
*****************
232+
233+
It adds a device to the node.
234+
235+
**NOTE** :
236+
237+
- This is the mandatory API to register device to node.
238+
- Single Node can have multiple devices.
239+
- Device name should be unique for each device.
240+
241+
.. code-block:: arduino
242+
243+
esp_err_t addDevice(Device device);
244+
245+
* ``device`` : Device object
246+
247+
This function will return
248+
249+
1. `ESP_OK` : On success
250+
2. Error in case of failure
251+
252+
253+
my_node.removeDevice
254+
********************
255+
256+
It removes a device from the node.
257+
258+
.. code-block:: arduino
259+
260+
esp_err_t removeDevice(Device device);
261+
262+
* ``device`` : Device object
263+
264+
This function will return
265+
266+
1. `ESP_OK` : On success
267+
2. Error in case of failure
268+
269+
270+
271+
ESP RainMaker Device API
272+
-----------------------------
273+
274+
`Device` class expose API's for virtual devices on the node.
275+
Parameterized constructor is defined which creates the virtual device on the node. Using Device class object you can create your own device.
276+
277+
**NOTE** : my_device is the object of Device class
278+
279+
.. code-block:: arduino
280+
281+
Device my_device(const char *dev_name, const char *dev_type, void *priv_data);
282+
283+
* ``dev_name`` : Unique device name
284+
* ``dev_type`` : Optional device type. It can be kept NULL.
285+
* Standard Device Types
286+
* ESP_RMAKER_DEVICE_SWITCH
287+
* ESP_RMAKER_DEVICE_LIGHTBULB
288+
* ESP_RMAKER_DEVICE_FAN
289+
* ESP_RMAKER_DEVICE_TEMP_SENSOR
290+
* ``priv_data`` : Private data associated with the device. This will be passed to the callbacks.
291+
292+
**NOTE** : This created device should be added to the node using ``my_node.addDevice(my_device);``
293+
294+
- Sample example
295+
296+
.. code-block:: arduino
297+
298+
Device my_device("Switch");
299+
Device my_device("Switch1", NULL, NULL);
300+
301+
- Here, dev_name is compulsory, rest are optional.
302+
- Node can have multiple device, each device should have unique device name.
303+
304+
**Standard Devices**
305+
306+
- Classes are defined for the standard devices.
307+
- Creating object of these class creates the standard device with default parameters to it.
308+
- Class for standard devices
309+
* Switch
310+
* LightBulb
311+
* TemperatureSensor
312+
* Fan
313+
314+
.. code-block:: arduino
315+
316+
Switch my_switch(const char *dev_name, void *priv_data, bool power);
317+
318+
* ``dev_name`` : Unique device name by default it is "switch" for switch device.
319+
* ``priv_data`` : Private data associated with the device. This will be passed to the callbacks.
320+
* ``power`` : It is the value that can be set for primary parameter.
321+
322+
Sample example for standard device.
323+
324+
.. code-block:: arduino
325+
326+
Switch switch1;
327+
Switch switch2("switch2", NULL, true);
328+
329+
- `"switch2"` : Name for standard device.
330+
- `NULL` : Private data for the device, which will be used in callback.
331+
- `true` : Default value for the primary param, in case of switch it is power.
332+
333+
**NOTE**: No parameter are compulsory for standard devices. However if you are creating two objects of same standard class then in that case you will have to set the device name, if not then both device will have same name which is set by default, hence device will not get create. *Device name should be unique for each device.*
334+
335+
336+
my_device.getDeviceName
337+
***********************
338+
339+
It returns the name of the Device.
340+
341+
.. code-block:: arduino
342+
343+
const char * getDeviceName();
344+
345+
* ``device`` : Device object
346+
347+
This function will return
348+
349+
- `char *`: Returns Device name.
350+
351+
**NOTE**: Each device on the node should have unique device name.
352+
353+
354+
my_device.addDeviceAttr
355+
***********************
356+
357+
It adds attribute to the device. Device attributes are reported only once after a boot-up as part of the node configuration. Eg. Serial Number
358+
359+
.. code-block:: arduino
360+
361+
esp_err_t addDeviceAttr(const char *attr_name, const char *val);
362+
363+
* ``attr_name`` : Name of the attribute
364+
* ``val`` : Value of the attribute
365+
366+
This funtion will return
367+
368+
1. `ESP_OK` : On success
369+
2. Error in case of failure
370+
371+
372+
my_device.deleteDevice
373+
**********************
374+
375+
It deletes the device created using parameterized constructor.
376+
377+
This device should be first removed from the node using `my_node.removeDevice(my_device)`.
378+
379+
.. code-block:: arduino
380+
381+
esp_err_t deleteDevice();
382+
383+
This function will return
384+
385+
1. `ESP_OK` : On success
386+
2. Error in case of failure
387+
388+
389+
my_device.addXParam
390+
*******************
391+
392+
It adds standard parameter to the device.
393+
394+
**NOTE**: X is the default name by which parameter is referred, you can specify your own name to each parameter.
395+
396+
- Eg. `my_device.addPowerParam(true)` here power parameter is referred with name Power.
397+
- Eg. `my_device.addHueParam(12)` here hue parameter is referred with name Hue.
398+
399+
You can specify your own name to each parameter
400+
401+
- Eg. `my_device.addNameParam("NickName")` here name parameter is referred with name NickName.
402+
- Eg. `my_device.addPowerParam(true, "FanPower")` here power parameter is referred with name FanPower.
403+
404+
405+
**Standard Parameters**
406+
407+
* These are the standard parameters.
408+
* Name : ESP_RMAKER_DEF_NAME_PARAM
409+
* Power : ESP_RMAKER_DEF_POWER_NAME
410+
* Brightness : ESP_RMAKER_DEF_BRIGHTNESS_NAME
411+
* Hue : ESP_RMAKER_DEF_HUE_NAME
412+
* Saturation : ESP_RMAKER_DEF_SATURATION_NAME
413+
* Intensity : ESP_RMAKER_DEF_INTENSITY_NAME
414+
* CCT : ESP_RMAKER_DEF_CCT_NAME
415+
* Direction : ESP_RMAKER_DEF_DIRECTION_NAME
416+
* Speed : ESP_RMAKER_DEF_SPEED_NAME
417+
* Temperature : ESP_RMAKER_DEF_TEMPERATURE_NAME
418+
419+
420+
.. code-block:: arduino
421+
422+
esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM);
423+
esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME);
424+
esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME);
425+
esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME);
426+
esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME);
427+
esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME);
428+
esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME);
429+
esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME);
430+
esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME);
431+
esp_err_t addTempratureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME);
432+
433+
434+
This function will return
435+
436+
1. `ESP_OK` : On success
437+
2. Error in case of failure
438+
439+
**NOTE** : Care should be taken while accessing name of parameter. Above mentioned are the two ways using which default name of parameters can be accessed. Either LHS or RHS.
440+
441+
442+
my_device.assignPrimaryParam
443+
****************************
444+
445+
It assigns a parameter (already added using addXParam() or addParam()) as a primary parameter, which can be used by clients (phone apps specifically) to give prominence to it.
446+
447+
.. code-block:: arduino
448+
449+
esp_err_t assignPrimaryParam(param_handle_t *param);
450+
451+
* ``param`` : Handle of the parameter. It is obtained using `my_device.getParamByName()`.
452+
453+
This function will return
454+
455+
1. `ESP_OK` : On success
456+
2. Error in case of failure
457+
458+
459+
my_device.getParamByName
460+
************************
461+
462+
.. code-block:: arduino
463+
464+
param_handle_t * getParamByName(const char *param_name);
465+
466+
* ``param_name`` : It is the name of the parameter which was added using addXparam() or addParam().
467+
468+
This function will return object of the parameter.
469+
470+
471+
my_device.addParam
472+
******************
473+
474+
It allows user to add custom parameter to the device created using `Param` class.
475+
476+
.. code-block:: arduino
477+
478+
esp_err_t addParam(Param parameter);
479+
480+
* ``parameter`` : Object of Param
481+
482+
This function will return
483+
484+
1.`ESP_OK` : On success
485+
2. Error in case of failure
486+
487+
**NOTE**: Param class exposes API's to create the custom parameter.
488+
489+
490+
my_device.updateAndReportParam
491+
******************************
492+
493+
It updates the parameter assosicated with particular device on ESP RainMaker cloud.
494+
495+
.. code-block:: arduino
496+
497+
esp_err_t updateAndReportParam(const char *param_name, value);
498+
499+
* ``param_name`` : Name of the parameter
500+
* ``value`` : Value to be updated. It can be int, bool, char * , float.
501+
502+
This function will return
503+
504+
1. `ESP_OK` : On success
505+
2. Error in case of failure
506+
507+
508+
my_device.addCb
509+
***************
510+
511+
It registers read and write callback for the device which will be invoked as per requests received from the cloud (or other paths as may be added in future).
512+
513+
.. code-block:: arduino
514+
515+
void addCb(deviceWriteCb write_cb, deviceReadCb read_cb);
516+
517+
* ``write_cb`` : Function with signature
518+
func_name(Device \*device, Param \*param, const param_val_t val, void \*priv_data, write_ctx_t \*ctx);
519+
* ``read_cb`` : Function with signature
520+
func_name(Device \*device, Param \*param, void \*priv_data, read_ctx_t \*ctx);
521+
522+
523+
524+
525+
**Parameters**
526+
527+
**param_val_t val**
528+
529+
Value can be accessed as below
530+
531+
1. `bool` : val.val.b
532+
2. `integer` : val.val.i
533+
3. `float` : val.val.f
534+
4. `char *` : val.val.s
535+
536+
537+
538+
ESP RainMaker Param API
539+
-----------------------
540+
541+
`Param` class expose API's for creating custom parameters for the devices and report and update values associated with parameter to the ESP RainMaker cloud. Parameterized constructor is defined which creates custom parameter.
542+
543+
**NOTE** : `my_param` is the object of Param class.
544+
545+
.. code-block:: arduino
546+
547+
Param my_param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties);
548+
549+
* ``param_name`` : Name of the parameter
550+
* ``param_type`` : Type of the parameter. It is optional can be kept NULL.
551+
* ``val`` : Define the default value for the parameter. It should be defined using `value(int ival)` , `value(bool bval)` , `value(float fval)` , `value(char *sval)`.
552+
* ``properties`` : Properties of the parameter, which will be a logical OR of flags.
553+
* Flags
554+
* PROP_FLAG_WRITE
555+
* PROP_FLAG_READ
556+
* PROP_FLAG_TIME_SERIES
557+
* PROP_FLAG_PERSIST
558+
559+
Sample example :
560+
561+
.. code-block:: arduino
562+
563+
Param my_param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties);
564+
Param my_param("bright", NULL, value(30), PROP_FLAG_READ | PROP_FLAG_WRITE | PROP_FLAG_PERSIST);
565+
566+
**NOTE** : Parameter created using Param class should be added to the device using `my_device.addParam(my_param);`
567+
568+
569+
my_param.addUIType
570+
******************
571+
572+
Add a UI type to the parameter. This will be used by the Phone apps (or other clients) to render appropriate UI for the given parameter. Please refer the RainMaker documentation
573+
`here <https://rainmaker.espressif.com/docs/standard-types.html#ui-elements>`__ for supported UI Types.
574+
575+
.. code-block:: arduino
576+
577+
esp_err_t addUIType(const char *ui_type);
578+
579+
* ``ui_type`` : String describing the UI Type.
580+
* Standard UI Types
581+
* ESP_RMAKER_UI_TOGGLE
582+
* ESP_RMAKER_UI_SLIDER
583+
* ESP_RMAKER_UI_DROPDOWN
584+
* ESP_RMAKER_UI_TEXT
585+
586+
This function will return
587+
588+
1. `ESP_OK` : On success
589+
2. Error in case of failure
590+
591+
592+
my_param.addBounds
593+
******************
594+
595+
Add bounds for an integer/float parameter. This can be used to add bounds (min/max values) for a given integer/float parameter. Eg. brightness will have bounds as 0 and 100 if it is a percentage.
596+
597+
.. code-block:: arduino
598+
599+
esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step);
600+
601+
* ``min`` : Minimum value
602+
* ``max`` : Maximum value
603+
* ``step`` : step Minimum stepping
604+
605+
This function will return
606+
607+
1. `ESP_OK` : On success
608+
2. Error in case of failure
609+
610+
`Sample example : my_param.addBounds(value(0), value(100), value(5));`
611+
612+
613+
my_param.updateAndReport
614+
************************
615+
616+
It updates the parameter and report it to ESP RainMaker cloud. This is called in callback.
617+
618+
.. code-block:: arduino
619+
620+
esp_err_t updateAndReport(param_val_t val);
621+
622+
* ``val`` : New value of the parameter
623+
624+
This function will return
625+
626+
1. `ESP_OK` : On success
627+
2. Error in case of failure
628+
629+
**NOTE**:
630+
631+
- This API should always be called inside device write callback, if you aimed at updating n reporting parameter values, changed via RainMaker Client (Phone App), to the ESP RainMaker cloud.
632+
- If not called then paramter values will not be updated to the ESP RainMaker cloud.
633+
634+
635+
printQR
636+
*******
637+
638+
This API displays QR code, which is used in provisioning.
639+
640+
.. code-block:: arduino
641+
642+
printQR(const char *serv_name, const char *pop, const char *transport);
643+
644+
* ``name`` : Service name used in provisioning API.
645+
* ``pop`` : Proof of posession used in provisioning API.
646+
* ``transport`` :
647+
1. `softap` : In case of provisioning using SOFTAP.
648+
2. `ble` : In case of provisioning using BLE.
649+
650+
651+
RMakerFactoryReset
652+
******************
653+
654+
Reset the device to factory defaults.
655+
656+
.. code-block:: arduino
657+
658+
RMakerFactoryReset(int seconds);
659+
660+
* ``seconds`` : Time in seconds after which the chip should reboot after doing a factory reset.
661+
662+
663+
RMakerWiFiReset
664+
***************
665+
666+
Reset Wi-Fi credentials.
667+
668+
.. code-block:: arduino
669+
670+
RMakerWiFiReset(int seconds);
671+
672+
* ``seconds`` : Time in seconds after which the chip should reboot after doing a Wi-Fi reset.

0 commit comments

Comments
 (0)
Please sign in to comment.