Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- ESP32-CAM remote image access via FTP. Take pictures with ESP32 and upload it via FTP making it accessible for the outisde network.
- Leonardo Bispo
- July - 2019
- https://github.com/ldab/ESP32_FTPClient
- Distributed as-is; no warranty is given.
- ******************************************************************************/
- #include "Arduino.h"
- #include <Ethernet.h>
- #include <EthernetClient.h>
- #include "ESP32_FTPClient.h"
- #include "octocat.h"
- #include <SPI.h>
- // Enter a MAC address for your controller below.
- // Newer Ethernet shields have a MAC address printed on a sticker on the shield
- byte mac[] = {
- 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
- };
- char ftp_server[] = "";
- char ftp_user[] = "";
- char ftp_pass[] = "";
- // you can pass a FTP timeout and debbug mode on the last 2 arguments
- ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);
- void setup()
- {
- Serial.begin( 115200 );
- Ethernet.init(15); // ESP32CAM SCS (chip select pin, 15 and 2 work for sure)
- SPI.begin(14,12,13,15); //SCLK,MISO,MOSI,SCS(same as Ethernet.init())
- // start the Ethernet connection:
- Serial.println("Initialize Ethernet with DHCP:");
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- if (Ethernet.hardwareStatus() == EthernetNoHardware) {
- Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
- } else if (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("Ethernet cable is not connected.");
- }
- // no point in carrying on, so do nothing forevermore:
- while (true) {
- delay(1);
- }
- }
- // print your local IP address:
- Serial.print("My IP address: ");
- Serial.println(Ethernet.localIP());
- ftp.OpenConnection();
- // Get directory content
- ftp.InitFile("Type A");
- String list[128];
- ftp.ChangeWorkDir("/public_html/zyro/gallery_gen/");
- ftp.ContentList("", list);
- Serial.println("\nDirectory info: ");
- for(int i = 0; i < sizeof(list); i++)
- {
- if(list[i].length() > 0)
- Serial.println(list[i]);
- else
- break;
- }
- // Make a new directory
- ftp.InitFile("Type A");
- ftp.MakeDir("my_new_dir");
- // Create the new file and send the image
- ftp.ChangeWorkDir("my_new_dir");
- ftp.InitFile("Type I");
- ftp.NewFile("octocat.jpg");
- ftp.WriteData( octocat_pic, sizeof(octocat_pic) );
- ftp.CloseFile();
- // Create the file new and write a string into it
- ftp.InitFile("Type A");
- ftp.NewFile("hello_world.txt");
- ftp.Write("Hello World");
- ftp.CloseFile();
- ftp.CloseConnection();
- }
- void loop()
- {
- }
Add Comment
Please, Sign In to add comment