瀏覽代碼

2020-02-05 / ct_chen

Actions:
1. logPackTools 修改壓縮檔名為Model name+Serial no+yyyymmddhhiiss, 避免OCPP上傳到後台因檔名重覆而覆蓋
2. php程式增加curl供OCPP上傳檔案到後台

Files:
1. EVSE/Modularization/logPackTools.c
2. EVSE/rootfs/var/www/ocpp_upload.php
ct_chen 5 年之前
父節點
當前提交
2956453435
共有 2 個文件被更改,包括 30 次插入7 次删除
  1. 13 7
      EVSE/Modularization/logPackTools.c
  2. 17 0
      EVSE/rootfs/var/www/ocpp_upload.php

+ 13 - 7
EVSE/Modularization/logPackTools.c

@@ -226,17 +226,23 @@ int main(int argc, char *argv[]) {
 	return 0;
 	}
 	if(strcmp(argv[1], "log") == 0){
+		unsigned char			ModelName[64];;
 		unsigned char			SerialNo[64];;
+		memcpy(ModelName,ShmSysConfigAndInfo->SysConfig.ModelName,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		printf("%s", ModelName);
 		memcpy(SerialNo,ShmSysConfigAndInfo->SysConfig.SerialNumber,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
 		printf("%s", SerialNo);
-		int year,month,i,ty,tm,cnt;
-		char ym[7] ;
+		int year,month,day,hour,min,sec,i,ty,tm,cnt;
 		char pwd[70];
 		char cmd[100];
 		time_t tt = time(0); //獲取當前時間
 		struct tm *pst = localtime(&tt); //把time_t類型轉換為struct tm類型
 		year = pst->tm_year + 1900;
 		month = pst->tm_mon + 1;
+		day = pst->tm_mday;
+		hour = pst->tm_hour;
+		min = pst->tm_min;
+		sec = pst->tm_sec;
 		if((argc == 3) && isdigit(*argv[2])){
 			cnt=atoi(argv[2]);
 		}
@@ -252,16 +258,16 @@ int main(int argc, char *argv[]) {
 				tm=month-i;
 				ty=year;
 			}
-			sprintf(ym,"%04d-%02d",ty,tm);
 			sprintf(pwd,"%04d%02d%s",year,month,SerialNo);
-			sprintf(cmd,"zip --password %s \t /mnt/%04d-%02d.zip \t /Storage/ChargeLog/*%04d*%02d*\n",pwd,year,month,ty,tm);
+			sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/ChargeLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
 			system(cmd);
-			sprintf(cmd,"zip --password %s \t /mnt/%04d-%02d.zip \t /Storage/EventLog/*%04d*%02d*\n",pwd,year,month,ty,tm);
+			sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/EventLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
 			system(cmd);
-			sprintf(cmd,"zip --password %s \t /mnt/%04d-%02d.zip \t /Storage/SystemLog/*%04d*%02d*\n",pwd,year,month,ty,tm);
+			sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/SystemLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
+			system(cmd);
+			sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/OCPP/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
 			system(cmd);
 			printf("Log packing is done!\n");
-	//		zip --password "'.date('Ym').$SerialNumber.'" -r /var/www/log.zip /Storage/
 		}
 	}
 }

+ 17 - 0
EVSE/rootfs/var/www/ocpp_upload.php

@@ -0,0 +1,17 @@
+<?php
+$content=file("/mnt/upload_file.txt");
+$url = $content[0];
+$upload_file = $content[1];
+ 
+$ch = curl_init();
+ 
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+curl_setopt($ch, CURLOPT_URL, $url);
+ 
+### 設定要上傳檔案的路徑
+$upload_data = array(
+    'upload_file' => $upload_file,
+);
+ 
+curl_setopt($ch, CURLOPT_POSTFIELDS, $upload_data);
+?>