Digital Photo Frame using FTP Client
Dependencies: FTPClient SDFileSystem SeeedStudioTFTv2 TFT_fonts WIZnetInterface mbed
Overview
This program is smart Digital Photo Frame remotely controlled by FTP protocol.
Demo
<iframe src="https://player.vimeo.com/video/137345478" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="https://vimeo.com/137345478">Digital Photo Frame controlled remotely by using FTP protocol.</a> from <a href="https://vimeo.com/midnightcow">MidnightCow</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
For more detail
http://midnightcow.tistory.com/entry/Digital-Photo-Frame-controlled-remotely-by-using-FTP-protocol
main.cpp@1:72700c87f8d5, 2015-08-26 (annotated)
- Committer:
- MidnightCow
- Date:
- Wed Aug 26 13:43:34 2015 +0000
- Revision:
- 1:72700c87f8d5
- Parent:
- 0:583a42b8d940
Enhance Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MidnightCow | 0:583a42b8d940 | 1 | #include "mbed.h" |
MidnightCow | 0:583a42b8d940 | 2 | #include "EthernetInterface.h" |
MidnightCow | 0:583a42b8d940 | 3 | #include "SDFileSystem.h" |
MidnightCow | 0:583a42b8d940 | 4 | #include <stdio.h> |
MidnightCow | 0:583a42b8d940 | 5 | #include <string.h> |
MidnightCow | 0:583a42b8d940 | 6 | |
MidnightCow | 0:583a42b8d940 | 7 | #include "FTPClient.h" |
MidnightCow | 0:583a42b8d940 | 8 | #include "MySeeedStudioTFTv2.h" |
MidnightCow | 0:583a42b8d940 | 9 | #include "Arial12x12.h" |
MidnightCow | 0:583a42b8d940 | 10 | #include "Arial24x23.h" |
MidnightCow | 0:583a42b8d940 | 11 | #include "Arial28x28.h" |
MidnightCow | 0:583a42b8d940 | 12 | #include "font_big.h" |
MidnightCow | 0:583a42b8d940 | 13 | |
MidnightCow | 0:583a42b8d940 | 14 | #define PIN_XP A3 |
MidnightCow | 0:583a42b8d940 | 15 | #define PIN_XM A1 |
MidnightCow | 0:583a42b8d940 | 16 | #define PIN_YP A2 |
MidnightCow | 0:583a42b8d940 | 17 | #define PIN_YM A0 |
MidnightCow | 0:583a42b8d940 | 18 | #define PIN_MOSI D11 |
MidnightCow | 0:583a42b8d940 | 19 | #define PIN_MISO D12 |
MidnightCow | 0:583a42b8d940 | 20 | #define PIN_SCLK D13 |
MidnightCow | 0:583a42b8d940 | 21 | #define PIN_CS_TFT D5 |
MidnightCow | 0:583a42b8d940 | 22 | #define PIN_DC_TFT D6 |
MidnightCow | 0:583a42b8d940 | 23 | #define PIN_BL_TFT D7 |
MidnightCow | 0:583a42b8d940 | 24 | #define PIN_CS_SD D4 |
MidnightCow | 0:583a42b8d940 | 25 | |
MidnightCow | 0:583a42b8d940 | 26 | #define MAC "\x00\x08\xDC\x11\x34\x78" |
MidnightCow | 1:72700c87f8d5 | 27 | #define IP "192.168.1.100" |
MidnightCow | 0:583a42b8d940 | 28 | #define MASK "255.255.255.0" |
MidnightCow | 1:72700c87f8d5 | 29 | #define GATEWAY "192.168.1.1" |
MidnightCow | 0:583a42b8d940 | 30 | |
MidnightCow | 1:72700c87f8d5 | 31 | #define FTP_SERVER_IP "192.168.1.200" |
MidnightCow | 1:72700c87f8d5 | 32 | |
MidnightCow | 1:72700c87f8d5 | 33 | #define _MAX_FNAME_LEN_ 127 |
MidnightCow | 1:72700c87f8d5 | 34 | #define _FTP_UPDATE_TIME_ 20 |
MidnightCow | 1:72700c87f8d5 | 35 | |
MidnightCow | 0:583a42b8d940 | 36 | |
MidnightCow | 0:583a42b8d940 | 37 | Serial uart(USBTX, USBRX); |
MidnightCow | 0:583a42b8d940 | 38 | |
MidnightCow | 0:583a42b8d940 | 39 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD |
MidnightCow | 0:583a42b8d940 | 40 | //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD |
MidnightCow | 0:583a42b8d940 | 41 | //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F |
MidnightCow | 0:583a42b8d940 | 42 | //SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 |
MidnightCow | 0:583a42b8d940 | 43 | |
MidnightCow | 0:583a42b8d940 | 44 | EthernetInterface eth; |
MidnightCow | 0:583a42b8d940 | 45 | |
MidnightCow | 0:583a42b8d940 | 46 | DigitalOut led1(LED1); //server listning status |
MidnightCow | 0:583a42b8d940 | 47 | DigitalOut led2(LED2); //socket connecting status |
MidnightCow | 0:583a42b8d940 | 48 | |
MidnightCow | 0:583a42b8d940 | 49 | |
MidnightCow | 0:583a42b8d940 | 50 | MySeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD); |
MidnightCow | 0:583a42b8d940 | 51 | |
MidnightCow | 0:583a42b8d940 | 52 | |
MidnightCow | 0:583a42b8d940 | 53 | FTPClient myFTP("/sdc"); // mountname in MySeeedStudioTFTv2 |
MidnightCow | 0:583a42b8d940 | 54 | |
MidnightCow | 0:583a42b8d940 | 55 | Ticker ledTick; |
MidnightCow | 0:583a42b8d940 | 56 | |
MidnightCow | 1:72700c87f8d5 | 57 | uint32_t ftp_time_1s = 0; |
MidnightCow | 0:583a42b8d940 | 58 | |
MidnightCow | 0:583a42b8d940 | 59 | char myfilelist[MAX_SS] = {0,}; |
MidnightCow | 0:583a42b8d940 | 60 | |
MidnightCow | 0:583a42b8d940 | 61 | void ledTickfunc() |
MidnightCow | 0:583a42b8d940 | 62 | { |
MidnightCow | 0:583a42b8d940 | 63 | led1 = !led1; |
MidnightCow | 1:72700c87f8d5 | 64 | if(ftp_time_1s) |
MidnightCow | 1:72700c87f8d5 | 65 | { |
MidnightCow | 1:72700c87f8d5 | 66 | if(ftp_time_1s++ > _FTP_UPDATE_TIME_) ftp_time_1s = 0; |
MidnightCow | 1:72700c87f8d5 | 67 | } |
MidnightCow | 0:583a42b8d940 | 68 | } |
MidnightCow | 0:583a42b8d940 | 69 | |
MidnightCow | 0:583a42b8d940 | 70 | |
MidnightCow | 0:583a42b8d940 | 71 | int main (void) |
MidnightCow | 0:583a42b8d940 | 72 | { |
MidnightCow | 0:583a42b8d940 | 73 | int ret; |
MidnightCow | 0:583a42b8d940 | 74 | char* tok = NULL; |
MidnightCow | 0:583a42b8d940 | 75 | char* lasts = NULL; |
MidnightCow | 1:72700c87f8d5 | 76 | char filename[_MAX_FNAME_LEN_]; |
MidnightCow | 0:583a42b8d940 | 77 | FILE* fp; |
MidnightCow | 1:72700c87f8d5 | 78 | |
MidnightCow | 0:583a42b8d940 | 79 | // Serial Interface eth; |
MidnightCow | 0:583a42b8d940 | 80 | uart.baud(115200); |
MidnightCow | 0:583a42b8d940 | 81 | uart.printf("Initializing\n"); |
MidnightCow | 0:583a42b8d940 | 82 | |
MidnightCow | 0:583a42b8d940 | 83 | // EthernetInterface eth; |
MidnightCow | 0:583a42b8d940 | 84 | uart.printf("Initializing Ethernet\n"); |
MidnightCow | 1:72700c87f8d5 | 85 | |
MidnightCow | 0:583a42b8d940 | 86 | //eth.init(); //Use DHCP |
MidnightCow | 0:583a42b8d940 | 87 | eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway |
MidnightCow | 0:583a42b8d940 | 88 | uart.printf("Connecting\n"); |
MidnightCow | 0:583a42b8d940 | 89 | eth.connect(); |
MidnightCow | 0:583a42b8d940 | 90 | uart.printf("IP Address is %s\n", eth.getIPAddress()); |
MidnightCow | 0:583a42b8d940 | 91 | |
MidnightCow | 1:72700c87f8d5 | 92 | // Check File System |
MidnightCow | 1:72700c87f8d5 | 93 | uart.printf("Checking File System\n"); |
MidnightCow | 1:72700c87f8d5 | 94 | DIR *d = opendir("/sdc/"); |
MidnightCow | 1:72700c87f8d5 | 95 | if (d != NULL) { |
MidnightCow | 1:72700c87f8d5 | 96 | uart.printf("SD Card Present\n"); |
MidnightCow | 1:72700c87f8d5 | 97 | closedir(d); |
MidnightCow | 1:72700c87f8d5 | 98 | } else { |
MidnightCow | 1:72700c87f8d5 | 99 | uart.printf("SD Card Root Directory Not Found\n"); |
MidnightCow | 1:72700c87f8d5 | 100 | } |
MidnightCow | 0:583a42b8d940 | 101 | |
MidnightCow | 1:72700c87f8d5 | 102 | ledTick.attach(&ledTickfunc,1); |
MidnightCow | 0:583a42b8d940 | 103 | |
MidnightCow | 1:72700c87f8d5 | 104 | while(1) |
MidnightCow | 0:583a42b8d940 | 105 | { |
MidnightCow | 1:72700c87f8d5 | 106 | if(ftp_time_1s == 0) |
MidnightCow | 0:583a42b8d940 | 107 | { |
MidnightCow | 1:72700c87f8d5 | 108 | //Configure the display driver |
MidnightCow | 1:72700c87f8d5 | 109 | ftp_time_1s = 1; |
MidnightCow | 1:72700c87f8d5 | 110 | TFT.background(Black); |
MidnightCow | 1:72700c87f8d5 | 111 | TFT.foreground(White); |
MidnightCow | 1:72700c87f8d5 | 112 | TFT.set_font((unsigned char*) Arial12x12); |
MidnightCow | 1:72700c87f8d5 | 113 | TFT.cls(); |
MidnightCow | 1:72700c87f8d5 | 114 | |
MidnightCow | 1:72700c87f8d5 | 115 | TFT.locate(0,0); |
MidnightCow | 1:72700c87f8d5 | 116 | TFT.printf(" UPDATING PHOTO\n"); |
MidnightCow | 1:72700c87f8d5 | 117 | TFT.printf("==================\n\n"); |
MidnightCow | 1:72700c87f8d5 | 118 | |
MidnightCow | 1:72700c87f8d5 | 119 | if(myFTP.open("192.168.77.210", 21, "user", "pass")) |
MidnightCow | 0:583a42b8d940 | 120 | { |
MidnightCow | 1:72700c87f8d5 | 121 | printf("Connect Success to FTPServer\r\n"); |
MidnightCow | 1:72700c87f8d5 | 122 | TFT.printf("Connected to FTP Server\n"); |
MidnightCow | 1:72700c87f8d5 | 123 | |
MidnightCow | 1:72700c87f8d5 | 124 | myFTP.ls(myfilelist); |
MidnightCow | 1:72700c87f8d5 | 125 | |
MidnightCow | 1:72700c87f8d5 | 126 | if(*myfilelist !=0) |
MidnightCow | 0:583a42b8d940 | 127 | { |
MidnightCow | 1:72700c87f8d5 | 128 | tok = myfilelist; |
MidnightCow | 1:72700c87f8d5 | 129 | while(tok) |
MidnightCow | 1:72700c87f8d5 | 130 | { |
MidnightCow | 1:72700c87f8d5 | 131 | tok = strtok_r(tok,"\r\n",&lasts); |
MidnightCow | 1:72700c87f8d5 | 132 | if(tok != NULL) |
MidnightCow | 1:72700c87f8d5 | 133 | { |
MidnightCow | 1:72700c87f8d5 | 134 | printf("tok=%s\r\n",tok); |
MidnightCow | 1:72700c87f8d5 | 135 | if(strstr(tok,"bmp")) |
MidnightCow | 1:72700c87f8d5 | 136 | { |
MidnightCow | 1:72700c87f8d5 | 137 | sprintf(filename,"/sdc/%s",tok); |
MidnightCow | 1:72700c87f8d5 | 138 | fp = fopen(filename, "r"); |
MidnightCow | 1:72700c87f8d5 | 139 | printf("fp=%d\r\n",fp); |
MidnightCow | 1:72700c87f8d5 | 140 | if(fp==NULL) |
MidnightCow | 1:72700c87f8d5 | 141 | { |
MidnightCow | 1:72700c87f8d5 | 142 | myFTP.getfile(tok); |
MidnightCow | 1:72700c87f8d5 | 143 | printf("Get File : %s\r\n",tok); |
MidnightCow | 1:72700c87f8d5 | 144 | TFT.printf(" New file : %s\n", tok); |
MidnightCow | 1:72700c87f8d5 | 145 | } |
MidnightCow | 1:72700c87f8d5 | 146 | else fclose(fp); |
MidnightCow | 1:72700c87f8d5 | 147 | } |
MidnightCow | 1:72700c87f8d5 | 148 | tok = lasts; |
MidnightCow | 1:72700c87f8d5 | 149 | } |
MidnightCow | 1:72700c87f8d5 | 150 | } |
MidnightCow | 1:72700c87f8d5 | 151 | } |
MidnightCow | 1:72700c87f8d5 | 152 | else TFT.printf(" Empty FTP Server\n"); |
MidnightCow | 1:72700c87f8d5 | 153 | TFT.printf("\n UPDATE DONE\n"); |
MidnightCow | 1:72700c87f8d5 | 154 | myFTP.quit(); |
MidnightCow | 1:72700c87f8d5 | 155 | } |
MidnightCow | 1:72700c87f8d5 | 156 | else |
MidnightCow | 1:72700c87f8d5 | 157 | { |
MidnightCow | 1:72700c87f8d5 | 158 | TFT.printf(" Can't connect to FTP Server\n\n"); |
MidnightCow | 1:72700c87f8d5 | 159 | TFT.printf(" UPDATE FAIL\n"); |
MidnightCow | 1:72700c87f8d5 | 160 | } |
MidnightCow | 1:72700c87f8d5 | 161 | TFT.printf("==================\n"); |
MidnightCow | 1:72700c87f8d5 | 162 | } |
MidnightCow | 1:72700c87f8d5 | 163 | |
MidnightCow | 1:72700c87f8d5 | 164 | d = opendir("/sdc/"); |
MidnightCow | 1:72700c87f8d5 | 165 | if(d != NULL) |
MidnightCow | 1:72700c87f8d5 | 166 | { |
MidnightCow | 1:72700c87f8d5 | 167 | struct dirent *p; |
MidnightCow | 1:72700c87f8d5 | 168 | while((p = readdir(d)) != NULL) |
MidnightCow | 1:72700c87f8d5 | 169 | { |
MidnightCow | 1:72700c87f8d5 | 170 | sprintf(filename, "/sdc/%s", p->d_name); |
MidnightCow | 1:72700c87f8d5 | 171 | uart.printf("%s\n", filename); |
MidnightCow | 1:72700c87f8d5 | 172 | DIR *subDir = opendir(filename); |
MidnightCow | 1:72700c87f8d5 | 173 | if (subDir != NULL) uart.printf("Skip a sub-directory\r\n"); |
MidnightCow | 1:72700c87f8d5 | 174 | else |
MidnightCow | 1:72700c87f8d5 | 175 | { |
MidnightCow | 0:583a42b8d940 | 176 | fp = fopen(filename, "r"); |
MidnightCow | 1:72700c87f8d5 | 177 | if(fp) |
MidnightCow | 0:583a42b8d940 | 178 | { |
MidnightCow | 1:72700c87f8d5 | 179 | TFT.DrawBitmapFile(fp); |
MidnightCow | 1:72700c87f8d5 | 180 | TFT.locate(1,1); |
MidnightCow | 1:72700c87f8d5 | 181 | TFT.printf("%s", filename); |
MidnightCow | 1:72700c87f8d5 | 182 | fclose(fp); |
MidnightCow | 0:583a42b8d940 | 183 | } |
MidnightCow | 1:72700c87f8d5 | 184 | else uart.printf("Can't open file %s\r\n", filename); |
MidnightCow | 0:583a42b8d940 | 185 | } |
MidnightCow | 0:583a42b8d940 | 186 | } |
MidnightCow | 1:72700c87f8d5 | 187 | } |
MidnightCow | 1:72700c87f8d5 | 188 | else |
MidnightCow | 1:72700c87f8d5 | 189 | { |
MidnightCow | 1:72700c87f8d5 | 190 | TFT.cls(); |
MidnightCow | 1:72700c87f8d5 | 191 | TFT.locate(0,0); |
MidnightCow | 1:72700c87f8d5 | 192 | TFT.printf(" No SD Card !!!\n"); |
MidnightCow | 1:72700c87f8d5 | 193 | TFT.printf(" Insert a SD card\n"); |
MidnightCow | 0:583a42b8d940 | 194 | } |
MidnightCow | 0:583a42b8d940 | 195 | } |
MidnightCow | 1:72700c87f8d5 | 196 | |
MidnightCow | 0:583a42b8d940 | 197 | } |