Skip to content

Commit

Permalink
add 5m timeout to captive portal and reboot on timeout (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumnerboy12 authored Mar 26, 2023
1 parent 00cb721 commit 6654433
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
18 changes: 15 additions & 3 deletions src/OXRS_Rack32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,25 @@ void OXRS_Rack32::_initialiseNetwork(byte * mac)
// Ensure we are in the correct WiFi mode
WiFi.mode(WIFI_STA);

// We use WifiManager library from /~https://github.com/tzapu/WiFiManager
// to handle WiFi connection and credential persistence etc.
WiFiManager wm;

// If the captive portal is launched and nothing happens for a while then
// reboot - this helps if we come online before an AP (e.g. power outage)
// and prevents us sitting in captive portal mode indefinitely
wm.setConfigPortalTimeout(WM_CONFIG_PORTAL_TIMEOUT_S);

// Connect using saved creds, or start captive portal if none found
// NOTE: Blocks until connected or the portal is closed
WiFiManager wm;
bool success = wm.autoConnect("OXRS_WiFi", "superhouse");
if (!wm.autoConnect("OXRS_WiFi", "superhouse"))
{
_logger.println(F("[ra32] failed to connect to wifi access point, rebooting"));
ESP.restart();
}

_logger.print(F("[ra32] ip address: "));
_logger.println(success ? WiFi.localIP() : IPAddress(0, 0, 0, 0));
_logger.println(WiFi.localIP());
#else
_logger.print(F("[ra32] ethernet mac address: "));
_logger.println(mac_display);
Expand Down
23 changes: 13 additions & 10 deletions src/OXRS_Rack32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@
#include <OXRS_API.h> // For REST API
#include <OXRS_LCD.h> // For LCD runtime displays

// WifiManager
#define WM_CONFIG_PORTAL_TIMEOUT_S 300

// Ethernet
#define ETHERNET_CS_PIN 26
#define WIZNET_RESET_PIN 13
#define DHCP_TIMEOUT_MS 15000
#define DHCP_RESPONSE_TIMEOUT_MS 4000
#define ETHERNET_CS_PIN 26
#define WIZNET_RESET_PIN 13
#define DHCP_TIMEOUT_MS 15000
#define DHCP_RESPONSE_TIMEOUT_MS 4000

// I2C
#define I2C_SDA 21
#define I2C_SCL 22
#define I2C_SDA 21
#define I2C_SCL 22

// REST API
#define REST_API_PORT 80
#define REST_API_PORT 80

// Temperature update internal
#define DEFAULT_TEMP_UPDATE_MS 60000L
#define DEFAULT_TEMP_UPDATE_MS 60000L

// MCP9808 temperature sensor
#define MCP9808_I2C_ADDRESS 0x18
#define MCP9808_MODE 0
#define MCP9808_I2C_ADDRESS 0x18
#define MCP9808_MODE 0
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
Expand Down

0 comments on commit 6654433

Please sign in to comment.