You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
5.5 KiB
183 lines
5.5 KiB
/*void savedata()
|
|
{
|
|
|
|
JSONVar boardat;
|
|
if(min1<10)
|
|
{boardat["Time"] = String(hour1)+":0"+String(min1);
|
|
}
|
|
else
|
|
{
|
|
boardat["Time"] = String(hour1)+":"+String(min1);
|
|
}
|
|
boardat["temperatura"] =String(t1)+" C";
|
|
boardat["humidity"] = String(h1)+" %";
|
|
tempdat = JSON.stringify(boardat);
|
|
// Serial.println (tempdat);
|
|
//JSON { "Time":"11:03", "temperatura":"10.56 C", "humidity":"7,56 %" },
|
|
|
|
// myFile = SPIFFS.open("/TempUl.txt", FILE_WRITE);//создаем файл с именем TempUl
|
|
myFile = SPIFFS.open("/TempU1.txt", FILE_APPEND);//открываем файл в режиме добавления данных
|
|
myFile.print(tempdat+"\n");
|
|
myFile.close();
|
|
//****************************************************
|
|
|
|
|
|
}
|
|
|
|
void readdata()
|
|
{
|
|
//****************************************************
|
|
Serial.println("/TempU1.txt");
|
|
// Читаем содержимое файла:
|
|
|
|
myFile = SPIFFS.open("/TempU1.txt", FILE_READ);
|
|
|
|
|
|
|
|
// "Содержимое файла: \""
|
|
|
|
while(myFile.available()) {
|
|
|
|
Serial.write(myFile.read());
|
|
|
|
}
|
|
Serial.println(" ");
|
|
|
|
// Узнаем размер файла:
|
|
|
|
Serial.print("File size: ");
|
|
// "Размер файла: "
|
|
Serial.println(myFile.size());
|
|
|
|
myFile.close();
|
|
|
|
strdat="";
|
|
|
|
myFile = SPIFFS.open("/TempU1.txt", FILE_READ);
|
|
|
|
|
|
while(myFile.available()) {
|
|
|
|
strdat+=char(myFile.read());
|
|
|
|
}
|
|
|
|
|
|
myFile.close();
|
|
|
|
|
|
|
|
|
|
board1["tdata"] = strdat;
|
|
board1["dataserv"] = dataserv;
|
|
board1["timeserv"] = timeserv;
|
|
jsonString1 = JSON.stringify(board1);
|
|
// Serial.println (jsonString1);
|
|
// Serial.println ("strdat=");
|
|
//Serial.println (strdat);
|
|
|
|
// events.send(tempdat.c_str(), "readings", millis());//обновление веба
|
|
// events.send(strdat.c_str(), "readings", millis());//обновление веба
|
|
}*/
|
|
|
|
|
|
void Sdreaddata()//чтение данных после откл питания или сброса
|
|
{ Serial.println ("read SD data");
|
|
strdat="";
|
|
myFile = SD.open("/thkom1.txt", FILE_READ);
|
|
while(myFile.available()) {
|
|
|
|
strdat+=char(myFile.read());
|
|
|
|
}
|
|
|
|
|
|
myFile.close();
|
|
jsonString2=strdat;
|
|
Serial.println (jsonString2);
|
|
events.send(jsonString2.c_str(), "new_datatemp", millis());//обновление веба
|
|
JSONVar myObject = JSON.parse(strdat);
|
|
//{"tkom1":"","hkom1":"","batkom1":"","timekom1":"","tkom2":"25.1","hkom2":"50.1","batkom2":"4.0","timekom2":"22:00","tkor":"23.6","hkor":"45.7","batkor":"3.71","timekor":"21:55","tbal":"11.1","hbal":"56.3","batbal":"3.45","timebal":"21:47","tul1":"5.3","hul1":"99.9","osv1":"0%","timeul1":"22:01"}
|
|
|
|
if (myObject.hasOwnProperty("tkom1")) {
|
|
tkom1=((const char*) myObject["tkom1"]);}
|
|
if (myObject.hasOwnProperty("hkom1")) {
|
|
hkom1=((const char*) myObject["hkom1"]);}
|
|
if (myObject.hasOwnProperty("batkom1")) {
|
|
batkom1=((const char*) myObject["batkom1"]);}
|
|
if (myObject.hasOwnProperty("timekom1")) {
|
|
timekom1=((const char*) myObject["timekom1"]);}
|
|
|
|
if (myObject.hasOwnProperty("tkom2")) {
|
|
tkom2=((const char*) myObject["tkom2"]);}
|
|
if (myObject.hasOwnProperty("hkom2")) {
|
|
hkom2=((const char*) myObject["hkom2"]);}
|
|
if (myObject.hasOwnProperty("batkom2")) {
|
|
batkom2=((const char*) myObject["batkom2"]);}
|
|
if (myObject.hasOwnProperty("timekom2")) {
|
|
timekom2=((const char*) myObject["timekom2"]);}
|
|
|
|
|
|
if (myObject.hasOwnProperty("tkor")) {
|
|
tkor=((const char*) myObject["tkor"]);}
|
|
if (myObject.hasOwnProperty("hkor")) {
|
|
hkor=((const char*) myObject["hkor"]);}
|
|
if (myObject.hasOwnProperty("batkor")) {
|
|
batkor=((const char*) myObject["batkor"]);}
|
|
if (myObject.hasOwnProperty("timekor")) {
|
|
timekor=((const char*) myObject["timekor"]);}
|
|
|
|
if (myObject.hasOwnProperty("tbal")) {
|
|
tbal=((const char*) myObject["tbal"]);}
|
|
if (myObject.hasOwnProperty("hbal")) {
|
|
hbal=((const char*) myObject["hbal"]);}
|
|
if (myObject.hasOwnProperty("batbal")) {
|
|
batbal=((const char*) myObject["batbal"]);}
|
|
if (myObject.hasOwnProperty("timebal")) {
|
|
timebal=((const char*) myObject["timebal"]);}
|
|
|
|
if (myObject.hasOwnProperty("tul1")) {
|
|
tul1=((const char*) myObject["tul1"]);}
|
|
if (myObject.hasOwnProperty("hul1")) {
|
|
hul1=((const char*) myObject["hul1"]);}
|
|
if (myObject.hasOwnProperty("osv1")) {
|
|
osv1=((const char*) myObject["osv1"]);}
|
|
if (myObject.hasOwnProperty("timeul1")) {
|
|
timeul1=((const char*) myObject["timeul1"]);}
|
|
|
|
|
|
strdat="";
|
|
myFile = SD.open("/thku1.txt", FILE_READ);
|
|
while(myFile.available()) {
|
|
|
|
strdat+=char(myFile.read());
|
|
|
|
}
|
|
myFile.close();
|
|
jsonString=strdat;
|
|
Serial.println ("jsonString");
|
|
Serial.println (jsonString);
|
|
|
|
events.send(jsonString.c_str(), "new_readings", millis());//обновление веба текущая температура
|
|
myObject = JSON.parse(jsonString);
|
|
if (myObject.hasOwnProperty("id")) {
|
|
String id=((const char*) myObject["id"]);}
|
|
if (myObject.hasOwnProperty("temperature")) {
|
|
ts=((double) myObject["temperature"]);}
|
|
|
|
if (myObject.hasOwnProperty("humidity")) {
|
|
hs=((double) myObject["humidity"]);}
|
|
|
|
if (myObject.hasOwnProperty("tim2")) {
|
|
tim2=((const char*) myObject["tim2"]);}
|
|
if (myObject.hasOwnProperty("tim3")) {
|
|
tim3=((const char*) myObject["tim3"]);}
|
|
if (myObject.hasOwnProperty("dataserv")) {
|
|
dataserv=((const char*) myObject["dataserv"]);}
|
|
if (myObject.hasOwnProperty("timev")) {
|
|
timev=((int) myObject["timev"]);}
|
|
|
|
//{"id":2,"temperature":9.6733450317382812,"humidity":50.41815185546875,"tim2":"12:02",
|
|
// "dataserv":"12","timeserv":"15:30","munthserv":"январь",weekserv:"среда"}
|
|
|
|
}
|
|
|