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 <PubSubClient.h>
|
||||
|
||||
// Include any secrets.
|
||||
#include "window_control_secrets.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
|
||||
|
||||
// Include the settings.h.
|
||||
#include "window_control_settings.h"
|
||||
|
||||
#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 out_topic "/testing/out"
|
||||
|
@ -30,7 +21,7 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
setup_wifi();
|
||||
client.setClient(espClient);
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||
client.setCallback(callback);
|
||||
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
|
@ -44,13 +35,14 @@ void setup_wifi() {
|
|||
Serial.println();
|
||||
WiFi.hostname("ESP-" window_name);
|
||||
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) {
|
||||
delay(500);
|
||||
Serial.println("Not yet connected.. Waiting 500ms to check again..");
|
||||
delay(950);
|
||||
tone(2, 1200, 50);
|
||||
Serial.println("Not yet connected.. Waiting 1s to check again..");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
|
@ -64,7 +56,7 @@ void reconnect() {
|
|||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
|
||||
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
||||
Serial.println("connected");
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
|
@ -92,14 +84,18 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
// If we ever disconnect, reconnect.
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
|
||||
// Run the client loop
|
||||
client.loop();
|
||||
|
||||
// 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);
|
||||
client.subscribe(in_topic);
|
||||
client.subscribe(mqtt_root "/in");
|
||||
tone(2, 2000, 500);
|
||||
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