Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static IP config option to IRMQTTServer #480

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/IRMQTTServer/IRMQTTServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,19 @@
#define IR_LED 4
// define IR_LED 3 // For an ESP-01 we suggest you use RX/GPIO3/Pin 7.
#define HTTP_PORT 80 // The port the HTTP server is listening on.
#define HOSTNAME "ir_server" // Name of the device you want in mDNS.
// Name of the device you want in mDNS.
// NOTE: Changing this will change the MQTT path too unless you override it
// via MQTTprefix below.
#define HOSTNAME "ir_server"

// We obtain our network config via DHCP by default but allow an easy way to
// use a static IP config.
#define USE_STATIC_IP false // Change to 'true' if you don't want to use DHCP.
#if USE_STATIC_IP
const IPAddress kIPAddress = IPAddress(10, 0, 1, 78);
const IPAddress kGateway = IPAddress(10, 0, 1, 1);
const IPAddress kSubnetMask = IPAddress(255, 255, 255, 0);
#endif // USE_STATIC_IP

#ifdef MQTT_ENABLE
// Address of your MQTT server.
Expand Down Expand Up @@ -832,6 +844,10 @@ void setup_wifi() {
// We start by connecting to a WiFi network

wifiManager.setTimeout(300); // Time out after 5 mins.
#if USE_STATIC_IP
// Use a static IP config rather than the one supplied via DHCP.
wifiManager.setSTAStaticIPConfig(kIPAddress, kGateway, kSubnetMask);
#endif // USE_STATIC_IP
if (!wifiManager.autoConnect()) {
debug("Wifi failed to connect and hit timeout.");
delay(3000);
Expand Down