Skip to content

Commit a33fbe5

Browse files
committed
The big 2025 revspace network reconfiguration update
1 parent e17d266 commit a33fbe5

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.h

config.h.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define WIFI_SSID "revspace-dingen"
2+
#define WIFI_PASS "..."

esp8266-hoofdruimte/src/main.ino

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#include <WiFiUdp.h>
1010
#include <WiFiClient.h>
1111

12-
#include <PubSubClient.h> //https://github.com/knolleary/pubsubclient/releases/tag/2.4
12+
#include <PubSubClient.h> //https://github.com/knolleary/pubsubclient/
13+
14+
#include "../../config.h"
15+
#define HOSTNAME "lightstate-hoofdruimte"
1316

1417
void onMqttMessage(char* topic, byte * payload, unsigned int length);
1518
boolean reconnect();
@@ -20,12 +23,8 @@ boolean reconnect();
2023
#define LIGHTSTATE_R_PIN D1
2124
#define LIGHTSTATE_R_TOPIC "revspace/lightstate/hoofdruimte_bar/set"
2225

23-
// WiFi settings
24-
char ssid[] = "revspace-pub-2.4ghz"; // your network SSID (name)
25-
char pass[] = ""; // your network password
26-
2726
// MQTT Server settings and preparations
28-
const char* mqtt_server = "10.42.42.1";
27+
const char* mqtt_server = "mosquitto.space.revspace.nl";
2928
WiFiClient espClient;
3029

3130
PubSubClient client(mqtt_server, 1883, onMqttMessage, espClient);
@@ -56,8 +55,10 @@ void setup() {
5655

5756

5857
Serial.print("Connecting to ");
59-
Serial.print(ssid);
60-
WiFi.begin(ssid, pass);
58+
Serial.print(WIFI_SSID);
59+
60+
WiFi.hostname(HOSTNAME);
61+
WiFi.begin(WIFI_SSID, WIFI_PASS);
6162

6263
while (WiFi.status() != WL_CONNECTED) {
6364
delay(50);
@@ -70,11 +71,14 @@ void setup() {
7071
Serial.print("IP address: ");
7172
Serial.println(WiFi.localIP());
7273

74+
Serial.print("Hostname and MQTT id: ");
75+
Serial.println(HOSTNAME);
76+
7377
reconnect();
7478
}
7579

7680
boolean reconnect() {
77-
if (client.connect("lightstate-hoofdruimte")) {
81+
if (client.connect(HOSTNAME)) {
7882
client.subscribe(LIGHTSTATE_L_TOPIC);
7983
client.subscribe(LIGHTSTATE_R_TOPIC);
8084
client.loop();

esp8266-other/src/main.ino

+15-9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
#include <WiFiUdp.h>
1010
#include <WiFiClient.h>
1111

12-
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/2.4
12+
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient
1313

14-
boolean reconnect();
14+
#include "../../config.h"
1515

16-
// WiFi settings
17-
char ssid[] = "revspace-pub-2.4ghz"; // your network SSID (name)
18-
char pass[] = ""; // your network password
16+
boolean reconnect();
1917

2018
// MQTT Server settings and preparations
2119
const char* mqtt_server = "mosquitto.space.revspace.nl";
@@ -32,8 +30,10 @@ void setup() {
3230

3331

3432
Serial.print("Connecting to ");
35-
Serial.print(ssid);
36-
WiFi.begin(ssid, pass);
33+
Serial.print(WIFI_SSID);
34+
35+
WiFi.hostname("lightstate-" ROOM);
36+
WiFi.begin(WIFI_SSID, WIFI_PASS);
3737

3838
while (WiFi.status() != WL_CONNECTED) {
3939
delay(50);
@@ -46,14 +46,20 @@ void setup() {
4646
Serial.print("IP address: ");
4747
Serial.println(WiFi.localIP());
4848

49-
Serial.print("MQTT name: ");
49+
Serial.print("Hostname and MQTT id: ");
5050
Serial.println("lightstate-" ROOM);
51+
52+
reconnect();
5153
}
5254

5355
boolean reconnect() {
5456
client.setKeepAlive(5);
5557
if (client.connect("lightstate-" ROOM, NULL, NULL, "revspace/lightstate/" ROOM, 0, true, "off")) {
56-
client.publish("revspace/lightstate/" ROOM, "on", true);
58+
if (client.publish("revspace/lightstate/" ROOM, "on", true)) {
59+
Serial.println("publish succesful, yay!");
60+
} else {
61+
Serial.println("publish failed :(");
62+
}
5763
client.loop();
5864
}
5965
return client.connected();

0 commit comments

Comments
 (0)