Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: EasyButton OTA
- - Source Code NOT compiled for: Arduino Opta WiFi
- - Source Code created on: 2025-10-05 11:56:21
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Detect a debounced push-button event on A0 using */
- /* EasyButton; the input uses INPUT_PULLUP, so a */
- /* pressed state is LOW and should trigger the system */
- /* logic. Integrate flash over the air. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- #include <POTA.h>
- /****** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t button_PushButton_PIN_A0 = A0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- EasyButton button(button_PushButton_PIN_A0);
- POTA ota;
- /****** FUNCTION PROTOTYPES *****/
- void onButtonPressed();
- void performOTAUpdate();
- /***** SETUP / LOOP DEFINITIONS *****/
- void setup(void);
- void loop(void);
- void onButtonPressed()
- {
- // Debounced button press detected on A0 via EasyButton
- Serial.println("[POTA] Button pressed on A0");
- performOTAUpdate();
- }
- void performOTAUpdate()
- {
- Serial.println("[POTA] Starting OTA update check...");
- // Initialize POTA with WiFi credentials and device information.
- // Requires a valid secrets.h to supply credentials. See secrets.h in this project.
- POTAError err = ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
- if (err != POTAError::SUCCESS)
- {
- Serial.print("[POTA] begin() failed: ");
- Serial.println(ota.errorToString(err));
- return;
- }
- // Check for updates and perform OTA if available
- err = ota.checkAndPerformOTA();
- if (err == NO_UPDATE_AVAILABLE || err == POTAError::NO_UPDATE_AVAILABLE)
- {
- Serial.println("[POTA] Firmware already up to date");
- }
- else if (err != POTAError::SUCCESS)
- {
- Serial.print("[POTA] OTA error: ");
- Serial.println(ota.errorToString(err));
- }
- else
- {
- Serial.println("[POTA] OTA update performed (check serial for status)");
- }
- }
- void setup()
- {
- // Initialize Serial for debugging
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> POTA OTA via EasyButton on A0 <<<");
- // Initialize the button and attach callback
- button.begin();
- button.onPressed(onButtonPressed);
- }
- void loop()
- {
- // Read the push-button state and debounce internally
- button.read();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment