Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Nov 14, 2020
1 parent 149a389 commit 52b8e47
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 23 deletions.
25 changes: 24 additions & 1 deletion examples/Unpack_gz_file/Unpack_gz_file.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#include <SPIFFS.h>
#include <ESP32-targz.h>

// progress callback, leave empty for less console output
void myNullProgressCallback( uint8_t progress ) {
// printf("Progress: %d", progress );
}
// error/warning/info logger, leave empty for less console output
void myNullLogger(const char* format, ...) {
//va_list args;
//va_start(args, format);
//vprintf(format, args);
//va_end(args);
}


void setup() {

Serial.begin( 115200 );
Serial.printf("Initializing SPIFFS...\n");

if (!SPIFFS.begin(false)) {
Serial.printf("SPIFFS Mount Failed\n");
}
else {
Serial.printf("SPIFFS Mount Successful\n");
}

SPIFFS.begin( true );
//setProgressCallback( myNullProgressCallback );
//setLoggerCallback( myNullLogger );

// extract content from gz file
gzExpander(SPIFFS, "/index_html.gz", SPIFFS, "/index.html");
Expand All @@ -16,6 +38,7 @@ void setup() {

}


void loop() {

}
24 changes: 23 additions & 1 deletion examples/Unpack_tar_file/Unpack_tar_file.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#include <SPIFFS.h>
#include <ESP32-targz.h>

// progress callback, leave empty for less console output
void myNullProgressCallback( uint8_t progress ) {
// printf("Progress: %d", progress );
}
// error/warning/info logger, leave empty for less console output
void myNullLogger(const char* format, ...) {
//va_list args;
//va_start(args, format);
//vprintf(format, args);
//va_end(args);
}


void setup() {

Serial.begin( 115200 );
Serial.printf("Initializing SPIFFS...\n");

if (!SPIFFS.begin(false)) {
Serial.printf("SPIFFS Mount Failed\n");
}
else {
Serial.printf("SPIFFS Mount Successful\n");
}

SPIFFS.begin(true);
//setProgressCallback( myNullProgressCallback );
//setLoggerCallback( myNullLogger );

// expand tar contents to /tmp folder
tarExpander(SPIFFS, "/tobozo.tar", SPIFFS, "/");
Expand Down
37 changes: 29 additions & 8 deletions examples/Unpack_targz_file/Unpack_targz_file.ino
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
#include <SPIFFS.h>
#include <ESP32-targz.h>

// progress callback, leave empty for less console output
void myNullProgressCallback( uint8_t progress ) {
// printf("Progress: %d", progress );
}
// error/warning/info logger, leave empty for less console output
void myNullLogger(const char* format, ...) {
//va_list args;
//va_start(args, format);
//vprintf(format, args);
//va_end(args);
}


void setup() {

Serial.begin( 115200 );
Serial.printf("Initializing SPIFFS...\n");

SPIFFS.begin(true);

// direct .tar.gz to file expanding is broken so do this separately
// tarGzExpander(SPIFFS, "/tbz.tar.gz", SPIFFS, "/tmp");
if (!SPIFFS.begin(false)) {
Serial.printf("SPIFFS Mount Failed\n");
}
else {
Serial.printf("SPIFFS Mount Successful\n");
}

gzExpander(SPIFFS, "/tbz.tar.gz", SPIFFS, "/tmp/data.tar");
tarExpander(SPIFFS, "/tmp/data.tar", SPIFFS, "/tmp");
SPIFFS.remove("/tmp/data.tar");
//setProgressCallback( myNullProgressCallback );
//setLoggerCallback( myNullLogger );

tarGzListDir( SPIFFS, "/tmp");
if( tarGzExpander(SPIFFS, "/zombocom.tar.gz", SPIFFS, "/tmp") ) {
Serial.println("Yay!");
tarGzListDir( SPIFFS, "/tmp" );
} else {
Serial.printf("tarGzExpander failed with return code #%d\n", tarGzGetError() );
}

}


void loop() {

}
Binary file added examples/Unpack_targz_file/data/zombocom.tar.gz
Binary file not shown.
60 changes: 47 additions & 13 deletions examples/Update_from_gz/Update_from_gz.ino
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
#include <SPIFFS.h>
#include <ESP32-targz.h>

#define BUTTON_PIN 32
// progress callback, leave empty for less console output
void myNullProgressCallback( uint8_t progress ) {
// printf("Progress: %d", progress );
}
// error/warning/info logger, leave empty for less console output
void myNullLogger(const char* format, ...) {
//va_list args;
//va_start(args, format);
//vprintf(format, args);
//va_end(args);
}

void setup() {
// 1) Find your firmware and gzip it:
// gzip -c /tmp/arduino/firmware.bin > /tmp/firmware.gz
//
// 2) Copy the gz file in the /data folder and upload it using Arduino sketch data uploader for SPIFFS
//
// 3) Edit the value of "firmwareFile" to match the gz file name:
//
const char* firmwareFile = "/M5Rotatey_Cube.gz";

void setup() {
Serial.begin( 115200 );
Serial.printf("Initializing SPIFFS...\n");

pinMode( BUTTON_PIN, INPUT_PULLUP );

if (!SPIFFS.begin(false)) {
Serial.printf("SPIFFS Mount Failed\n");
}
else {
Serial.printf("SPIFFS Mount Successful\n");
}
}

void loop() {

if( digitalRead( BUTTON_PIN ) == LOW ) {

SPIFFS.begin(true);

// flash the ESP with gz's contents (gzip the bin yourself and use the spiffs uploader)
gzUpdater(SPIFFS, "/menu_bin.gz");

void loop() {
bool done = false;

while (!done) {
delay(1000);
if (SPIFFS.exists( firmwareFile )) { // <<< gzipped firmware update
Serial.printf("Found file, about to update...\n");
delay(1000);
//setProgressCallback( myNullProgressCallback );
//setLoggerCallback( myNullLogger );
// flash the ESP with gz's contents (gzip the bin yourself and use the spiffs uploader)
if( ! gzUpdater(SPIFFS, firmwareFile ) ) {
Serial.printf("gzUpdater failed with return code #%d", tarGzGetError() );
}
done = true;
}
else {
Serial.printf("firmware not found\n");
break;
}
}

}
Binary file added examples/Update_from_gz/data/M5Rotatey_Cube.gz
Binary file not shown.

0 comments on commit 52b8e47

Please sign in to comment.