Skip to content

Commit 35fb620

Browse files
committed
1.1
Corrections and download function created!
1 parent 65eee84 commit 35fb620

File tree

8 files changed

+164
-9
lines changed

8 files changed

+164
-9
lines changed

.DS_Store

8 KB
Binary file not shown.

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Available resources:
2525
-Acquisition of token.
2626
-Upload files.
2727
-Upload of strings.
28+
-Download of files.
2829
(COMING SOON!)
2930

3031
This library does not have all the features available in the dropbox, it is constantly developing and improving!
@@ -100,8 +101,14 @@ The Replace type inserts a new file and if there is a file with the same name in
100101
0 to Add.
101102
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
102103
This function returns TRUE if it succeeded and FALSE if there was a failure!
104+
105+
bool fileDownload (String localFile, String address, bool type);
106+
This function downloads files from your Dropbox to your ESP8266, to use it simply provide it with the local address where the file will be saved (SPIFFS from your esp8266), the address of which place is saved the file you want to download from your dropbox and if you want to delete the file if there is already one with the same name in your esp8266, 1 to delete and 0 to not delete! If you enter 0 and the file exists, the new one will not be downloaded.
107+
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
108+
This function returns TRUE if it succeeded and FALSE if there was a failure!
109+
103110
Remember to create an instance to access the library:
104-
Ex: DropboxManager myDrop;
111+
Ex: DropboxMan myDrop;
105112

106113
See the Basic_upload example to understand better.
107114

@@ -150,6 +157,7 @@ Recursos disponíveis:
150157
-Aquisição de token.
151158
-Upload de arquivos.
152159
-Upload de strings.
160+
-Download de arquivos.
153161
(MAIS EM BREVE!)
154162

155163
Esta biblioteca não conta com todos os recursos disponíveis no dropbox, ela está em constante desenvolvimento e melhoria!
@@ -219,8 +227,15 @@ O tipo Substituir insere um novo arquivo e se existir um arquivo com o mesmo nom
219227
0 para Adicionar.
220228
Ex: myDrop.stringUpload("<minha string aqui>","/home/math/test.txt",1);
221229
Essa função retorna TRUE se teve sucesso e FALSE se houve alguma falha!
230+
231+
bool fileDownload(String localFile, String address, bool type);
232+
Essa função faz o download de arquivos do seu Dropbox para seu ESP8266, para usar basta fornecer a ela o endereço local onde o arquivo será salvo (SPIFFS do seu esp8266), o endereço de qual lugar está salvo o arquivo que deseja baixar do seu dropbox e se deseja apagar o arquivo caso já exista um com o mesmo nome no seu esp8266, 1 para apagar e 0 para não apagar! Caso coloque 0 e exista o arquivo, o novo não será baixado.
233+
Ex: myDrop.fileDownload("/test.txt","/home/math/test.txt",1);
234+
Essa função retorna TRUE se teve sucesso e FALSE se houve alguma falha!
235+
236+
222237
Lembre de criar uma instancia para acessar a biblioteca:
223-
Ex: DropboxManager myDrop;
238+
Ex: DropboxMan myDrop;
224239

225240
Veja o exemplo Basic_upload para entender melhor.
226241

examples/.DS_Store

6 KB
Binary file not shown.

examples/Basic_upload/Basic_upload.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const char* ssid = "...........";
2121
const char* password = "...........";
2222

2323

24-
DropboxManager myDrop;
24+
DropboxMan myDrop;
2525

2626

2727
void setup() {

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ DropboxMan KEYWORD2
1616
begin KEYWORD2
1717
getToken KEYWORD2
1818
fileUpload KEYWORD2
19-
stringUpload KEYWORD2
19+
stringUpload KEYWORD2
20+
fileDownload KEYWORD2

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name=DropboxManager
2-
version=1.0
3-
author=Lucas Romeiro <lucas_romeiro@hotmail.com>
2+
version=1.1
3+
author=ANTÔNIO CEZAR DE CASTRO LIMA, CRISTIANO HORA DE OLIVEIRA FONTES, LUCAS DE ARAÚJO WANDERLEY ROMEIRO
44
maintainer=Lucas Romeiro <lucas_romeiro@hotmail.com>
55
sentence=Manipulate your Dropbox files by ESP8266
66
paragraph=This library allows you to manipulate your files, for example, upload files and other functions. Save your files on the cloud!

src/DropboxManager.cpp

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Available resources:
2424
-Acquisition of token.
2525
-Upload files.
2626
-Upload of strings.
27+
-Download of files.
2728
(COMING SOON!)
2829
2930
This library does not have all the features available in the dropbox, it is constantly developing and improving!
@@ -99,8 +100,15 @@ The Replace type inserts a new file and if there is a file with the same name in
99100
0 to Add.
100101
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
101102
This function returns TRUE if it succeeded and FALSE if there was a failure!
103+
104+
bool fileDownload (String localFile, String address, bool type);
105+
This function downloads files from your Dropbox to your ESP8266, to use it simply provide it with the local address where the file will be saved (SPIFFS from your esp8266), the address of which place is saved the file you want to download from your dropbox and if you want to delete the file if there is already one with the same name in your esp8266, 1 to delete and 0 to not delete! If you enter 0 and the file exists, the new one will not be downloaded.
106+
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
107+
This function returns TRUE if it succeeded and FALSE if there was a failure!
108+
109+
102110
Remember to create an instance to access the library:
103-
Ex: DropboxManager myDrop;
111+
Ex: DropboxMan myDrop;
104112
105113
See the Basic_upload example to understand better.
106114
@@ -133,16 +141,18 @@ PARA EXPLICAÇÕES EM PORTUGUES, CONSULTAR O ARQUIVO “README.md” QUE SE ENCO
133141
#include "FS.h"
134142
#include "DropboxManager.h"
135143

136-
#define ver "v1.0"
144+
#define ver "v1.1"
137145
//#define debug_mode Serial
138146

139147

140148
#define upload "/2/files/upload HTTP/1.1\r\n"
149+
#define download "/2/files/download HTTP/1.1\r\n"
141150
#define host_content "Host: content.dropboxapi.com\r\n"
142151
#define content_type_octet "Content-Type: application/octet-stream\r\n"
143152
#define _accept "Accept: */*\r\n"
144153
#define Aut_Bearer "Authorization: Bearer "
145154
#define timeout_client 5000
155+
#define timeout_down 5000
146156
#define content_API "162.125.5.8"
147157
#define fingerprint_Content_API "9D 86 7B C9 7E 07 D7 5C 86 66 A3 E2 95 C3 B5 45 C5 1E 89 B3"
148158
#define main_API "162.125.5.7"
@@ -424,7 +434,128 @@ bool DropboxMan::stringUpload(String data, String address, bool type){
424434
}
425435

426436
}
437+
bool DropboxMan::fileDownload(String localFile, String address, bool type){
438+
439+
440+
441+
WiFiClientSecure client;
442+
//WiFiClientSecure *client= new WiFiClientSecure;
443+
#ifdef debug_mode
444+
debug_mode.println("Connecting to Dropbox...");
445+
#endif
446+
if (!client.connect(content_API,443)){
447+
#ifdef debug_mode
448+
debug_mode.println("Connection failed!");
449+
#endif
450+
//client.close();
451+
client.stop();
452+
return false;
453+
}
454+
455+
if (client.verify(fingerprint_Content_API,"content.dropboxapi.com")) {
456+
#ifdef debug_mode
457+
debug_mode.println("Certificate matches!");
458+
#endif
459+
} else {
460+
#ifdef debug_mode
461+
debug_mode.println("Certificate doesn't match!");
462+
#endif
463+
}
464+
465+
if(!SPIFFS.begin()){
466+
#ifdef debug_mode
467+
debug_mode.println("Failed to open file system...");
468+
#endif
469+
//client.close();
470+
client.stop();
471+
return false;
472+
} else {
473+
#ifdef debug_mode
474+
debug_mode.println("Open file system successfully!");
475+
#endif
476+
}
427477

478+
479+
480+
481+
482+
483+
client.print(String("POST ") + download +
484+
host_content +
485+
"User-Agent: ESP8266/Arduino_Dropbox_Manager_"+(String)ver+"\r\n" +
486+
(String)Aut_Bearer + (String)_token +"\r\n" +
487+
_accept +
488+
"Dropbox-API-Arg: {\"path\": \"" + address + "\"}\r\n\r\n"// +
489+
//"Content-Length: 0\r\n\r\n"
490+
);
491+
492+
493+
494+
#ifdef debug_mode
495+
debug_mode.println("Request sent!");
496+
#endif
497+
uint32_t millisTimeoutClient;
498+
millisTimeoutClient = millis();
499+
String line;
500+
bool ok;
501+
ok=0;
502+
while (client.connected() && ((millis()-millisTimeoutClient)<timeout_client)) {
503+
line = client.readStringUntil('\n');
504+
if (line == "\r") {
505+
break;
506+
}
507+
if(line.indexOf(address+"\", \"par")!=-1){
508+
ok=1;
509+
}
510+
}
511+
512+
if(ok){
513+
if(type){
514+
SPIFFS.remove(localFile);
515+
#ifdef debug_mode
516+
debug_mode.println("Old file removed!");
517+
#endif
518+
}else{
519+
if(SPIFFS.exists(localFile)){
520+
#ifdef debug_mode
521+
debug_mode.println("Aborted, file exist!");
522+
#endif
523+
SPIFFS.end();
524+
client.stop();
525+
return false;
526+
}
527+
}
528+
529+
530+
millisTimeoutClient = millis();
531+
File files = SPIFFS.open(localFile,"a");
532+
while (client.connected() && ((millis()-millisTimeoutClient)<timeout_down)) {
533+
if (client.available()) {
534+
millisTimeoutClient = millis();
535+
yield();
536+
ESP.wdtFeed();
537+
files.println(client.readStringUntil('\r'));
538+
}
539+
}
540+
541+
files.close();
542+
SPIFFS.end();
543+
}
544+
//client.close();
545+
client.stop();
546+
//delete client;
547+
if (ok) {
548+
#ifdef debug_mode
549+
debug_mode.println("Successfull!!!");
550+
#endif
551+
return true;
552+
} else {
553+
#ifdef debug_mode
554+
debug_mode.println("ERROR!!!");
555+
#endif
556+
return false;
557+
}
558+
}
428559

429560

430561

src/DropboxManager.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Available resources:
2424
-Acquisition of token.
2525
-Upload files.
2626
-Upload of strings.
27+
-Download of files.
2728
(COMING SOON!)
2829
2930
This library does not have all the features available in the dropbox, it is constantly developing and improving!
@@ -99,8 +100,14 @@ The Replace type inserts a new file and if there is a file with the same name in
99100
0 to Add.
100101
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
101102
This function returns TRUE if it succeeded and FALSE if there was a failure!
103+
104+
bool fileDownload (String localFile, String address, bool type);
105+
This function downloads files from your Dropbox to your ESP8266, to use it simply provide it with the local address where the file will be saved (SPIFFS from your esp8266), the address of which place is saved the file you want to download from your dropbox and if you want to delete the file if there is already one with the same name in your esp8266, 1 to delete and 0 to not delete! If you enter 0 and the file exists, the new one will not be downloaded.
106+
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
107+
This function returns TRUE if it succeeded and FALSE if there was a failure!
108+
102109
Remember to create an instance to access the library:
103-
Ex: DropboxManager myDrop;
110+
Ex: DropboxMan myDrop;
104111
105112
See the Basic_upload example to understand better.
106113
@@ -141,6 +148,7 @@ class DropboxMan{
141148
String getToken(String code);
142149
bool fileUpload(String localFile, String address, bool type);
143150
bool stringUpload(String data, String address, bool type);
151+
bool fileDownload(String localFile, String address, bool type);
144152

145153
private:
146154
String _token;

0 commit comments

Comments
 (0)