void savebalk()
{
boolean q=0;
  if((hb==hour1)&&( mb==min1)){q=1;}
  hb=hour1;
  mb=min1;
  if(q==0)
 { 
JSONVar boardat;
if(min1<10)
{boardat["Time"] = String(hour1)+":0"+String(min1); 
}
else
{
  boardat["Time"] = String(hour1)+":"+String(min1); 
}
boardat["temperatura"] =String(tbal)+" C";
boardat["humidity"] = String(hbal)+" %";
tempdat = JSON.stringify(boardat);
 Serial.println (tempdat);
   esp_task_wdt_reset();//reset WDT
//JSON { "Time":"11:03", "temperatura":"10.56 C", "humidity":"7,56 %" },
tempdat=tempdat+"\n";

 Serial.println ("name2");
//  String name1="/TEMPUL"+ stryen[stamp.year-2014]+strmen[stamp.month-1]+strden[stamp.day-1];
// Serial.println (name2);
createDir(SD, "/TEMPUL");
String name1="/TEMPUL"+ String(stryen[year1-2014]);//2022
 char Buf[50];
 name1.toCharArray(Buf, 50);
 Serial.println (Buf);
createDir(SD, Buf);
 name1=name1+String(strmen[month1-1]);//FEB
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);
 name1=name1+String(strden[data1-1]);//27
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);

 name1=name1+String(strdaten[2]);//
 name1.toCharArray(Buf, 50);
//createDir(SD, "/TEMPUL/2022/FEB/27");
// name1="/TEMPUL"+ String(stryen[stamp.year-2014])+String(strmen[stamp.month-1])+String(strden[stamp.day-1])+String(strdaten[0]);
 Serial.println (Buf);
appendFile(SD,Buf,tempdat.c_str());//добавление на инфы в файл
 }
}
//*************************K2*****************************************************************


void savek2()
{
 
JSONVar boardat;
if(min1<10)
{boardat["Time"] = String(hour1)+":0"+String(min1); 
}
else
{
  boardat["Time"] = String(hour1)+":"+String(min1); 
}
boardat["temperatura"] =String(tkom2)+" C";
boardat["humidity"] = String(hkom2)+" %";
tempdat = JSON.stringify(boardat);
 Serial.println (tempdat);
   esp_task_wdt_reset();//reset WDT
//JSON { "Time":"11:03", "temperatura":"10.56 C", "humidity":"7,56 %" },
tempdat=tempdat+"\n";

 Serial.println ("name2");
//  String name1="/TEMPUL"+ stryen[stamp.year-2014]+strmen[stamp.month-1]+strden[stamp.day-1];
// Serial.println (name2);
createDir(SD, "/TEMPUL");
String name1="/TEMPUL"+ String(stryen[year1-2014]);//2022
 char Buf[50];
 name1.toCharArray(Buf, 50);
 Serial.println (Buf);
createDir(SD, Buf);
 name1=name1+String(strmen[month1-1]);//FEB
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);
 name1=name1+String(strden[data1-1]);//27
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);

 name1=name1+String(strdaten[3]);//
 name1.toCharArray(Buf, 50);
//createDir(SD, "/TEMPUL/2022/FEB/27");
// name1="/TEMPUL"+ String(stryen[stamp.year-2014])+String(strmen[stamp.month-1])+String(strden[stamp.day-1])+String(strdaten[0]);
 Serial.println (Buf);
appendFile(SD,Buf,tempdat.c_str());//добавление на инфы в файл

}

//**************************K1****************************************************************


void savek1()
{
 boolean q=0;
  if((hk==hour1)&&( mk==min1)){q=1;}
  hk=hour1;
  mk=min1;
  if(q==0)
 { 
JSONVar boardat;
if(min1<10)
{boardat["Time"] = String(hour1)+":0"+String(min1); 
}
else
{
  boardat["Time"] = String(hour1)+":"+String(min1); 
}
boardat["temperatura"] =String(tkom1)+" C";
boardat["humidity"] = String(hkom1)+" %";
tempdat = JSON.stringify(boardat);
 Serial.println (tempdat);
   esp_task_wdt_reset();//reset WDT
//JSON { "Time":"11:03", "temperatura":"10.56 C", "humidity":"7,56 %" },
tempdat=tempdat+"\n";

 Serial.println ("name2");
//  String name1="/TEMPUL"+ stryen[stamp.year-2014]+strmen[stamp.month-1]+strden[stamp.day-1];
// Serial.println (name2);
createDir(SD, "/TEMPUL");
String name1="/TEMPUL"+ String(stryen[year1-2014]);//2022
 char Buf[50];
 name1.toCharArray(Buf, 50);
 Serial.println (Buf);
createDir(SD, Buf);
 name1=name1+String(strmen[month1-1]);//FEB
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);
 name1=name1+String(strden[data1-1]);//27
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);

 name1=name1+String(strdaten[4]);//
 name1.toCharArray(Buf, 50);
//createDir(SD, "/TEMPUL/2022/FEB/27");
// name1="/TEMPUL"+ String(stryen[stamp.year-2014])+String(strmen[stamp.month-1])+String(strden[stamp.day-1])+String(strdaten[0]);
 Serial.println (Buf);
appendFile(SD,Buf,tempdat.c_str());//добавление на инфы в файл
 }
}

//*********************akva*********************************************************************
void saveakva()
{
  String id="akva";
 board5["id"] =id;
  board5["tempakv1"] =takva1;
  board5["light1"] =String(lightakv);
    board5["timakv1"] =timeakva;
    if(fanak1==0)
    {fan1="OFF";
    }
    else
    {
      fan1="ON";
    }
     board5["fan1"] =fan1;
      board5["tempakv2"] =takva2;
   board5["light2"] =String(lightakv);
    board5["timakv2"] =timeakva;
     if(fanak2==0)
    {fan2="OFF";
    }
    else
    {
      fan2="ON";
    }
     board5["fan2"] =fan2;
      board5["tempakv3"] =takva3;
   board5["light3"] =String(lightakv);
    board5["timakv3"] =timeakva;
     if(fanak3==0)
    {fan3="OFF";
    }
    else
    {
      fan3="ON";
    }
     board5["fan3"] =fan3;

 jsonStringakva = JSON.stringify(board5);
 
 Serial.println (jsonStringakva);
 jsonStringakva=jsonStringakva+"\n";
 
 createDir(SD, "/AKVA");
String name1="/AKVA"+ String(stryen[year1-2014]);//2022
 char Buf[50];
 name1.toCharArray(Buf, 50);
 Serial.println (Buf);
createDir(SD, Buf);
 name1=name1+String(strmen[month1-1]);//FEB
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);
 name1=name1+String(strden[data1-1]);//27
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);

 name1=name1+String(strdaten[9]);//имя текстового файла TA
 name1.toCharArray(Buf, 50);
//createDir(SD, "/TEMPUL/2022/FEB/27/TA.txt");
// name1="/TEMPUL"+ String(stryen[stamp.year-2014])+String(strmen[stamp.month-1])+String(strden[stamp.day-1])+String(strdaten[0]);
 Serial.println (Buf);
appendFile(SD,Buf,jsonStringakva.c_str());//добавление на инфы в файл

}
//*********************kor*********************************************************************


void savekor()
{
 boolean q=0;
  if((hkr==hour1)&&( mkr==min1)){q=1;}
  hkr=hour1;
  mkr=min1;
  if(q==0)
 { 
JSONVar boardat;
if(min1<10)
{boardat["Time"] = String(hour1)+":0"+String(min1); 
}
else
{
  boardat["Time"] = String(hour1)+":"+String(min1); 
}
boardat["temperatura"] =String(tkor)+" C";
boardat["humidity"] = String(hkor)+" %";
tempdat = JSON.stringify(boardat);
 Serial.println (tempdat);
   esp_task_wdt_reset();//reset WDT
//JSON { "Time":"11:03", "temperatura":"10.56 C", "humidity":"7,56 %" },
tempdat=tempdat+"\n";

 Serial.println ("name2");
//  String name1="/TEMPUL"+ stryen[stamp.year-2014]+strmen[stamp.month-1]+strden[stamp.day-1];
// Serial.println (name2);
createDir(SD, "/TEMPUL");
String name1="/TEMPUL"+ String(stryen[year1-2014]);//2022
 char Buf[50];
 name1.toCharArray(Buf, 50);
 Serial.println (Buf);
createDir(SD, Buf);
 name1=name1+String(strmen[month1-1]);//FEB
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);
 name1=name1+String(strden[data1-1]);//27
 name1.toCharArray(Buf, 50);
  Serial.println (Buf);
 createDir(SD, Buf);

 name1=name1+String(strdaten[5]);//
 name1.toCharArray(Buf, 50);
//createDir(SD, "/TEMPUL/2022/FEB/27");
// name1="/TEMPUL"+ String(stryen[stamp.year-2014])+String(strmen[stamp.month-1])+String(strden[stamp.day-1])+String(strdaten[0]);
 Serial.println (Buf);
appendFile(SD,Buf,tempdat.c_str());//добавление на инфы в файл
 }
}
