pleasedontcode

EasyButton OTA rev_06

Oct 5th, 2025
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: EasyButton OTA
  13.     - Source Code NOT compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-10-05 11:56:21
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Detect a debounced push-button event on A0 using */
  21.     /* EasyButton; the input uses INPUT_PULLUP, so a */
  22.     /* pressed state is LOW and should trigger the system */
  23.     /* logic. Integrate flash over the air. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <EasyButton.h>
  31. #include <POTA.h>
  32.  
  33. /****** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t button_PushButton_PIN_A0 = A0;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  37. EasyButton button(button_PushButton_PIN_A0);
  38. POTA ota;
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void onButtonPressed();
  42. void performOTAUpdate();
  43.  
  44. /***** SETUP / LOOP DEFINITIONS *****/
  45. void setup(void);
  46. void loop(void);
  47.  
  48. void onButtonPressed()
  49. {
  50.   // Debounced button press detected on A0 via EasyButton
  51.   Serial.println("[POTA] Button pressed on A0");
  52.   performOTAUpdate();
  53. }
  54.  
  55. void performOTAUpdate()
  56. {
  57.   Serial.println("[POTA] Starting OTA update check...");
  58.  
  59.   // Initialize POTA with WiFi credentials and device information.
  60.   // Requires a valid secrets.h to supply credentials. See secrets.h in this project.
  61.   POTAError err = ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
  62.   if (err != POTAError::SUCCESS)
  63.   {
  64.     Serial.print("[POTA] begin() failed: ");
  65.     Serial.println(ota.errorToString(err));
  66.     return;
  67.   }
  68.  
  69.   // Check for updates and perform OTA if available
  70.   err = ota.checkAndPerformOTA();
  71.   if (err == NO_UPDATE_AVAILABLE || err == POTAError::NO_UPDATE_AVAILABLE)
  72.   {
  73.     Serial.println("[POTA] Firmware already up to date");
  74.   }
  75.   else if (err != POTAError::SUCCESS)
  76.   {
  77.     Serial.print("[POTA] OTA error: ");
  78.     Serial.println(ota.errorToString(err));
  79.   }
  80.   else
  81.   {
  82.     Serial.println("[POTA] OTA update performed (check serial for status)");
  83.   }
  84. }
  85.  
  86. void setup()
  87. {
  88.   // Initialize Serial for debugging
  89.   Serial.begin(115200);
  90.   Serial.println();
  91.   Serial.println(">>> POTA OTA via EasyButton on A0 <<<");
  92.  
  93.   // Initialize the button and attach callback
  94.   button.begin();
  95.   button.onPressed(onButtonPressed);
  96. }
  97.  
  98. void loop()
  99. {
  100.   // Read the push-button state and debounce internally
  101.   button.read();
  102. }
  103.  
  104. /* END CODE */
  105.  
Advertisement
Add Comment
Please, Sign In to add comment