[VicPiMakers Projects] Refactoring the AI way

George Bowden gtbowdeng at gmail.com
Tue Mar 11 19:34:18 PDT 2025


I was getting a lot of scope errors in my code, so I made my local
declarations global.  It compiled.  So I asked  Claude.Sonnet to refactor
the code, reducing the number of global variables.  Who knew refactoring is
this simple:
// Configuration struct to contain all WiFi related settings
struct Config {
  // Access Point settings
  const char* ap_ssid = "ESP32-Setup";
  const char* ap_password = "password123";  // Minimum 8 characters
  IPAddress local_ip{192, 168, 1, 1};
  IPAddress gateway{192, 168, 1, 1};
  IPAddress subnet{255, 255, 255, 0};

  // Station mode credentials
  String station_ssid = "";
  String station_password = "";
  bool credentialsUpdated = false;

  // EEPROM settings
  static const int EEPROM_SIZE = 512;
  static const int SSID_ADDR = 0;
  static const int PASS_ADDR = 100;
  static const int FLAG_ADDR = 200;

  // GPIO pins
  static const int redLed = 27;
  static const int yellowLed = 26;
  static const int inSwitch = 25;

  // Connection timeout (ms)
  static const int timeout = 30000;
};

// Single global instance for configuration
Config config;

-- 
George Bowden  250-893-7423
Victoria BC
No ChatGPT used
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://vicpimakers.ca/pipermail/projects_vicpimakers.ca/attachments/20250311/ca5c1f95/attachment.htm>


More information about the Projects mailing list