Make the secrets.h file more of a settings.h
This commit is contained in:
parent
74a5ff2d1a
commit
7ca6199fd6
|
@ -3,20 +3,11 @@
|
||||||
// Include the mqtt client lib
|
// Include the mqtt client lib
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
// Include any secrets.
|
// Include the settings.h.
|
||||||
#include "window_control_secrets.h"
|
#include "window_control_settings.h"
|
||||||
|
|
||||||
#define wifi_ssid SECRET_SSID
|
|
||||||
#define wifi_password SECRET_PASS
|
|
||||||
|
|
||||||
#define mqtt_server "mqtt.kitsunehosting.net"
|
|
||||||
#define mqtt_port 1883
|
|
||||||
#define mqtt_user SECRET_MQTT_USER
|
|
||||||
#define mqtt_password SECRET_MQTT_PASS
|
|
||||||
|
|
||||||
|
|
||||||
#define window_name "window_0"
|
#define window_name "window_0"
|
||||||
#define mqtt_root "/home/upstairs_lab/actuators/" window_name
|
#define mqtt_root "home/upstairs_lab/actuators/" window_name
|
||||||
|
|
||||||
#define in_topic "/testing/in"
|
#define in_topic "/testing/in"
|
||||||
#define out_topic "/testing/out"
|
#define out_topic "/testing/out"
|
||||||
|
@ -30,7 +21,7 @@ void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
client.setClient(espClient);
|
client.setClient(espClient);
|
||||||
client.setServer(mqtt_server, mqtt_port);
|
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
|
|
||||||
// initialize digital pin LED_BUILTIN as an output.
|
// initialize digital pin LED_BUILTIN as an output.
|
||||||
|
@ -44,13 +35,14 @@ void setup_wifi() {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
WiFi.hostname("ESP-" window_name);
|
WiFi.hostname("ESP-" window_name);
|
||||||
Serial.print("Connecting to ");
|
Serial.print("Connecting to ");
|
||||||
Serial.println(wifi_ssid);
|
Serial.println(WIFI_SSID);
|
||||||
|
|
||||||
WiFi.begin(wifi_ssid, wifi_password);
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(950);
|
||||||
Serial.println("Not yet connected.. Waiting 500ms to check again..");
|
tone(2, 1200, 50);
|
||||||
|
Serial.println("Not yet connected.. Waiting 1s to check again..");
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
@ -64,7 +56,7 @@ void reconnect() {
|
||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
Serial.print("Attempting MQTT connection...");
|
Serial.print("Attempting MQTT connection...");
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
|
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
|
@ -92,14 +84,18 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// If we ever disconnect, reconnect.
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run the client loop
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
// Publishes a random 0 and 1 like someone switching off and on randomly (random(2))
|
// Publishes a random 0 and 1 like someone switching off and on randomly (random(2))
|
||||||
client.publish(out_topic, String(random(2)).c_str(), true);
|
client.publish(mqtt_root "/random", String(random(2)).c_str(), true);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
client.subscribe(in_topic);
|
client.subscribe(mqtt_root "/in");
|
||||||
tone(2, 2000, 500);
|
tone(2, 2000, 500);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#define WIFI_SSID "muner"
|
||||||
|
#define WIFI_PASS "apollo11"
|
||||||
|
|
||||||
|
#define MQTT_SERVER "mqtt.kitsunehosting.net"
|
||||||
|
#define MQTT_PORT 1883
|
||||||
|
#define MQTT_USER "device"
|
||||||
|
#define MQTT_PASS "iamnotacrook"
|
Loading…
Reference in New Issue