Skip to content

Commit

Permalink
Fixed hostname setting for ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
forkineye committed Sep 28, 2021
1 parent f5bb0a2 commit e929332
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool deserializeCore (JsonObject & json)

do // once
{
uint8_t TempVersion;
uint8_t TempVersion = 0;
setFromJSON (TempVersion, json, CN_cfgver);
if (TempVersion != CurrentConfigVersion)
{
Expand Down
2 changes: 0 additions & 2 deletions ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
#if defined(ARDUINO_ARCH_ESP8266)
# include <ESP8266WiFi.h>
# include <ESPAsyncTCP.h>
# include <ESP8266mDNS.h>
# include <ESPAsyncUDP.h>
#elif defined(ARDUINO_ARCH_ESP32)
# include <AsyncTCP.h>
# include <AsyncUDP.h>
# include <ESPmDNS.h>
# include <WiFi.h>
#else
# error "Unsupported CPU type"
Expand Down
2 changes: 2 additions & 0 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void c_WebMgr::init ()
});

// JSON Config Handler
//TODO: This is only being used by FPP to get the hostname. Will submit PR to change FPP and remove this
// https://github.com/FalconChristmas/fpp/blob/ae10a0b6fb1e32d1982c2296afac9af92e4da908/src/NetworkController.cpp#L248
webServer.on ("/conf", HTTP_GET, [this](AsyncWebServerRequest* request)
{
// DEBUG_V (CN_Heap_colon + String (ESP.getFreeHeap ()));
Expand Down
16 changes: 13 additions & 3 deletions ESPixelStick/src/WiFiMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,24 @@ void c_WiFiMgr::connectWifi (const String & ssid, const String & passphrase)
if (ResetWiFi)
return;

// disconnect just in case
// Hostname must be set after the mode on ESP8266 and before on ESP32
#ifdef ARDUINO_ARCH_ESP8266
WiFi.disconnect ();

// Switch to station mode
WiFi.mode (WIFI_STA);
// DEBUG_V ("");

// DEBUG_V (String ("config->hostname: ") + config->hostname);
if (0 != config->hostname.length ())
{
// DEBUG_V (String ("Setting WiFi hostname: ") + config->hostname);
WiFi.hostname (config->hostname);
}
#else
WiFi.persistent (false);
// DEBUG_V ("");
WiFi.disconnect (true);
#endif
// DEBUG_V ("");

// DEBUG_V (String ("config->hostname: ") + config->hostname);
if (0 != config->hostname.length ())
Expand All @@ -178,6 +187,7 @@ void c_WiFiMgr::connectWifi (const String & ssid, const String & passphrase)
// Switch to station mode
WiFi.mode (WIFI_STA);
// DEBUG_V ("");
#endif

logcon (String(F ("WiFi Connecting to '")) +
ssid +
Expand Down
3 changes: 2 additions & 1 deletion ESPixelStick/src/service/fseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ struct FSEQRangeEntry

} __attribute__ ((packed));

// https://github.com/FalconChristmas/fpp/blob/master/docs/FSEQ_Sequence_File_Format.txt
struct FSEQHeader
{
uint8_t header[4]; // FSEQ
uint8_t header[4]; // PSEQ
uint16_t dataOffset;
uint8_t minorVersion;
uint8_t majorVersion;
Expand Down

0 comments on commit e929332

Please sign in to comment.