Skip to content

Commit

Permalink
Moving WiFi credentials to dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisBrock committed Sep 14, 2024
1 parent 26e9a5e commit 59deb52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.vscode/launch.json
.vscode/ipch
/.vscode
src/Configuration/Credentials.cpp
10 changes: 4 additions & 6 deletions src/Components/WiFi/WifiConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#include <WiFi.h>
#include "../../Configuration/Constants.h"
#include "WifiConnection.h"
#include "../../Configuration/Credentials.h"

namespace WifiConnection
{
const char *ssid = "YourSSID";
const char *password = "YourPassword";

void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info)
{
Serial.println("Connected to AP successfully!");
Expand All @@ -26,7 +24,7 @@ namespace WifiConnection
Serial.print("WiFi lost connection. Reason: ");
Serial.println(info.wifi_sta_disconnected.reason);
Serial.println("Trying to reconnect");
WiFi.begin(ssid, password);
WiFi.begin(Credentials::WiFi_SSID, Credentials::WiFi_Password);
}

void Init()
Expand All @@ -43,7 +41,7 @@ namespace WifiConnection

// Start Wifi connection
Serial.print("Connecting WiFi, SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println(Credentials::WiFi_SSID);
WiFi.begin(Credentials::WiFi_SSID, Credentials::WiFi_Password);
}
};
8 changes: 8 additions & 0 deletions src/Configuration/Credentials.cpp.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <Arduino.h>
#include "Credentials.h"

namespace Credentials
{
const char *WiFi_SSID = "YourSSID";
const char *WiFi_Password = "YourPassword";
}
7 changes: 7 additions & 0 deletions src/Configuration/Credentials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace Credentials
{
extern const char* WiFi_SSID;
extern const char* WiFi_Password;
}

0 comments on commit 59deb52

Please sign in to comment.