131 if (f == NULL) { |
131 if (f == NULL) { |
132 // Create the file and add the header |
132 // Create the file and add the header |
133 f = fopen(filename, "a"); |
133 f = fopen(filename, "a"); |
134 if (f) { |
134 if (f) { |
135 strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
135 strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
136 fprintf(f, "{\n"); |
136 fprintf(f, "{\"brew\":[{\"Recipe\":\"%s %s\",\"Date\":\"%s\",\"brewdata\":[\n", recipe.Code, recipe.Name, strftime_buf); |
137 fprintf(f, " \"brew\": [{\n"); |
|
138 fprintf(f, " \"Recipe\":\"%s %s\",\n", recipe.Code, recipe.Name); |
|
139 fprintf(f, " \"Date\":\"%s\",\n", strftime_buf); |
|
140 fprintf(f, " \"brewdata\":[\n"); |
|
141 addcomma = false; |
137 addcomma = false; |
142 fclose(f); |
138 fclose(f); |
143 } else { |
139 } else { |
144 ESP_LOGE(TAG, "Failed to create %s error %d", filename, errno); |
140 ESP_LOGE(TAG, "Failed to create %s error %d", filename, errno); |
145 return; |
141 return; |
520 } else { |
516 } else { |
521 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile); |
517 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile); |
522 // First close the JSON data records |
518 // First close the JSON data records |
523 FILE *f = fopen(filename, "a+"); |
519 FILE *f = fopen(filename, "a+"); |
524 if (f) { |
520 if (f) { |
525 fprintf(f, " ],\n"); // End of brewdata |
521 fprintf(f, "],\"annotations\":[\n"); // End of brewdata |
526 fprintf(f, " \"annotations\":[\n"); |
|
527 // Insert annotation records |
522 // Insert annotation records |
528 sprintf(destname, "/spiffs/log/%s.anno", sdcard_state->logfile); |
523 sprintf(destname, "/spiffs/log/%s.anno", sdcard_state->logfile); |
529 FILE *a = fopen(destname, "r"); |
524 FILE *a = fopen(destname, "r"); |
530 char buf[256]; |
525 char buf[256]; |
531 if (a) { |
526 if (a) { |
537 } |
532 } |
538 } |
533 } |
539 fclose(a); |
534 fclose(a); |
540 unlink(destname); |
535 unlink(destname); |
541 } |
536 } |
542 fprintf(f, " ]\n"); // End of annotations |
537 fprintf(f, "]}]}\n"); // End of annotations and brew |
543 fprintf(f, " }]\n"); // End of brew |
|
544 fprintf(f, "}\n"); |
|
545 fclose(f); |
538 fclose(f); |
546 } |
539 } |
547 sprintf(destname, "/sdcard/w/log/%s.json", sdcard_state->logfile); |
540 sprintf(destname, "/sdcard/w/log/%s.json", sdcard_state->logfile); |
548 if (FileCopy(filename, destname) == 0) { |
541 if (FileCopy(filename, destname) == 0) { |
549 log_msg(TAG, "JSON file copied to %s", destname); |
542 log_msg(TAG, "JSON file copied to %s", destname); |