csv to firebase
bool log_to_fb(){
String log_buf="";
if((Firebase.getString(firebaseData, on_path+"/lc"))){
String buf = firebaseData.stringData();
fb_count = buf.toInt();
if ((log_count<= fb_count)){ return(false);}
if ((SPIFFS.exists("/log.csv"))){
File f = SPIFFS.open("/log.csv", "r");
if (!f){return(false);}
while(f.available()) {
log_buf = "";
log_buf = f.readStringUntil('\n');
log_buf +="\0";
splitCommand(log_buf);
}
f.close();
return(true);
}
}else{return(true);}
}
//=====================================================================================
bool splitCommand(String text) {
String dt="",rh="",rt="",ft="",ct="",bt="",pw="",nw="",lc="";
int index =0;
bool FB = true;
while (text[index]!=','){dt+=text[index]; index++;}index++;dt.trim();
while (text[index]!=','){rh+=text[index]; index++;}index++;rh.trim();
while (text[index]!=','){rt+=text[index]; index++;}index++;rt.trim();
while (text[index]!=','){ft+=text[index]; index++;}index++;ft.trim();
while (text[index]!=','){ct+=text[index]; index++;}index++;ct.trim();
while (text[index]!=','){bt+=text[index]; index++;}index++;bt.trim();
while (text[index]!=','){pw+=text[index]; index++;}index++;pw.trim();
while (text[index]!=','){nw+=text[index]; index++;}index++;nw.trim();
while (text[index]!='\0'){lc+=text[index]; index++;}index++;lc.trim();
index =0;
String fb_dt="";
while (dt[index]!=' '){fb_dt+=text[index]; index++;}index++;fb_dt.trim();
fb_dt+="\0";
if ( lc.toInt()<=fb_count){return(false);}
json.clear();
json.add("dt" ,dt);
json.add("rh" ,rh);
json.add("rt" ,rt);
json.add("ft" ,ft);
json.add("ct" ,ct);
json.add("bt" ,bt);
json.add("pw" ,pw);
json.add("nw" ,nw);
json.add("lc" ,lc);
FB = false;
int j;
while (!FB)
{
if (Firebase.pushJSON(firebaseData, ga_path+fb_dt,json)){
Firebase.setString(firebaseData, on_path+"lc",lc);
FB=true;}
j++;
if (j>5) break;
}
/*lcd.setCursor(11,2);
lcd.print("Log--->DB");
lcd.setCursor(11,3);
sprintf(BUF,"%d",log_count);
lcd.print(BUF);
lcd.setCursor(20-lc.length(),3);
lcd.print(lc);*/
return (FB);
}
ความคิดเห็น
แสดงความคิดเห็น