Created
February 7, 2021 00:26
-
-
Save dj1711572002/8b431088ad170bb26c23cde5b48b9a7a to your computer and use it in GitHub Desktop.
M5StickC NTRIP_CATER_ReCIver_With GPS Module_GGA getting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ALES_M5Stick_NewBizStatio_GGA_TEST__rev000.ino | |
/* | |
* NTRIP client for Arduino Ver. 1.0.0 | |
* NTRIPClient Sample | |
* Request Source Table (Source Table is basestation list in NTRIP Caster) | |
* Request Reference Data | |
* | |
* | |
*/ | |
//#include <ESP8266WiFi.h> //Need for ESP8266 | |
#include<M5StickC.h> | |
#include <WiFi.h> //Need for ESP32 | |
#include <NTRIPClient.h> | |
//#include "esp_http_client.h" | |
#include "FS.h" | |
#include "SPIFFS.h" | |
//SPIFFS Para----------------------- | |
String GPSGGA; | |
char GGAc[83]; | |
char GGAp[]={83}; | |
char fnm[]={"/GGA/txt"}; | |
char fname[30]; | |
File file; | |
#define FORMAT_SPIFFS_IF_FAILED true | |
int i,j,k,m; | |
int shokai=0; | |
int shokai_1; | |
String Listname[1000] ; | |
char file_name[20] = "/GGA.txt"; | |
int gpsFlag=0; | |
String Sentence; | |
int var_size = 2000; | |
//------------------------------- | |
#define YELLOW 0xFFE0 | |
//#include"M5Stack.h"; | |
const char* ssid = "WiFI SSID";// | |
const char* password = "WiFi Pass";// | |
int n; | |
char* host ="XXXXXXXXXXXXX";//NTRIP SERVER URL | |
int httpPort =2101; //port 2101 is default port of NTRIP caster | |
char* mntpnt ="YYYYYYYYYY";// ntrip caster's mountpoint"; | |
char* user = "ID"; //"ntrip caster's client user"; | |
char* passwd ="Pass";// "ntrip caster's client password"; | |
NTRIPClient ntrip_c; | |
//=================================================================================================== | |
//===========================GPS GGA GET sub========================================================= | |
//=================================================================================================== | |
void gps_gga() | |
{ | |
while(digitalRead(36)==0)//RED Button OFF(UP) | |
{ | |
//M5.Lcd.fillScreen(BLACK); | |
WiFi.disconnect();//NTRIP Receiving Stop | |
Serial2.begin(9600,SERIAL_8N1,0,26);//To LEFT_F9P EXT RX0 TX26*******(baudrate,config,RX,TX) | |
gpsFlag=1; | |
//Serial.println("GPS Connecting to Exit from GPS-> PUSH BtnA"); | |
M5.Lcd.setCursor(0,0); | |
M5.Lcd.setTextSize(1); | |
// M5.Lcd.println("GGA Fix=>PUSH BtnA"); | |
//==================GPS READING================================== | |
while(M5.BtnA.wasPressed()==0)//Loop until BtnA Pressed | |
{ | |
M5.update(); | |
if(Serial2.available()) | |
{ | |
Sentence=Serial2.readStringUntil('\n'); | |
//Serial.println(Sentence); | |
//M5.Lcd.setCursor(0,12); | |
if(Sentence.indexOf("$GPGGA")>= 0) | |
{ | |
GPSGGA=Sentence; | |
Serial.println(Sentence); | |
M5.Lcd.println(Sentence); | |
M5.Lcd.println("-------------------------"); | |
m++; | |
if(m%3==0) | |
{ | |
//M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.fillRect(0,8,160,80,BLACK); | |
M5.Lcd.setCursor(0,10); | |
} | |
} | |
}//=>Serial2.available end | |
}//=>While Untile BtnA was Pressed | |
if(shokai==0)// BtnA was Pressed後1回だけ----------------------------------------------------------- | |
{ | |
M5.Lcd.fillScreen(BLACK); | |
Serial.print("BtnA Pushed GGA="); | |
Serial.println(GPSGGA); | |
Serial.println("PUSH RED Butn Save GGA to SPIFFS GGA.txt"); | |
M5.Lcd.setCursor(0,10); | |
M5.Lcd.setTextColor(YELLOW); | |
M5.Lcd.println(GPSGGA); | |
M5.Lcd.println("PUSH RED Btn to SPIFFS GGA.txt"); | |
shokai_1=shokai; | |
shokai=1; | |
//--------------GGA String To CharArry and Save SPIFFS GGA.txt---------------------------- | |
str2char(GGAp,GPSGGA); | |
//dataS.toCharArray(c,dataS_len); | |
Serial.print("GGAp Length="); | |
Serial.println(strlen(GGAp)); | |
for (i=0;i<strlen(GGAp);i++) | |
{ | |
Serial.print("GGAp["); | |
Serial.print(i); | |
Serial.print("]="); | |
Serial.println(GGAp[i]); | |
} | |
writeFile(SPIFFS, "/GGA.txt", GGAp); | |
Serial.println("SPIFFS Write Finished"); | |
}//shokai==0 | |
}//=>while GPIO36 OFF | |
//if(shokai_1==0 && shokai==1) | |
if(M5.BtnA.isPressed()) | |
{ | |
//esp_restart();// Restart to NTRIP Rcv | |
} | |
}//gps_gga() END ============================================================================== | |
//*********************************************************************************************** | |
//setup() | |
//*********************************************************************************************** | |
void setup() { | |
M5.begin(); | |
pinMode(36, INPUT);//RED ButtonON:GPIO=1=GPS RedButtonOFF=GPIO36=0=GPS ON | |
M5.Lcd.setRotation( 1 ); | |
//======INITIAL CHECK RED Button PUSHED CAUTION ?=========== | |
if(digitalRead(36)==0) | |
{ | |
M5.Lcd.setTextSize(2); | |
M5.Lcd.setTextColor(RED); | |
M5.Lcd.println("PUSH RED Butn"); | |
while(digitalRead(36)==0) | |
{ | |
M5.update(); | |
} | |
}// RED Button Released Caution END | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.setTextColor(YELLOW); | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
m=0; | |
//M5.Lcd.println("RedBtn Release then GPS-GGA Mode start"); | |
delay(1000); | |
Serial.println("Serial1,2 Reset to 115200bps"); | |
Serial2.begin(115200,SERIAL_8N1,0,26);//To LEFT_F9P EXT RX0 TX26*******(baudrate,config,RX,TX) | |
Serial1.begin(115200,SERIAL_8N1,32,33);//To RIGHT_F9P Grove RX32 TX33*******(baudrate,config,RX,TX) | |
//WiFi conencting---------------------------- | |
Serial.print("Connecting to "); | |
// M5.Lcd.print("Connecting to "); | |
Serial.println("Requesting SourceTable."); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
//M5.Lcd.print("."); | |
} | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
Serial.print(ssid); | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.print("WiFI:OK_"); | |
//--------------------------------------------------- | |
//*****************************From SPIFFS GGA read GGA.txt ************************************************ | |
Serial.println("----GGAc read Start--------------"); | |
if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){ | |
Serial.println("SPIFFS Mount Failed"); | |
M5.Lcd.setTextSize(2); | |
M5.Lcd.print("GGA.txt Error"); | |
return; | |
} | |
int endFlag=0; | |
File file = SPIFFS.open(file_name); | |
if(!file || file.isDirectory()){ | |
Serial.println("- failed to o pen file for reading"); | |
} | |
else{ | |
Serial.println("- read from file:"); | |
//Add GGA terminator \r\n | |
while(file.available() && endFlag==0 ){ | |
char c=file.read(); | |
if(c=='*') //CheckSum Search | |
{ | |
Serial.println("***Add \r\n Exit***"); | |
GGAc[i]=c;//Add '*' | |
GGAc[i+1]= file.read(); | |
Serial.print(i+1); | |
Serial.print(":"); | |
Serial.println(GGAc[i+1]); | |
GGAc[i+2]=file.read(); | |
Serial.print(i+2); | |
Serial.print(":"); | |
Serial.println(GGAc[i+2]); | |
GGAc[i+3]='\r'; | |
GGAc[i+4]='\n'; | |
Serial.println("******"); | |
endFlag=1; | |
} | |
else | |
{ | |
GGAc[i]=c; | |
Serial.print(i); | |
Serial.print(":"); | |
Serial.println(GGAc[i]); | |
} | |
i++; | |
} | |
Serial.print("GGAc size="); | |
Serial.println(sizeof(GGAc)); | |
Serial.print("**********Check GGAc Array************"); | |
for (i=0;i<83;i++) | |
{ | |
Serial.print(i); | |
Serial.print(":"); | |
Serial.println(GGAc[i]); | |
} | |
Serial.println("---------GGAc read Finished from SPIFFS GGA.txt------------------"); | |
file.close();//GGA.txt close | |
} | |
//*********************************************GGA Reading Finished********************************************************* | |
delay(10); | |
if(ntrip_c.reqSrcTbl(host,httpPort)){ | |
char buffer[512]; | |
delay(5); | |
while(ntrip_c.available()){ | |
ntrip_c.readLine(buffer,sizeof(buffer)); | |
Serial.print(buffer); | |
// M5.Lcd.print(buffer); | |
} | |
} | |
else{ | |
Serial.println("SourceTable request error"); | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.print("Ntrip Err"); | |
} | |
Serial.print("Requesting SourceTable is OK\n"); | |
ntrip_c.stop(); //Need to call "stop" function for next request. | |
Serial.println("Requesting MountPoint's Raw data"); | |
// M5.Lcd.print("R"); | |
//===================================NTRIP CASTER Call====================================================== | |
char ggac[]={"$GNGGA,124733.13,3612.27759,N,13756.95161,E,4,12,0.80,608.5,M,36.7,M,0.1,0000*6C\r\n"};//Matsumoto Sample | |
//Serial.print(ggac); | |
//Serial.print("ggac size="); | |
//Serial.println(sizeof(ggac)); | |
//ggac=Const char data ,GGAc=SPIFFS GGA.txt data must be last \n\r | |
if(!ntrip_c.reqRaw(host,httpPort,mntpnt,user,passwd,GGAc)){ | |
delay(10000); | |
ESP.restart(); | |
} | |
//======================================================================================================= | |
/* | |
//===================Ntrip Caster======================================================= | |
if(!ntrip_c.reqRaw(host,httpPort,mntpnt,user,passwd)){ | |
delay(15000); | |
ESP.restart(); | |
} | |
//==================================================================================== | |
*/ | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.print("Ntrip:OK\n"); | |
M5.Lcd.setTextSize(2); | |
M5.Lcd.printf("%s\n",mntpnt); | |
Serial.print("Requesting MountPoint is OK="); | |
Serial.println(mntpnt); | |
//M5.Lcd.print("Requesting MountPoint's Raw data"); | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.print("RTCM:OK_"); | |
M5.Lcd.print("["); | |
// listDir(SPIFFS, "/", 0); | |
/* | |
writeFile(SPIFFS, "/hello.txt", "Hello "); | |
appendFile(SPIFFS, "/hello.txt", "World!\r\n"); | |
readFile(SPIFFS, "/hello.txt"); | |
renameFile(SPIFFS, "/hello.txt", "/foo.txt"); | |
readFile(SPIFFS, "/foo.txt"); | |
deleteFile(SPIFFS, "/foo.txt"); | |
testFileIO(SPIFFS, "/test.txt"); | |
deleteFile(SPIFFS, "/test.txt"); | |
*/ | |
Serial.println( "Test complete" ); | |
}// SetUp end======================================================================== | |
//*********************************************************************************** | |
//*****************************LOOP*************************************************** | |
void loop() { | |
// put your main code here, to run repeatedly: | |
keyin(); | |
gps_gga(); | |
while(ntrip_c.available()) { | |
n++; | |
char ch = ntrip_c.read(); | |
Serial1.print(ch); | |
Serial2.print(ch); | |
Serial.print(ch,HEX); | |
//Serial.print(","); | |
//Lcd Header Disp | |
if (n<6 && n>2){ | |
M5.Lcd.print("-"); | |
M5.Lcd.print(ch,HEX); | |
} | |
if(n==8){ | |
M5.Lcd.println("]"); | |
M5.Lcd.println("RedBtn Release then GPS-GGA Mode start"); | |
} | |
} | |
//GGA GET from Serial to SPIFFS | |
}//loop end************************************************************************************** | |
//********************************************************************************************** | |
//key in for SPIFFS FileSystem=============================================== | |
char keyin()// | |
{ | |
char key; | |
if( Serial.available()){ | |
WiFi.disconnect();// NTRIP RCV STOP | |
key =Serial.read(); | |
// test ----------------------------------------- | |
if(key=='t') | |
{ | |
Serial.println("TotalTEST going"); | |
listDir(SPIFFS, "/", 0); | |
writeFile(SPIFFS, "/hello.txt", "Hello "); | |
appendFile(SPIFFS, "/hello.txt", "World!\r\n"); | |
readFile(SPIFFS, "/hello.txt"); | |
renameFile(SPIFFS, "/hello.txt", "/foo.txt"); | |
readFile(SPIFFS, "/foo.txt"); | |
//deleteFile(SPIFFS, "/foo.txt"); | |
testFileIO(SPIFFS, "/test.txt"); | |
//deleteFile(SPIFFS, "/test.txt"); | |
Serial.println( "Test complete" ); | |
} | |
//DeleteFile----------------------------------------------------- | |
if(key=='D')//D Key Pushed | |
{ | |
int dk; //File No 0-9999 | |
int dflag=0; | |
listDir(SPIFFS, "/", 0); | |
Serial.print("Input Delete File No="); | |
String dsN="";//d selectNo | |
char dC;//Input key char | |
char dN[4]={};//4keta No 0-9999 Char Array | |
dk=0; | |
while(dC!= '\r'){ | |
if(Serial.available()) | |
{ | |
dC=Serial.read(); | |
Serial.print(dC); | |
dN[dk]=dC; | |
dk++; | |
} | |
} | |
dsN=String(dN);//FileNo CharArray to String dsN | |
Serial.print(dsN);//FileNo Diplay | |
int deN=dsN.toInt();//FileNo String dsN to Integer | |
Serial.printf("deN=%d\n\r",deN); | |
String dstr=Listname[deN];//FileName [FileNo deN] to dstr | |
int dslen=dstr.length()+1;//Filename Length | |
char buf[dslen];//Filename CharArry buf | |
dstr.toCharArray(buf,dslen);//buf charArry Filename | |
Serial.printf("DeleteFilename=%s=%S,dslen=%d\n\r",dstr,Listname[deN],dslen); | |
deleteFile(SPIFFS, buf); | |
} | |
//List File------------------------------------------------------ | |
if (key=='L'){ | |
listDir(SPIFFS, "/", 0); | |
} | |
//Append FIle--------------------------------------------------- | |
if(key=='A'){ | |
int j=0; | |
String dataStr; | |
char char_array[]={}; | |
for (j=0;j<10;j++) | |
{ | |
dataStr=String(millis())+","; | |
str2char(char_array,dataStr); | |
appendFile(SPIFFS, "/hello.txt",char_array); | |
Serial.printf("Appending %j\n\r",j); | |
//appendFile(SPIFFS, "/hello.txt",String(millis())+"\r\n"); | |
} | |
} | |
//Read File------------------------------------------------------ | |
if(key=='R'){ | |
int rflag=0; | |
listDir(SPIFFS, "/", 0); | |
Serial.print("Input Read File No="); | |
String sN=""; | |
char bC; | |
bC='a'; | |
char cN[4]; | |
k=0; | |
while(bC!= '\r'){ | |
if(Serial.available()) | |
{ | |
bC=Serial.read(); | |
Serial.print(bC); | |
cN[k]=bC; | |
k++; | |
} | |
} | |
sN=String(cN); | |
Serial.print(sN); | |
int aN=sN.toInt(); | |
String str=Listname[aN]; | |
//Serial.print("str="); | |
//Serial.print(str); | |
int slen=str.length()+1; | |
Serial.print("ReadFilename="); | |
Serial.print(str); | |
Serial.print("/slen="); | |
Serial.print(slen); | |
char buf[slen]; | |
str.toCharArray(buf,slen); | |
readFile(SPIFFS, buf); | |
//readFile(SPIFFS, "/hello.txt"); | |
} | |
//Write FileName messages------------------------------------- | |
if(key=='W'){ | |
//key in FileName----------------------------- | |
listDir(SPIFFS, "/", 0); | |
Serial.print("Listed=>GGA.TXT KeyInput="); | |
char inputC; | |
/* | |
while( inputC!= '.'){ | |
if(Serial.available()) | |
{ | |
j++; | |
inputC=Serial.read(); | |
fname[j] =inputC; | |
Serial.print(fname[j]); | |
} | |
}//while end | |
Serial.print("fname[0]="); | |
Serial.print(fname[0]); | |
Serial.print("fname[1]="); | |
Serial.print(fname[1]); | |
Serial.print("fname[2]="); | |
Serial.print(fname[2]); | |
Serial.print("fname[3]="); | |
Serial.print(fname[3]); | |
*/ | |
fname[0]='/'; | |
fname[1]='G'; | |
fname[2]='G'; | |
fname[3]='A'; | |
fname[4]='.'; | |
fname[5]='t'; | |
fname[6]='x'; | |
fname[7]='t'; | |
fname[8]=0x00; | |
//key in Message--------------------------------- | |
char mes[100]; | |
Serial.print("Please Input message="); | |
j=0; | |
while( inputC!= '\r'){ | |
if(Serial.available()) | |
{ | |
inputC=Serial.read(); | |
mes[j] =inputC; | |
Serial.print(mes[j]); | |
j++; | |
} | |
mes[j]=0x00; | |
}//while end | |
writeFile(SPIFFS, fname, mes); | |
}//key 'W' end | |
/* | |
//Upload WebServer ======================================================================= | |
if(key=='U'){ | |
int rflag=0; | |
listDir(SPIFFS, "/", 0); | |
Serial.print("Input Read File No="); | |
String sN=""; | |
char bC; | |
char cN[4]; | |
k=0; | |
bC='a'; | |
while(bC!= '\r'){ | |
if(Serial.available()) | |
{ | |
bC=Serial.read(); | |
Serial.print(bC); | |
cN[k]=bC; | |
k++; | |
} | |
} | |
sN=String(cN); | |
Serial.print(sN); | |
int aN=sN.toInt(); | |
String str=Listname[aN];//Selected FileName | |
int slen=str.length()+1; | |
Serial.print("ReadFilename="); | |
Serial.print(str); | |
Serial.print("/slen="); | |
Serial.print(slen); | |
char buf[slen]; | |
str.toCharArray(buf,slen); | |
Webserver_writeSPfile(SPIFFS,str); | |
//readFile(SPIFFS, buf); | |
//readFile(SPIFFS, "/hello.txt"); | |
} | |
*/// end U | |
Serial.println(); | |
Serial.println("===Please key IN===="); | |
Serial.println("W:writeFile,R:ReadFile,L:List,D:Delete U:WEB Upload ButnB_restart");//Append Not working | |
}// end Serial.available() | |
return key; | |
} | |
//SPIFFS UTILITIES========================================================= | |
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ | |
Serial.printf("Listing directory: %s\r\n", dirname); | |
File root = fs.open(dirname); | |
if(!root){ | |
Serial.println("- failed to open directory"); | |
return; | |
} | |
if(!root.isDirectory()){ | |
Serial.println(" - not a directory=>Fomatting"); | |
bool formatted = SPIFFS.format(); | |
return; | |
} | |
File file = root.openNextFile(); | |
int n=0; | |
while(file){ | |
if(file.isDirectory()){ | |
Serial.print(" DIR : "); | |
Serial.println(file.name()); | |
if(levels){ | |
listDir(fs, file.name(), levels -1); | |
} | |
} else { | |
n++; | |
Listname[n]=file.name(); | |
Serial.print("FILE No "); | |
Serial.print(n); | |
Serial.print("="); | |
Serial.print(Listname[n]); | |
Serial.print("\tSIZE: "); | |
Serial.println(file.size()); | |
} | |
file = root.openNextFile(); | |
} | |
} | |
void readFile(fs::FS &fs, const char * path){ | |
Serial.printf("Reading file: %s\r\n", path); | |
File file = fs.open(path); | |
if(!file || file.isDirectory()){ | |
Serial.println("- failed to open file for reading"); | |
return; | |
} | |
Serial.println("- read from file:"); | |
while(file.available()){ | |
Serial.write(file.read()); | |
} | |
file.close(); | |
} | |
void writeFile(fs::FS &fs, const char * path, const char * message){ | |
Serial.printf("Writing file: %s\r\n", path); | |
File file = fs.open(path, FILE_WRITE); | |
if(!file){ | |
Serial.println("- failed to open file for writing"); | |
return; | |
} | |
if(file.print(message)){ | |
Serial.println("- file written"); | |
} else { | |
Serial.println("- write failed"); | |
} | |
file.close(); | |
} | |
void appendFile(fs::FS &fs, const char * path, const char * message){ | |
//Serial.printf("Appending to file: %s\r\n", path); | |
File file = fs.open(path, FILE_APPEND); | |
if(!file){ | |
Serial.println("- failed to open file for appending"); | |
return; | |
} | |
if(file.print(message)){ | |
//Serial.println("- message appended"); | |
} else { | |
Serial.println("- append failed"); | |
} | |
file.close(); | |
} | |
void renameFile(fs::FS &fs, const char * path1, const char * path2){ | |
Serial.printf("Renaming file %s to %s\r\n", path1, path2); | |
if (fs.rename(path1, path2)) { | |
Serial.println("- file renamed"); | |
} else { | |
Serial.println("- rename failed"); | |
} | |
} | |
void deleteFile(fs::FS &fs, const char * path){ | |
Serial.printf("Deleting file: %s\r\n", path); | |
if(fs.remove(path)){ | |
Serial.println("- file deleted"); | |
} else { | |
Serial.println("- delete failed"); | |
} | |
} | |
void testFileIO(fs::FS &fs, const char * path){ | |
Serial.printf("Testing file I/O with %s\r\n", path); | |
static uint8_t buf[512]; | |
size_t len = 0; | |
File file = fs.open(path, FILE_WRITE); | |
if(!file){ | |
Serial.println("- failed to open file for writing"); | |
return; | |
} | |
size_t i; | |
Serial.print("- writing" ); | |
uint32_t start = millis(); | |
for(i=0; i<512; i++){ | |
if ((i & 0x001F) == 0x001F){ | |
Serial.print("."); | |
} | |
file.write(buf, 512); | |
} | |
Serial.println(""); | |
uint32_t end = millis() - start; | |
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end); | |
file.close(); | |
file = fs.open(path); | |
start = millis(); | |
end = start; | |
i = 0; | |
if(file && !file.isDirectory()){ | |
len = file.size(); | |
size_t flen = len; | |
start = millis(); | |
Serial.print("- reading" ); | |
while(len){ | |
size_t toRead = len; | |
if(toRead > 512){ | |
toRead = 512; | |
} | |
file.read(buf, toRead); | |
if ((i++ & 0x001F) == 0x001F){ | |
Serial.print("."); | |
} | |
len -= toRead; | |
} | |
Serial.println(""); | |
end = millis() - start; | |
Serial.printf("- %u bytes read in %u ms\r\n", flen, end); | |
file.close(); | |
} else { | |
Serial.println("- failed to open file for reading"); | |
} | |
} | |
void str2char(char c[],String dataS) | |
{ | |
//String dataS; | |
//dataS="HELLO dataS"; | |
int dataS_len=dataS.length()+1; | |
char char_array[dataS_len]; | |
dataS.toCharArray(c,dataS_len); | |
} | |
/* | |
//web server write | |
void Webserver_writeSPfile( fs::FS &fs,String fname) | |
{ | |
//file = SD.open(file_name, FILE_READ); | |
//file = SD.open(fname, FILE_READ); | |
//SPIFFS readfile | |
File file = fs.open(fname); | |
if(!file || file.isDirectory()){ | |
Serial.println("- failed to open file for reading"); | |
return; | |
} | |
// Serial.println("- read from file:"); | |
// while(file.available()){ | |
// Serial.write(file.read()); | |
// } | |
// file.close(); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(0, 0, 2); | |
M5.Lcd.print("FILE SIZE : "); | |
M5.Lcd.println(file.size()); | |
//char tmp_var[file.size()] = ""; | |
char tmp_var[var_size+1] = ""; | |
esp_http_client_config_t config = {0}; | |
config.url = "http://damp-goto-9456.punyu.jp/writefile.php";//"http://ml.maru-yo.net/writefile.php"; | |
config.method = HTTP_METHOD_POST; | |
esp_http_client_handle_t client = esp_http_client_init(&config); | |
esp_http_client_open(client, file.size()); | |
//----------------------------------------------- | |
Serial.printf("Start Upload time=%d\n\r",millis()); | |
while(file.available()) { | |
char c=file.read();//SPIFFS file read | |
//Serial.print(c); | |
sprintf(tmp_var, "%s%c", tmp_var, c); | |
if(strlen(tmp_var)>=var_size) { | |
esp_http_client_write(client, (const char *)tmp_var, strlen(tmp_var)); | |
sprintf(tmp_var, ""); | |
//M5.Lcd.print("*"); | |
} | |
} | |
esp_http_client_write(client, (const char *)tmp_var, strlen(tmp_var)); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(0, 0, 2); | |
M5.Lcd.println("FINISH"); | |
esp_http_client_close(client); | |
esp_http_client_cleanup(client); | |
file.close(); | |
Serial.printf("Upload Finished time=%d\n\r",millis()); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment