const char Input[] PROGMEM = "Zkušební text";
char *i = Input;
char CSVline[] = "subdomain1.domain.tld,211,username,Tsa5JrHYx0gmde,/path1/path2/ ,\n";
char CharArray[] = "Proměnná s textem";
const PROGMEM char BOM[] = {0xEF, 0xBB, 0xBF, 0x2A, 0x2B,};
// const char *p;
char * ptr;
void setup() {
Serial.begin(115200);
// char CSVline[] = "subdomain1.domain.tld,211,username,Tsa5JrHYx0gmde,/ \n";
uint8_t CSVlinelength;
size_t pFTPport;
size_t pFTPlogin;
size_t pFTPpassw;
size_t pFTPpath;
// const char *p;
uint16_t FTPport;
char * ptr;
bool Error = false;
uint8_t param;
uint8_t i;
CSVlinelength = strlen(CSVline);
size_t CurrPointer = 0;
for (param = 1; param <= 4; param++) {
CurrPointer = strcspn(CSVline + CurrPointer, " ,") + CurrPointer ;
if (CurrPointer > CSVlinelength) {
Serial.print("Parameter No. ");
Serial.print(param);
Serial.println(" not found.");
Error = true;
return;
}
Serial.print("Parameter No. ");
Serial.println(param);
CSVline[CurrPointer] = '\0';
CurrPointer++;
i = 0;
while (!(isalnum(CSVline[CurrPointer + i]) || CSVline[CurrPointer + i] == '/') && (CurrPointer + i) < CSVlinelength) i++;
CurrPointer += i;
switch (param) {
case 1:
Serial.print(F("FTP URL: "));
Serial.print(CSVline);
Serial.println(F("«"));
pFTPport = CurrPointer;
break;
case 2:
Serial.print(F("pFTPport position: "));
Serial.println(pFTPport);
pFTPlogin = CurrPointer;
FTPport = atoi(CSVline + pFTPport);
if (FTPport == 0) {
Serial.println("Conversion to number failed. ");
Error = true;
} else {
Serial.print("FTPport: ");
Serial.println(FTPport);
}
Serial.print("pFTPlogin position: ");
Serial.println(CurrPointer);
break;
case 3:
Serial.print("FTP login: ");
Serial.print(CSVline + pFTPlogin);
Serial.println(F("«"));
pFTPlogin += CSVline;
pFTPpassw = CurrPointer;
Serial.print("pFTPpassw position: ");
Serial.println(pFTPpassw);
break;
case 4:
Serial.print("FTP password: ");
Serial.print(CSVline + pFTPpassw);
Serial.println(F("«"));
pFTPpassw += CSVline;
pFTPpath = CurrPointer;
Serial.print("pFTPpath position: ");
Serial.println(pFTPpath);
}
}
pFTPport = strcspn(CSVline + pFTPpath, ", \n");
if (pFTPport > 0) {
CSVline[pFTPpath + pFTPport] = '\0';
Serial.print("FTP path: ");
Serial.print(CSVline + pFTPpath);
Serial.println(F("«"));
if (CSVline[pFTPpath] != '/') {
Serial.println(F("File path doesn't start with '/'."));
Error = true;
}
if (CSVline[pFTPpath + pFTPport - 1] != '/') {
Serial.println(F("File path doesn't end with '/'."));
Error = true;
}
pFTPpath += CSVline;
} else {
Serial.println("Parameter File path has zero length.");
Error = true;
}
delay(2000);
if (! Error) {
DisplayParameters(CSVline, FTPport, pFTPlogin, pFTPpassw, pFTPpath);
}
}
void loop() {
// delay(3000);
}
void DisplayParameters(char text1[], uint16_t port, char text3[], char text4[], char text5[]) {
Serial.println("\nFunction DisplayParameters with char arrays in declaration.");
Serial.println(text1);
Serial.println(port);
Serial.println(text3);
Serial.println(text4);
Serial.println(text5);
}