pleasedontcode

OTA Check rev_05

Oct 5th, 2025
119
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: OTA Check
  13.     - Source Code NOT compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-10-05 11:46:50
  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. #ifndef POTA_ENABLED
  34. #define POTA_ENABLED 1
  35. #endif
  36.  
  37. #if defined(POTA_ENABLED) && POTA_ENABLED
  38. POTA ota;
  39. #endif
  40.  
  41. /****** FUNCTION PROTOTYPES *****/
  42. void setup(void);
  43. void loop(void);
  44. void buttonPressed();
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t button_PushButton_PIN_A0      = A0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****
  50. ******/
  51. EasyButton debouncedBtn(button_PushButton_PIN_A0);
  52.  
  53. void setup(void)
  54. {
  55.   // put your setup code here, to run once:
  56.  
  57.   Serial.begin(115200);
  58.   Serial.println();
  59.   Serial.println("POTATest: Debounced button on A0 ready. Press to trigger OTA (if configured).");
  60.  
  61.   pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
  62.  
  63.   debouncedBtn.begin();
  64.   debouncedBtn.onPressed(buttonPressed);
  65. }
  66.  
  67. void buttonPressed()
  68. {
  69.   Serial.println("Debounced button pressed (LOW). Triggering OTA check if configured...");
  70. #if defined(POTA_ENABLED) && POTA_ENABLED
  71.   POTAError err = ota.checkAndPerformOTA();
  72.   if (err == POTAError::NO_UPDATE_AVAILABLE) {
  73.     Serial.println("OTA: firmware already up to date");
  74.   } else if (err != POTAError::SUCCESS) {
  75.     Serial.print("OTA error: ");
  76.     Serial.println(ota.errorToString(err));
  77.   } else {
  78.     Serial.println("OTA check completed successfully");
  79.   }
  80. #endif
  81. }
  82.  
  83. void loop(void)
  84. {
  85.   // put your main code here, to run repeatedly:
  86.   debouncedBtn.read();
  87. }
  88.  
  89. /* END CODE */
  90.  
Advertisement
Add Comment
Please, Sign In to add comment