I was wondering how to keep from removing and adding my wifi credentials and IP addresses in my arduino projects. Paul pointed me towards using a header file.

Using PlatformIO, create the file at /project/include/secrets.h/ and enter:

#ifndef SECRETS
#define SECRETS

const char *ssid_name = "wifi network name";
const char *ssid_password = "wifi network password";
const char *rbp_ip = "ip address";

#endif

I’m not sure if a header guard is necessary here, but it seems like good practice. Don’t forget to add secrets.h to your .gitignore!

Then make the changes in your /project/src/main.cpp:

#include <Adafruit_GFX.h>
...
#include <PubSubClient.h>

#include "secrets.h"

// wifi credentials
const char *ssid = ssid_name;
const char *password = ssid_password;

// MQTT
WiFiClient espClient;
PubSubClient client(espClient);

const char *mqtt_server = rbp_ip;  // IP to broker (raspberry pi)

// screen pinout
#define TFT_CS  D0
#define TFT_RST D1
#define TFT_DC  D2
...