ESP8266 FTP 서버에서 파일을 전송을 하던지 PC에서 FTP 서버로 전송을 하면

ESP8266 의 디렉토리가 몇개씩 사라지는 현상이 있어서 원인을 한참 찾다가 고쳐졌습니다.

정확한 원인은 잘 모르겠고, SD Card 에서 디렉토리를 읽어서 보여줄 때,
함수를 1개(rewindDirectory) 더 추가해야 이 현상이 없어졌습니다.

어쩌면 SPIFFS 메모리에서는 이런 현상이 안나타날 지도 모르겠습니다.
제가 SPIFFS 메모리로 된 FTP 서버 프로그램을 SD 카드용으로 바꿔서 여러가지 오동작이 많이 발생하는 것 같습니다.

FTP 서버에서 디렉토리를 새로고치는 명령이 "MLSD" 이므로 
ESP8266FtpServer.ccp 의 processCommand 함수에서 "MLSD" 명령을 처리하는 부분을 수정하면 됩니다.
수정한 코드는 다음과 같습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  //
  //  MLSD - Listing for Machine Processing (see RFC 3659)
  //
  else if! strcmp( command, "MLSD" ))
  {
    if! dataConnect())
      client.println( "425 No data connection MLSD");
    else
    {
      client.println( "150 Accepted data connection");
      uint16_t nm = 0;
 
      File dir=SD.open(cwdName);
      File entry;
 
      dir.rewindDirectory();
          
      char dtStr[ 15 ];
 
        while(1)
        {
            entry =  dir.openNextFile();
            if (!entry)
                break;
            String fn,fs;
            fn = entry.name();
            fs = String(entry.size());
              data.println( "Type=file;Size=" + fs + ";"+"modify=20000101160656;" +" " + fn);
              nm ++;
        }
        client.println( "226-options: -a -l");
        client.println( "226 " + String(nm) + " matches total");
      }
      data.stop();
      entry.close();
  }
cs

SD.open() 함수 다음에 rewindDirectory(); 함수를 사용하면 됩니다.


다음의 링크로 가면 아두이노 IDE 툴에서 사용하는 일반적인 함수와 문법에 관한 내용들이 있다.

사용한지 얼마 안되서, 좀 생소하군요,. ^^


ESP8266 에서 EEPROM 은 실제로는 없고 외부에 있는 SPIFF 플래쉬 메모리의 일부를 사용하는 것이다.


EEPROM 을 다루는 함수들은 Library 에 있는 EEPROM.cpp 에 정의되어 있다.
라이브러리 소스의 위치는 다음과 같다.
C:\Users\trion\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\EEPROM

함수들의 종류는 다음과 같다.
1. void EEPROMClass::begin(size_t size)
   : 예를 들어 아두이노 스케치 코드에서 begin.EEPROM(512); 라고 코딩을 하면, EEPROM 을 512바이트 할당하고,
     EEPROM 관련 항목들을 초기화한다.
2. uint8_t EEPROMClass::read(int address)
   : 위에서 예를 든 begin 함수와 같이 설명하자면, 어드레스 0~511 까지 512개의 바이트 데이터를 해당 주소에서 읽어 올 수 있다.
3. void EEPROMClass::write(int address, uint8_t value)
   : 해당 주소(address)에 값을 쓴다. 이 때, 실제로 EEPROM에 물리적으로 기록되는 것이 아니고,
     램으로 된 버퍼값을 바꾸는 것이다.
4. bool EEPROMClass::commit()
   : 실제로 물리적으로 EEPROM(외부 플래쉬 메모리)에 값을 기록해서 리셋이나 전원이 꺼져도 값을 유지할 수 있다.

다음은 아두이노 IDE 툴에서 EEPROM 을 테스트한 코드 입니다.
: NODE MCU V3.0 보드의 Flash 버튼을 누르면 EEPROM 의 0번 어드레스의 값의 0번 비트가 토글 되면서,
  값을 기록하고 소프트웨어 리셋을 이용하여 리셋을 한 후,
  EEPROM의 0번 어드레스의 값이 바뀌어 있는지 EEPROM을 읽어서 시리얼 포트에 출력해 본 테스트입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <EEPROM.h>
 
const int buttonPin = 0;     // the number of the pushbutton pin
int buttonState = 0,buttonState_old=0;         // variable for reading the pushbutton status
byte value;
 
void setup() {
  // put your setup code here, to run once:
  delay(1000);
  Serial.begin(115200);
  EEPROM.begin(512);
  pinMode(buttonPin, INPUT);
  value = EEPROM.read(0);
  Serial.println("");
  Serial.print("EEPROM value = ");
  Serial.println(value,HEX);
 
  buttonState_old = buttonState = digitalRead(buttonPin);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  buttonState_old = buttonState;
  buttonState = digitalRead(buttonPin);
  if (buttonState_old != buttonState)
  {
    if (buttonState == LOW) 
    {
      value = EEPROM.read(0);
      value ^= 1;
      EEPROM.write(0, value);
      EEPROM.commit(); 
      Serial.print("Button Pressed !, EEPROM value = ");
      Serial.println(value,HEX);
      Serial.println("ESP8266 Software Reset");
      ESP.reset();
    }
  }
 
}
cs


다음은 위의 ESP8266 아두이노 IDE 스케치 코드에의해 디버그용으로 시리얼에 표시한 내용 입니다.





+ Recent posts