Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
Corrections and download function created!
  • Loading branch information
lucasromeiro committed Jun 1, 2018
1 parent 65eee84 commit 35fb620
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 9 deletions.
Binary file added .DS_Store
Binary file not shown.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Available resources:
-Acquisition of token.
-Upload files.
-Upload of strings.
-Download of files.
(COMING SOON!)

This library does not have all the features available in the dropbox, it is constantly developing and improving!
Expand Down Expand Up @@ -100,8 +101,14 @@ The Replace type inserts a new file and if there is a file with the same name in
0 to Add.
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!

bool fileDownload (String localFile, String address, bool type);
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.
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!

Remember to create an instance to access the library:
Ex: DropboxManager myDrop;
Ex: DropboxMan myDrop;

See the Basic_upload example to understand better.

Expand Down Expand Up @@ -150,6 +157,7 @@ Recursos disponíveis:
-Aquisição de token.
-Upload de arquivos.
-Upload de strings.
-Download de arquivos.
(MAIS EM BREVE!)

Esta biblioteca não conta com todos os recursos disponíveis no dropbox, ela está em constante desenvolvimento e melhoria!
Expand Down Expand Up @@ -219,8 +227,15 @@ O tipo Substituir insere um novo arquivo e se existir um arquivo com o mesmo nom
0 para Adicionar.
Ex: myDrop.stringUpload("<minha string aqui>","/home/math/test.txt",1);
Essa função retorna TRUE se teve sucesso e FALSE se houve alguma falha!

bool fileDownload(String localFile, String address, bool type);
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.
Ex: myDrop.fileDownload("/test.txt","/home/math/test.txt",1);
Essa função retorna TRUE se teve sucesso e FALSE se houve alguma falha!


Lembre de criar uma instancia para acessar a biblioteca:
Ex: DropboxManager myDrop;
Ex: DropboxMan myDrop;

Veja o exemplo Basic_upload para entender melhor.

Expand Down
Binary file added examples/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/Basic_upload/Basic_upload.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const char* ssid = "...........";
const char* password = "...........";


DropboxManager myDrop;
DropboxMan myDrop;


void setup() {
Expand Down
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ DropboxMan KEYWORD2
begin KEYWORD2
getToken KEYWORD2
fileUpload KEYWORD2
stringUpload KEYWORD2
stringUpload KEYWORD2
fileDownload KEYWORD2
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=DropboxManager
version=1.0
author=Lucas Romeiro <[email protected]>
version=1.1
author=ANTÔNIO CEZAR DE CASTRO LIMA, CRISTIANO HORA DE OLIVEIRA FONTES, LUCAS DE ARAÚJO WANDERLEY ROMEIRO
maintainer=Lucas Romeiro <[email protected]>
sentence=Manipulate your Dropbox files by ESP8266
paragraph=This library allows you to manipulate your files, for example, upload files and other functions. Save your files on the cloud!
Expand Down
135 changes: 133 additions & 2 deletions src/DropboxManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Available resources:
-Acquisition of token.
-Upload files.
-Upload of strings.
-Download of files.
(COMING SOON!)
This library does not have all the features available in the dropbox, it is constantly developing and improving!
Expand Down Expand Up @@ -99,8 +100,15 @@ The Replace type inserts a new file and if there is a file with the same name in
0 to Add.
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!
bool fileDownload (String localFile, String address, bool type);
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.
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!
Remember to create an instance to access the library:
Ex: DropboxManager myDrop;
Ex: DropboxMan myDrop;
See the Basic_upload example to understand better.
Expand Down Expand Up @@ -133,16 +141,18 @@ PARA EXPLICAÇÕES EM PORTUGUES, CONSULTAR O ARQUIVO “README.md” QUE SE ENCO
#include "FS.h"
#include "DropboxManager.h"

#define ver "v1.0"
#define ver "v1.1"
//#define debug_mode Serial


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

}
bool DropboxMan::fileDownload(String localFile, String address, bool type){



WiFiClientSecure client;
//WiFiClientSecure *client= new WiFiClientSecure;
#ifdef debug_mode
debug_mode.println("Connecting to Dropbox...");
#endif
if (!client.connect(content_API,443)){
#ifdef debug_mode
debug_mode.println("Connection failed!");
#endif
//client.close();
client.stop();
return false;
}

if (client.verify(fingerprint_Content_API,"content.dropboxapi.com")) {
#ifdef debug_mode
debug_mode.println("Certificate matches!");
#endif
} else {
#ifdef debug_mode
debug_mode.println("Certificate doesn't match!");
#endif
}

if(!SPIFFS.begin()){
#ifdef debug_mode
debug_mode.println("Failed to open file system...");
#endif
//client.close();
client.stop();
return false;
} else {
#ifdef debug_mode
debug_mode.println("Open file system successfully!");
#endif
}






client.print(String("POST ") + download +
host_content +
"User-Agent: ESP8266/Arduino_Dropbox_Manager_"+(String)ver+"\r\n" +
(String)Aut_Bearer + (String)_token +"\r\n" +
_accept +
"Dropbox-API-Arg: {\"path\": \"" + address + "\"}\r\n\r\n"// +
//"Content-Length: 0\r\n\r\n"
);



#ifdef debug_mode
debug_mode.println("Request sent!");
#endif
uint32_t millisTimeoutClient;
millisTimeoutClient = millis();
String line;
bool ok;
ok=0;
while (client.connected() && ((millis()-millisTimeoutClient)<timeout_client)) {
line = client.readStringUntil('\n');
if (line == "\r") {
break;
}
if(line.indexOf(address+"\", \"par")!=-1){
ok=1;
}
}

if(ok){
if(type){
SPIFFS.remove(localFile);
#ifdef debug_mode
debug_mode.println("Old file removed!");
#endif
}else{
if(SPIFFS.exists(localFile)){
#ifdef debug_mode
debug_mode.println("Aborted, file exist!");
#endif
SPIFFS.end();
client.stop();
return false;
}
}


millisTimeoutClient = millis();
File files = SPIFFS.open(localFile,"a");
while (client.connected() && ((millis()-millisTimeoutClient)<timeout_down)) {
if (client.available()) {
millisTimeoutClient = millis();
yield();
ESP.wdtFeed();
files.println(client.readStringUntil('\r'));
}
}

files.close();
SPIFFS.end();
}
//client.close();
client.stop();
//delete client;
if (ok) {
#ifdef debug_mode
debug_mode.println("Successfull!!!");
#endif
return true;
} else {
#ifdef debug_mode
debug_mode.println("ERROR!!!");
#endif
return false;
}
}



Expand Down
10 changes: 9 additions & 1 deletion src/DropboxManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Available resources:
-Acquisition of token.
-Upload files.
-Upload of strings.
-Download of files.
(COMING SOON!)
This library does not have all the features available in the dropbox, it is constantly developing and improving!
Expand Down Expand Up @@ -99,8 +100,14 @@ The Replace type inserts a new file and if there is a file with the same name in
0 to Add.
Ex: myDrop.stringUpload("<my string here>", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!
bool fileDownload (String localFile, String address, bool type);
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.
Ex: myDrop.fileDownload ("/test.txt", "/home/math/test.txt", 1);
This function returns TRUE if it succeeded and FALSE if there was a failure!
Remember to create an instance to access the library:
Ex: DropboxManager myDrop;
Ex: DropboxMan myDrop;
See the Basic_upload example to understand better.
Expand Down Expand Up @@ -141,6 +148,7 @@ class DropboxMan{
String getToken(String code);
bool fileUpload(String localFile, String address, bool type);
bool stringUpload(String data, String address, bool type);
bool fileDownload(String localFile, String address, bool type);

private:
String _token;
Expand Down

0 comments on commit 35fb620

Please sign in to comment.