From d02f51882bd26422100507f25af12fc32951b0ce Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Mon, 29 May 2023 16:39:16 +0200 Subject: [PATCH] ota improvements --- .github/workflows/release.yml | 8 ++-- ESP32_AP-Flasher/data/calendar.txt | 46 ------------------- ESP32_AP-Flasher/data/demo_image_generator.py | 23 +++++++++- ESP32_AP-Flasher/data/www/ota.js | 14 ++++-- ESP32_AP-Flasher/src/ota.cpp | 7 +-- genfilelist.py | 1 - 6 files changed, 41 insertions(+), 58 deletions(-) delete mode 100644 ESP32_AP-Flasher/data/calendar.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37515a5f..b9175a8a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,7 +54,7 @@ jobs: - name: Build firmware for ESP32 run: | cd ESP32_AP-Flasher - export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref }} -D SHA=$GITHUB_SHA" + export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref_name }} -D SHA=$GITHUB_SHA" pio run --environment Simple_AP mkdir /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32fw cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32fw/boot_app0.bin @@ -76,7 +76,7 @@ jobs: - name: Build firmware for ESP32-S2 run: | cd ESP32_AP-Flasher - export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref }} -D SHA=$GITHUB_SHA" + export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref_name }} -D SHA=$GITHUB_SHA" pio run --environment OpenEPaperLink_Mini_AP mkdir /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32s2fw cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32s2fw/boot_app0.bin @@ -98,7 +98,7 @@ jobs: - name: Build firmware for ESP32-S3 run: | cd ESP32_AP-Flasher - export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref }} -D SHA=$GITHUB_SHA" + export PLATFORMIO_BUILD_FLAGS="-D BUILD_VERSION=${{ github.ref_name }} -D SHA=$GITHUB_SHA" pio run --environment OpenEPaperLink_AP_and_Flasher mkdir /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32s3fw cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin /home/runner/work/OpenEPaperLink/OpenEPaperLink/esp32s3fw/boot_app0.bin @@ -129,7 +129,7 @@ jobs: - name: generate release json file run: | - python genfilelist.py ${{ github.ref }} $GITHUB_REPOSITORY $GITHUB_SHA + python genfilelist.py ${{ github.ref_name }} $GITHUB_REPOSITORY $GITHUB_SHA - name: Add file list to release uses: svenstaro/upload-release-action@v2 diff --git a/ESP32_AP-Flasher/data/calendar.txt b/ESP32_AP-Flasher/data/calendar.txt deleted file mode 100644 index 5997a802..00000000 --- a/ESP32_AP-Flasher/data/calendar.txt +++ /dev/null @@ -1,46 +0,0 @@ -To use Google Apps Script to get all events for the next day and return them via JSON in a web app, you can follow these steps: - -Create a new Google Apps Script project by going to https://script.google.com and clicking on "New project". - -In the script editor, create a new function called "getEventsForNextDay" that will fetch all events for the next day and return them in JSON format: - -function getEventsForNextDay() { - var start = new Date(); - var end = new Date(); - end.setDate(end.getDate() + 1); - var calendars = CalendarApp.getAllCalendars(); - var events = []; - for (var i = 0; i < calendars.length; i++) { - var calendar = calendars[i]; - var eventsInCalendar = calendar.getEvents(start, end); - for (var j = 0; j < eventsInCalendar.length; j++) { - var event = eventsInCalendar[j]; - events.push({ - title: event.getTitle(), - start: Math.floor(event.getStartTime().getTime() / 1000), - end: Math.floor(event.getEndTime().getTime() / 1000), - location: event.getLocation(), - description: event.getDescription() - }); - } - } - // Sort events by start date/time - events.sort(function(a, b) { - return a.start - b.start; - }); - return JSON.stringify(events); -} - -function doGet() { - var content = getEventsForNextDay(); - var output = ContentService.createTextOutput(content); - output.setMimeType(ContentService.MimeType.JSON); - return output; -} - - -This function calls the getEventsForNextDay() function to get the events in JSON format, creates a text output with the JSON content, sets the MIME type to JSON, and returns the output. - -Deploy the web app by clicking on "Deploy > New Deployment" in the script editor. Choose "Web app" as the deployment type, set the access to "Anyone, even anonymous", and click on "Deploy". Make sure to take note of the web app URL generated by Google. - -Test the web app by visiting the web app URL in a web browser. You should see the events for the next day in JSON format. diff --git a/ESP32_AP-Flasher/data/demo_image_generator.py b/ESP32_AP-Flasher/data/demo_image_generator.py index da998bfc..21872159 100644 --- a/ESP32_AP-Flasher/data/demo_image_generator.py +++ b/ESP32_AP-Flasher/data/demo_image_generator.py @@ -1,5 +1,10 @@ +import requests from PIL import Image, ImageDraw, ImageFont +mac = "00000197E5CB3B38" # destination mac address +dither = 0 # set dither to 1 is you're sending photos etc +apip = "192.168.178.192" # ip address of your access point + # Create a new paletted image with indexed colors image = Image.new('P', (296, 128)) @@ -40,4 +45,20 @@ draw.text(text_position_line2, line2, fill=1, font=font_line2) # Use palette in rgb_image = image.convert('RGB') # Save the image as JPEG with maximum quality -rgb_image.save('output.jpg', 'JPEG', quality="maximum") +image_path = 'output.jpg' +rgb_image.save(image_path, 'JPEG', quality="maximum") + +# Prepare the HTTP POST request +url = "http://" + apip + "/imgupload" +payload = {"dither": dither, "mac": mac} # Additional POST parameter +files = {"file": open(image_path, "rb")} # File to be uploaded + +# Send the HTTP POST request +response = requests.post(url, data=payload, files=files) + +# Check the response status +if response.status_code == 200: + print("Image uploaded successfully!") +else: + print("Failed to upload the image.") + diff --git a/ESP32_AP-Flasher/data/www/ota.js b/ESP32_AP-Flasher/data/www/ota.js index d7d5425c..3ac82a42 100644 --- a/ESP32_AP-Flasher/data/www/ota.js +++ b/ESP32_AP-Flasher/data/www/ota.js @@ -74,7 +74,7 @@ export function initUpdate() { releaseDetails.forEach(release => { const tableRow = document.createElement('tr'); - tableRow.innerHTML = `${release.tag_name}${release.date}${release.name}${release.author}`; + tableRow.innerHTML = `${release.tag_name}${release.date}${release.name}${release.author}`; table.appendChild(tableRow); }); @@ -137,10 +137,14 @@ export function updateWebpage(fileUrl) { print(`Finished updating with ${errors} errors.`, "red"); } else { print("------", "gray"); - print("Update succesfull."); + print("Update succesful, reload now."); } disableButtons(false); + const newLine = document.createElement('div'); + newLine.innerHTML = ""; + consoleDiv.appendChild(newLine); + consoleDiv.scrollTop = consoleDiv.scrollHeight; }; } @@ -228,7 +232,11 @@ export function print(line, color = "white") { const isScrolledToBottom = consoleDiv.scrollHeight - consoleDiv.clientHeight <= consoleDiv.scrollTop; const newLine = document.createElement('div'); newLine.style.color = color; - newLine.textContent = line; + if (line == "[reboot]") { + newLine.innerHTML = ""; + } else { + newLine.textContent = line; + } consoleDiv.appendChild(newLine); if (isScrolledToBottom) { consoleDiv.scrollTop = consoleDiv.scrollHeight; diff --git a/ESP32_AP-Flasher/src/ota.cpp b/ESP32_AP-Flasher/src/ota.cpp index dfb78626..ca1f5008 100644 --- a/ESP32_AP-Flasher/src/ota.cpp +++ b/ESP32_AP-Flasher/src/ota.cpp @@ -202,7 +202,8 @@ void updateFirmware(const char* url, const char* expectedMd5, size_t size) { if (written == httpClient.getSize()) { if (Update.end(true)) { wsSerial("Firmware update successful"); - wsSerial("Restarting system..."); + wsSerial("Reboot system now"); + wsSerial("[reboot]"); vTaskDelay(1000 / portTICK_PERIOD_MS); ESP.restart(); } else { @@ -228,8 +229,8 @@ void handleRollback(AsyncWebServerRequest* request) { if (Update.canRollBack()) { bool rollbackSuccess = Update.rollBack(); if (rollbackSuccess) { - request->send(200, "Rollback successfull"); - wsSerial("Rollback successfull"); + request->send(200, "Rollback successful"); + wsSerial("Rollback successful"); wsSerial("Restarting system..."); vTaskDelay(1000 / portTICK_PERIOD_MS); ESP.restart(); diff --git a/genfilelist.py b/genfilelist.py index 8af56507..36e2ea3f 100644 --- a/genfilelist.py +++ b/genfilelist.py @@ -50,7 +50,6 @@ rp = os.getcwd() now = datetime.now() dt_string = now.strftime("%d/%m/%Y %H:%M:%S") tag = sys.argv[1] -tag = tag[10:] binaries = generate_file_hashes2(rp + "/espbinaries",tag) tagota = generate_file_hashes2(rp + "/binaries",tag)