main/iotbalkon.c

changeset 8
115e93bf8796
parent 7
2b337dd92f25
child 9
1659bd3c7a2b
equal deleted inserted replaced
7:2b337dd92f25 8:115e93bf8796
19 19
20 static TaskHandle_t xTaskBMP280 = NULL; 20 static TaskHandle_t xTaskBMP280 = NULL;
21 static TaskHandle_t xTaskINA219 = NULL; 21 static TaskHandle_t xTaskINA219 = NULL;
22 static TaskHandle_t xTaskMQTT = NULL; 22 static TaskHandle_t xTaskMQTT = NULL;
23 static TaskHandle_t xTaskWifi = NULL; 23 static TaskHandle_t xTaskWifi = NULL;
24
25 nvs_handle_t my_handle;
24 26
25 #define MAX_LOOPS 32 27 #define MAX_LOOPS 32
26 #define SUB_TIME 1000 28 #define SUB_TIME 1000
27 29
28 float temperature; 30 float temperature;
67 69
68 70
69 #define ST_INTERVAL 10000 71 #define ST_INTERVAL 10000
70 #define MAX_LOOPS 32 72 #define MAX_LOOPS 32
71 73
74 /*
75 * Variables in NVS namespace "balkon"
76 */
77 uint8_t Relay1;
78 uint8_t Relay2;
79 uint8_t Dimmer3;
80 uint8_t Dimmer4;
81
72 82
73 83
74 // 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% 84 // 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
75 float Charge_C_5[11] = { 12.40, 12.60, 12.75, 12.95, 13.20, 13.35, 13.55, 13.67, 14.00, 15.25, 15.94 }; 85 float Charge_C_5[11] = { 12.40, 12.60, 12.75, 12.95, 13.20, 13.35, 13.55, 13.67, 14.00, 15.25, 15.94 };
76 float Charge_C_10[11] = { 12.20, 12.38, 12.60, 12.80, 13.05, 13.20, 13.28, 13.39, 13.60, 14.20, 15.25 }; 86 float Charge_C_10[11] = { 12.20, 12.38, 12.60, 12.80, 13.05, 13.20, 13.28, 13.39, 13.60, 14.20, 15.25 };
271 ESP_LOGI(TAG, "Starting production"); 281 ESP_LOGI(TAG, "Starting production");
272 #endif 282 #endif
273 #ifdef CONFIG_CODE_TESTING 283 #ifdef CONFIG_CODE_TESTING
274 ESP_LOGI(TAG, "Starting testing"); 284 ESP_LOGI(TAG, "Starting testing");
275 #endif 285 #endif
286
287 /*
288 * Initialize NVS
289 */
290 esp_err_t err = nvs_flash_init();
291 if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
292 ESP_ERROR_CHECK(nvs_flash_erase());
293 err = nvs_flash_init();
294 }
295 ESP_ERROR_CHECK(err);
296
297 err = nvs_open("balkon", NVS_READWRITE, &my_handle);
298 if (err != ESP_OK) {
299 ESP_LOGE(TAG, "Error (%s) opening NVS handle 'balkon'", esp_err_to_name(err));
300 } else {
301 err = nvs_get_u8(my_handle, (char *)"out1", &Relay1);
302 if (err == ESP_ERR_NVS_NOT_FOUND) {
303 err = nvs_set_u8(my_handle, (char *)"out1", 0);
304 Relay1 = 0;
305 }
306 if (err != ESP_OK) {
307 ESP_LOGE(TAG, "Error (%s) opening NVS handle 'balkon', key 'out1'", esp_err_to_name(err));
308 }
309
310 err = nvs_get_u8(my_handle, (char *)"out2", &Relay2);
311 if (err == ESP_ERR_NVS_NOT_FOUND) {
312 err = nvs_set_u8(my_handle, (char *)"out2", 0);
313 Relay2 = 0;
314 }
315 if (err != ESP_OK) {
316 ESP_LOGE(TAG, "Error (%s) opening NVS handle 'balkon', key 'out2'", esp_err_to_name(err));
317 }
318
319 err = nvs_get_u8(my_handle, (char *)"out3", &Dimmer3);
320 if (err == ESP_ERR_NVS_NOT_FOUND) {
321 err = nvs_set_u8(my_handle, (char *)"out3", 0);
322 Dimmer3 = 0;
323 }
324 if (err != ESP_OK) {
325 ESP_LOGE(TAG, "Error (%s) opening NVS handle 'balkon', key 'out3'", esp_err_to_name(err));
326 }
327
328 err = nvs_get_u8(my_handle, (char *)"out4", &Dimmer4);
329 if (err == ESP_ERR_NVS_NOT_FOUND) {
330 err = nvs_set_u8(my_handle, (char *)"out4", 0);
331 Dimmer4 = 0;
332 }
333 if (err != ESP_OK) {
334 ESP_LOGE(TAG, "Error (%s) opening NVS handle 'balkon', key 'out4'", esp_err_to_name(err));
335 }
336
337 nvs_commit(my_handle);
338 nvs_close(my_handle);
339 }
276 340
277 gLastTime = millis(); 341 gLastTime = millis();
278 ESP_ERROR_CHECK(i2cdev_init()); 342 ESP_ERROR_CHECK(i2cdev_init());
279 343
280 bmp280_init_default_params(&bmp280_params); 344 bmp280_init_default_params(&bmp280_params);

mercurial