297 topic = topic_base(); |
295 topic = topic_base(); |
298 topic = xstrcat(topic, (char *)"output/set/1"); |
296 topic = xstrcat(topic, (char *)"output/set/1"); |
299 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
297 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
300 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
298 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
301 gotit = true; |
299 gotit = true; |
302 if ((uint8_t)atoi(data) != Relay1) { |
300 Relay1 = (uint8_t)atoi(data); |
303 Relay1 = (uint8_t)atoi(data); |
301 nvsio_write_u8((char *)"out1", Relay1); |
304 err = nvs_open("balkon", NVS_READWRITE, &my_handle); |
|
305 if (err == ESP_OK) { |
|
306 nvs_set_u8(my_handle, (char *)"out1", Relay1); |
|
307 nvs_commit(my_handle); |
|
308 nvs_close(my_handle); |
|
309 } |
|
310 } |
|
311 } |
302 } |
312 free(topic); |
303 free(topic); |
313 topic = NULL; |
304 topic = NULL; |
314 |
305 |
315 topic = topic_base(); |
306 topic = topic_base(); |
316 topic = xstrcat(topic, (char *)"output/set/2"); |
307 topic = xstrcat(topic, (char *)"output/set/2"); |
317 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
308 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
318 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
309 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
319 gotit = true; |
310 gotit = true; |
320 if ((uint8_t)atoi(data) != Relay2) { |
311 Relay2 = (uint8_t)atoi(data); |
321 Relay2 = (uint8_t)atoi(data); |
312 nvsio_write_u8((char *)"out2", Relay2); |
322 err = nvs_open("balkon", NVS_READWRITE, &my_handle); |
|
323 if (err == ESP_OK) { |
|
324 nvs_set_u8(my_handle, (char *)"out2", Relay2); |
|
325 nvs_commit(my_handle); |
|
326 nvs_close(my_handle); |
|
327 } |
|
328 } |
|
329 } |
313 } |
330 free(topic); |
314 free(topic); |
331 topic = NULL; |
315 topic = NULL; |
332 |
316 |
333 topic = topic_base(); |
317 topic = topic_base(); |
334 topic = xstrcat(topic, (char *)"output/set/3"); |
318 topic = xstrcat(topic, (char *)"output/set/3"); |
335 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
319 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
336 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
320 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
337 gotit = true; |
321 gotit = true; |
338 if ((uint8_t)atoi(data) != Dimmer3) { |
322 Dimmer3 = (uint8_t)atoi(data); |
339 Dimmer3 = (uint8_t)atoi(data); |
323 nvsio_write_u8((char *)"out3", Dimmer3); |
340 err = nvs_open("balkon", NVS_READWRITE, &my_handle); |
|
341 if (err == ESP_OK) { |
|
342 nvs_set_u8(my_handle, (char *)"out3", Dimmer3); |
|
343 nvs_commit(my_handle); |
|
344 nvs_close(my_handle); |
|
345 } |
|
346 } |
|
347 } |
324 } |
348 free(topic); |
325 free(topic); |
349 topic = NULL; |
326 topic = NULL; |
350 |
327 |
351 topic = topic_base(); |
328 topic = topic_base(); |
352 topic = xstrcat(topic, (char *)"output/set/4"); |
329 topic = xstrcat(topic, (char *)"output/set/4"); |
353 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
330 if (strncmp(topic, event->topic, event->topic_len) == 0) { |
354 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
331 ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); |
355 gotit = true; |
332 gotit = true; |
356 if ((uint8_t)atoi(data) != Dimmer4) { |
333 Dimmer4 = (uint8_t)atoi(data); |
357 Dimmer4 = (uint8_t)atoi(data); |
334 nvsio_write_u8((char *)"out4", Dimmer4); |
358 err = nvs_open("balkon", NVS_READWRITE, &my_handle); |
|
359 if (err == ESP_OK) { |
|
360 nvs_set_u8(my_handle, (char *)"out4", Dimmer4); |
|
361 nvs_commit(my_handle); |
|
362 nvs_close(my_handle); |
|
363 } |
|
364 } |
|
365 } |
335 } |
366 free(topic); |
336 free(topic); |
367 topic = NULL; |
337 topic = NULL; |
368 |
338 |
369 if (! gotit) { |
339 if (! gotit) { |