@@ -80,11 +80,11 @@ typedef struct {
80
80
81
81
static esp_rmaker_priv_data_t * esp_rmaker_priv_data ;
82
82
83
- static char * esp_rmaker_populate_node_id ()
83
+ static char * esp_rmaker_populate_node_id (bool use_claiming )
84
84
{
85
85
char * node_id = esp_rmaker_storage_get ("node_id" );
86
86
#ifdef ESP_RMAKER_CLAIM_ENABLED
87
- if (!node_id ) {
87
+ if (!node_id && use_claiming ) {
88
88
uint8_t eth_mac [6 ];
89
89
esp_err_t err = esp_wifi_get_mac (WIFI_IF_STA , eth_mac );
90
90
if (err != ESP_OK ) {
@@ -188,8 +188,34 @@ char *esp_rmaker_get_node_id(void)
188
188
}
189
189
return NULL ;
190
190
}
191
+
192
+ static esp_err_t esp_rmaker_mqtt_data_init (esp_rmaker_priv_data_t * rmaker_priv_data , bool use_claiming )
193
+ {
194
+ rmaker_priv_data -> mqtt_config = esp_rmaker_get_mqtt_config ();
195
+ if (rmaker_priv_data -> mqtt_config ) {
196
+ return ESP_OK ;
197
+ }
198
+ #ifdef ESP_RMAKER_CLAIM_ENABLED
199
+ if (use_claiming ) {
200
+ #ifdef CONFIG_ESP_RMAKER_SELF_CLAIM
201
+ rmaker_priv_data -> claim_data = esp_rmaker_self_claim_init ();
202
+ #endif
203
+ #ifdef CONFIG_ESP_RMAKER_ASSISTED_CLAIM
204
+ rmaker_priv_data -> claim_data = esp_rmaker_assisted_claim_init ();
205
+ #endif
206
+ if (!rmaker_priv_data -> claim_data ) {
207
+ ESP_LOGE (TAG , "Failed to initialise Claiming." );
208
+ return ESP_FAIL ;
209
+ } else {
210
+ rmaker_priv_data -> need_claim = true;
211
+ return ESP_OK ;
212
+ }
213
+ }
214
+ #endif /* ESP_RMAKER_CLAIM_ENABLED */
215
+ return ESP_FAIL ;
216
+ }
191
217
/* Initialize ESP RainMaker */
192
- static esp_err_t esp_rmaker_init (const esp_rmaker_config_t * config )
218
+ static esp_err_t esp_rmaker_init (const esp_rmaker_config_t * config , bool use_claiming )
193
219
{
194
220
if (esp_rmaker_priv_data ) {
195
221
ESP_LOGE (TAG , "ESP RainMaker already initialised" );
@@ -209,7 +235,7 @@ static esp_err_t esp_rmaker_init(const esp_rmaker_config_t *config)
209
235
return ESP_ERR_NO_MEM ;
210
236
}
211
237
212
- esp_rmaker_priv_data -> node_id = esp_rmaker_populate_node_id ();
238
+ esp_rmaker_priv_data -> node_id = esp_rmaker_populate_node_id (use_claiming );
213
239
if (!esp_rmaker_priv_data -> node_id ) {
214
240
esp_rmaker_deinit_priv_data (esp_rmaker_priv_data );
215
241
esp_rmaker_priv_data = NULL ;
@@ -232,34 +258,19 @@ static esp_err_t esp_rmaker_init(const esp_rmaker_config_t *config)
232
258
return ESP_FAIL ;
233
259
}
234
260
#endif /* !CONFIG_ESP_RMAKER_DISABLE_USER_MAPPING_PROV */
235
- esp_rmaker_priv_data -> mqtt_config = esp_rmaker_get_mqtt_config ();
236
- if (!esp_rmaker_priv_data -> mqtt_config ) {
237
- #ifdef ESP_RMAKER_CLAIM_ENABLED
238
- #ifdef CONFIG_ESP_RMAKER_SELF_CLAIM
239
- esp_rmaker_priv_data -> claim_data = esp_rmaker_self_claim_init ();
240
- #endif
241
- #ifdef CONFIG_ESP_RMAKER_ASSISTED_CLAIM
242
- esp_rmaker_priv_data -> claim_data = esp_rmaker_assisted_claim_init ();
243
- #endif
244
- if (!esp_rmaker_priv_data -> claim_data ) {
245
- esp_rmaker_deinit_priv_data (esp_rmaker_priv_data );
246
- esp_rmaker_priv_data = NULL ;
247
- ESP_LOGE (TAG , "Failed to initialise Claiming." );
248
- return ESP_FAIL ;
249
- }
250
- esp_rmaker_priv_data -> need_claim = true;
251
- #else
261
+ if (esp_rmaker_mqtt_data_init (esp_rmaker_priv_data , use_claiming ) != ESP_OK ) {
252
262
esp_rmaker_deinit_priv_data (esp_rmaker_priv_data );
253
263
esp_rmaker_priv_data = NULL ;
254
264
ESP_LOGE (TAG , "Failed to initialise MQTT Config. Please perform \"claiming\" using RainMaker CLI." );
255
265
return ESP_FAIL ;
256
- #endif /* !ESP_RMAKER_CLAIM_ENABLED */
257
266
} else {
258
- if (esp_rmaker_mqtt_init (esp_rmaker_priv_data -> mqtt_config ) != ESP_OK ) {
259
- esp_rmaker_deinit_priv_data (esp_rmaker_priv_data );
260
- esp_rmaker_priv_data = NULL ;
261
- ESP_LOGE (TAG , "Failed to initialise MQTT" );
262
- return ESP_FAIL ;
267
+ if (!esp_rmaker_priv_data -> need_claim ) {
268
+ if (esp_rmaker_mqtt_init (esp_rmaker_priv_data -> mqtt_config ) != ESP_OK ) {
269
+ esp_rmaker_deinit_priv_data (esp_rmaker_priv_data );
270
+ esp_rmaker_priv_data = NULL ;
271
+ ESP_LOGE (TAG , "Failed to initialise MQTT" );
272
+ return ESP_FAIL ;
273
+ }
263
274
}
264
275
}
265
276
esp_rmaker_priv_data -> enable_time_sync = config -> enable_time_sync ;
@@ -285,7 +296,7 @@ static esp_err_t esp_rmaker_register_node(const esp_rmaker_node_t *node)
285
296
286
297
esp_rmaker_node_t * esp_rmaker_node_init (const esp_rmaker_config_t * config , const char * name , const char * type )
287
298
{
288
- esp_err_t err = esp_rmaker_init (config );
299
+ esp_err_t err = esp_rmaker_init (config , true );
289
300
if (err != ESP_OK ) {
290
301
return NULL ;
291
302
}
0 commit comments