pleasedontcode

OTA Trigger rev_03

Oct 5th, 2025
71
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 Trigger
  13.     - Source Code compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-10-05 11:36:19
  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.  
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <EasyButton.h>
  33.  
  34. #if __has_include("POTA.h")
  35. #include <POTA.h>
  36. #define POTA_AVAILABLE 1
  37. #else
  38. #define POTA_AVAILABLE 0
  39. #endif
  40.  
  41. #if __has_include("secrets.h")
  42. #include "secrets.h"
  43. #define SECRETS_AVAILABLE 1
  44. #else
  45. #define SECRETS_AVAILABLE 0
  46. #endif
  47.  
  48. #if POTA_AVAILABLE && SECRETS_AVAILABLE
  49. POTA ota;
  50. #endif
  51.  
  52. /** Pin definitions **/
  53. const uint8_t button_PushButton_PIN_A0 = A0;
  54.  
  55. // Instance of EasyButton for the debounced push-button on A0
  56. EasyButton button(button_PushButton_PIN_A0);
  57.  
  58. /** Prototypes **/
  59. void onButtonPressed();
  60. void performOTAIfConfigured();
  61.  
  62. void setup(void);
  63. void loop(void);
  64.  
  65. void setup(void)
  66. {
  67.   // Initialize serial for debugging
  68.   Serial.begin(115200);
  69.   // Small delay to ensure serial is ready
  70.   delay(100);
  71.  
  72.   Serial.println("POTA EasyButton debounced button on A0 - OTA integration test");
  73.  
  74.   // Use INPUT_PULLUP for the push-button as required by the system requirements
  75.   pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
  76.  
  77.   // Initialize the button handling
  78.   button.begin();
  79.   button.onPressed(onButtonPressed);
  80.  
  81.   #if POTA_AVAILABLE && SECRETS_AVAILABLE
  82.   Serial.println("POTA and secrets detected. Initializing OTA may occur on button press.");
  83.   // Initialize OTA if secrets are available. The exact call depends on library usage
  84.   ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
  85.   #endif
  86. }
  87.  
  88. void loop(void)
  89. {
  90.   // Regularly update the button state (debounce handled internally by EasyButton)
  91.   button.read();
  92.  
  93.   #if POTA_AVAILABLE && SECRETS_AVAILABLE
  94.   // Optional: allow OTA background processing if the library supports it
  95.   ota.checkAndPerformOTA();
  96.   #endif
  97. }
  98.  
  99. void onButtonPressed()
  100. {
  101.   Serial.println("Button pressed (A0) - debounced.");
  102.   performOTAIfConfigured();
  103. }
  104.  
  105. void performOTAIfConfigured()
  106. {
  107.   #if POTA_AVAILABLE && SECRETS_AVAILABLE
  108.   Serial.println("Starting OTA check (POTA)...");
  109.   ota.checkAndPerformOTA();
  110.   #else
  111.   Serial.println("OTA not configured. Include POTA.h and secrets.h to enable OTA.");
  112.   #endif
  113. }
  114.  
  115. /* END CODE */
  116.  
Advertisement
Add Comment
Please, Sign In to add comment