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.

/media/uploads/MidnightCow/dpf_logo.jpg


Demo

https://vimeo.com/137345478

<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

Committer:
MidnightCow
Date:
Sat Aug 15 08:45:28 2015 +0000
Revision:
0:583a42b8d940
Child:
1:72700c87f8d5
Just Test version

Who changed what in which revision?

UserRevisionLine numberNew 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 0:583a42b8d940 27 #define IP "192.168.77.100"
MidnightCow 0:583a42b8d940 28 #define MASK "255.255.255.0"
MidnightCow 0:583a42b8d940 29 #define GATEWAY "192.168.77.1"
MidnightCow 0:583a42b8d940 30
MidnightCow 0:583a42b8d940 31 #define HTTPD_SERVER_PORT 80
MidnightCow 0:583a42b8d940 32 #define HTTPD_MAX_REQ_LENGTH 1023
MidnightCow 0:583a42b8d940 33 #define HTTPD_MAX_HDR_LENGTH 255
MidnightCow 0:583a42b8d940 34 #define HTTPD_MAX_FNAME_LENGTH 127
MidnightCow 0:583a42b8d940 35 #define HTTPD_MAX_DNAME_LENGTH 127
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 /*
MidnightCow 0:583a42b8d940 47 char buffer[HTTPD_MAX_REQ_LENGTH+1];
MidnightCow 0:583a42b8d940 48 char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
MidnightCow 0:583a42b8d940 49 char fileName[HTTPD_MAX_FNAME_LENGTH+1];
MidnightCow 0:583a42b8d940 50 char dirName[HTTPD_MAX_DNAME_LENGTH+1];
MidnightCow 0:583a42b8d940 51 char *uristr;
MidnightCow 0:583a42b8d940 52 char *eou;
MidnightCow 0:583a42b8d940 53 char *qrystr;
MidnightCow 0:583a42b8d940 54
MidnightCow 0:583a42b8d940 55 FILE *fp;
MidnightCow 0:583a42b8d940 56 int rdCnt;
MidnightCow 0:583a42b8d940 57 */
MidnightCow 0:583a42b8d940 58
MidnightCow 0:583a42b8d940 59 DigitalOut led1(LED1); //server listning status
MidnightCow 0:583a42b8d940 60 DigitalOut led2(LED2); //socket connecting status
MidnightCow 0:583a42b8d940 61
MidnightCow 0:583a42b8d940 62
MidnightCow 0:583a42b8d940 63
MidnightCow 0:583a42b8d940 64 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 65
MidnightCow 0:583a42b8d940 66
MidnightCow 0:583a42b8d940 67 FTPClient myFTP("/sdc"); // mountname in MySeeedStudioTFTv2
MidnightCow 0:583a42b8d940 68
MidnightCow 0:583a42b8d940 69 Ticker ledTick;
MidnightCow 0:583a42b8d940 70
MidnightCow 0:583a42b8d940 71
MidnightCow 0:583a42b8d940 72 char myfilelist[MAX_SS] = {0,};
MidnightCow 0:583a42b8d940 73
MidnightCow 0:583a42b8d940 74 void ledTickfunc()
MidnightCow 0:583a42b8d940 75 {
MidnightCow 0:583a42b8d940 76 led1 = !led1;
MidnightCow 0:583a42b8d940 77 }
MidnightCow 0:583a42b8d940 78
MidnightCow 0:583a42b8d940 79
MidnightCow 0:583a42b8d940 80 int main (void)
MidnightCow 0:583a42b8d940 81 {
MidnightCow 0:583a42b8d940 82 int ret;
MidnightCow 0:583a42b8d940 83 char* tok = NULL;
MidnightCow 0:583a42b8d940 84 char* lasts = NULL;
MidnightCow 0:583a42b8d940 85 char filename[20];
MidnightCow 0:583a42b8d940 86 FILE* fp;
MidnightCow 0:583a42b8d940 87
MidnightCow 0:583a42b8d940 88
MidnightCow 0:583a42b8d940 89 ledTick.attach(&ledTickfunc,0.5);
MidnightCow 0:583a42b8d940 90
MidnightCow 0:583a42b8d940 91 // Serial Interface eth;
MidnightCow 0:583a42b8d940 92 uart.baud(115200);
MidnightCow 0:583a42b8d940 93 uart.printf("Initializing\n");
MidnightCow 0:583a42b8d940 94
MidnightCow 0:583a42b8d940 95 // Check File System
MidnightCow 0:583a42b8d940 96 uart.printf("Checking File System\n");
MidnightCow 0:583a42b8d940 97 DIR *d = opendir("/sdc/");
MidnightCow 0:583a42b8d940 98 if (d != NULL) {
MidnightCow 0:583a42b8d940 99 uart.printf("SD Card Present\n");
MidnightCow 0:583a42b8d940 100 } else {
MidnightCow 0:583a42b8d940 101 uart.printf("SD Card Root Directory Not Found\n");
MidnightCow 0:583a42b8d940 102 }
MidnightCow 0:583a42b8d940 103
MidnightCow 0:583a42b8d940 104 // EthernetInterface eth;
MidnightCow 0:583a42b8d940 105 uart.printf("Initializing Ethernet\n");
MidnightCow 0:583a42b8d940 106 //eth.init(); //Use DHCP
MidnightCow 0:583a42b8d940 107 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
MidnightCow 0:583a42b8d940 108 uart.printf("Connecting\n");
MidnightCow 0:583a42b8d940 109 eth.connect();
MidnightCow 0:583a42b8d940 110 uart.printf("IP Address is %s\n", eth.getIPAddress());
MidnightCow 0:583a42b8d940 111
MidnightCow 0:583a42b8d940 112 //Configure the display driver
MidnightCow 0:583a42b8d940 113 TFT.background(Black);
MidnightCow 0:583a42b8d940 114 TFT.foreground(White);
MidnightCow 0:583a42b8d940 115 TFT.set_font((unsigned char*) Arial12x12);
MidnightCow 0:583a42b8d940 116 TFT.cls();
MidnightCow 0:583a42b8d940 117
MidnightCow 0:583a42b8d940 118
MidnightCow 0:583a42b8d940 119 if(myFTP.open("192.168.77.210", 21, "user", "pass"))
MidnightCow 0:583a42b8d940 120 {
MidnightCow 0:583a42b8d940 121 printf("Connect Success to FTPServer\r\n");
MidnightCow 0:583a42b8d940 122 }
MidnightCow 0:583a42b8d940 123 myFTP.ls(myfilelist);
MidnightCow 0:583a42b8d940 124
MidnightCow 0:583a42b8d940 125
MidnightCow 0:583a42b8d940 126 if(*myfilelist !=0)
MidnightCow 0:583a42b8d940 127 {
MidnightCow 0:583a42b8d940 128 tok = myfilelist;
MidnightCow 0:583a42b8d940 129 while(tok)
MidnightCow 0:583a42b8d940 130 {
MidnightCow 0:583a42b8d940 131 tok = strtok_r(tok,"\r\n",&lasts);
MidnightCow 0:583a42b8d940 132 if(tok != NULL)
MidnightCow 0:583a42b8d940 133 {
MidnightCow 0:583a42b8d940 134 printf("tok=%s\r\n",tok);
MidnightCow 0:583a42b8d940 135 if(strstr(tok,"bmp"))
MidnightCow 0:583a42b8d940 136 {
MidnightCow 0:583a42b8d940 137 sprintf(filename,"/sdc/%s",tok);
MidnightCow 0:583a42b8d940 138 fp = fopen(filename, "r");
MidnightCow 0:583a42b8d940 139 printf("fp=%d\r\n",fp);
MidnightCow 0:583a42b8d940 140 if(fp==NULL)
MidnightCow 0:583a42b8d940 141 {
MidnightCow 0:583a42b8d940 142 myFTP.getfile(tok);
MidnightCow 0:583a42b8d940 143 printf("Get File : %s\r\n",tok);
MidnightCow 0:583a42b8d940 144 }
MidnightCow 0:583a42b8d940 145 else fclose(fp);
MidnightCow 0:583a42b8d940 146 }
MidnightCow 0:583a42b8d940 147 tok = lasts;
MidnightCow 0:583a42b8d940 148 }
MidnightCow 0:583a42b8d940 149
MidnightCow 0:583a42b8d940 150 }
MidnightCow 0:583a42b8d940 151 }
MidnightCow 0:583a42b8d940 152 myFTP.quit();
MidnightCow 0:583a42b8d940 153
MidnightCow 0:583a42b8d940 154 /*
MidnightCow 0:583a42b8d940 155 struct dirent *p;
MidnightCow 0:583a42b8d940 156 while((p = readdir(d)) != NULL) {
MidnightCow 0:583a42b8d940 157 sprintf(dirName, "%s/%s", fileName, p->d_name);
MidnightCow 0:583a42b8d940 158 uart.printf("%s\n", dirName);
MidnightCow 0:583a42b8d940 159 DIR *subDir = opendir(dirName);
MidnightCow 0:583a42b8d940 160 if (subDir != NULL) {
MidnightCow 0:583a42b8d940 161 sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name);
MidnightCow 0:583a42b8d940 162 } else {
MidnightCow 0:583a42b8d940 163 sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name);
MidnightCow 0:583a42b8d940 164 }
MidnightCow 0:583a42b8d940 165 client.send(httpHeader,strlen(httpHeader));
MidnightCow 0:583a42b8d940 166 }
MidnightCow 0:583a42b8d940 167 */
MidnightCow 0:583a42b8d940 168
MidnightCow 0:583a42b8d940 169 for(int i=0; i < 4; i++)
MidnightCow 0:583a42b8d940 170 {
MidnightCow 0:583a42b8d940 171 TFT.set_orientation(i);
MidnightCow 0:583a42b8d940 172 fp = fopen("/sdc/island.bmp", "r");
MidnightCow 0:583a42b8d940 173 if((ret = TFT.DrawBitmapFile(fp)) < 0)
MidnightCow 0:583a42b8d940 174 {
MidnightCow 0:583a42b8d940 175 printf("error : %d\r\n",ret);
MidnightCow 0:583a42b8d940 176 }
MidnightCow 0:583a42b8d940 177 fclose(fp);
MidnightCow 0:583a42b8d940 178 TFT.locate(120-6*strlen("islasn.bmp"),308);
MidnightCow 0:583a42b8d940 179 TFT.printf("red24.bmp");
MidnightCow 0:583a42b8d940 180 fp = fopen("/sdc/tiger24.bmp", "r");
MidnightCow 0:583a42b8d940 181 if((ret = TFT.DrawBitmapFile(fp)) < 0)
MidnightCow 0:583a42b8d940 182 {
MidnightCow 0:583a42b8d940 183 printf("error : %d\r\n",ret);
MidnightCow 0:583a42b8d940 184 }
MidnightCow 0:583a42b8d940 185 fclose(fp);
MidnightCow 0:583a42b8d940 186 TFT.locate(120-6*strlen("tiger24.bmp"),308);
MidnightCow 0:583a42b8d940 187 TFT.printf("tiger24.bmp");
MidnightCow 0:583a42b8d940 188 printf("press key");getchar();
MidnightCow 0:583a42b8d940 189 }
MidnightCow 0:583a42b8d940 190 }