Slightly more robust wifi initialisation. Also set country code.
This commit is contained in:
		
							parent
							
								
									5664ee4acd
								
							
						
					
					
						commit
						268fd9986d
					
				
					 4 changed files with 30 additions and 4 deletions
				
			
		| 
						 | 
					@ -2,14 +2,19 @@
 | 
				
			||||||
#include "Wifi.h"
 | 
					#include "Wifi.h"
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <esp_err.h>
 | 
				
			||||||
 | 
					#include <esp_wifi.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool WatchFeatures::Wifi::Connect()
 | 
					bool WatchFeatures::Wifi::Connect()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (WiFi.begin(WIFI_SSID, WIFI_PASS) == WL_CONNECT_FAILED) {
 | 
					  WiFi.mode(WIFI_STA);
 | 
				
			||||||
 | 
					  auto status = WiFi.begin(WIFI_SSID, WIFI_PASS);
 | 
				
			||||||
 | 
					  if (status == WL_CONNECT_FAILED) {
 | 
				
			||||||
    WiFi.mode(WIFI_OFF);
 | 
					    WiFi.mode(WIFI_OFF);
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
 | 
					  if(WiFi.waitForConnectResult(5000) != WL_CONNECTED) {
 | 
				
			||||||
    WiFi.mode(WIFI_OFF);
 | 
					    WiFi.mode(WIFI_OFF);
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -19,10 +24,28 @@ bool WatchFeatures::Wifi::Connect()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WatchFeatures::Wifi::Disconnect()
 | 
					void WatchFeatures::Wifi::Disconnect()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  WiFi.mode(WIFI_OFF);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool WatchFeatures::Wifi::IsConnected()
 | 
					bool WatchFeatures::Wifi::IsConnected()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WatchFeatures::Wifi::InitBoot()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  WiFi.mode(WIFI_OFF);
 | 
				
			||||||
 | 
					  WiFi.persistent(false);        // prevent the flash storage WiFi credentials
 | 
				
			||||||
 | 
					  WiFi.setAutoReconnect(false);  // Set whether module will attempt to reconnect to an access point in case it is disconnected
 | 
				
			||||||
 | 
					  WiFi.softAPdisconnect(false);  // kill rogue AP on startup
 | 
				
			||||||
 | 
					  WiFi.disconnect(true);
 | 
				
			||||||
 | 
					  WiFi.mode(WIFI_STA);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  char country[3];
 | 
				
			||||||
 | 
					  esp_wifi_get_country_code(country);
 | 
				
			||||||
 | 
					  country[2] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (strcmp(country, WIFI_COUNTRY_CODE) != 0) {
 | 
				
			||||||
 | 
					    esp_wifi_set_country_code(WIFI_COUNTRY_CODE, true);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -8,5 +8,6 @@ namespace WatchFeatures
 | 
				
			||||||
    bool Connect();
 | 
					    bool Connect();
 | 
				
			||||||
    void Disconnect();
 | 
					    void Disconnect();
 | 
				
			||||||
    bool IsConnected();
 | 
					    bool IsConnected();
 | 
				
			||||||
 | 
					    void InitBoot();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -134,9 +134,9 @@ void Watchy::InitBootInternal()
 | 
				
			||||||
  m_display.epd2.selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0));
 | 
					  m_display.epd2.selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0));
 | 
				
			||||||
  m_display.init(0, g_displayFullInit, 10, true);
 | 
					  m_display.init(0, g_displayFullInit, 10, true);
 | 
				
			||||||
  SetBusyCallback(); 
 | 
					  SetBusyCallback(); 
 | 
				
			||||||
 | 
					 | 
				
			||||||
  BmaConfig();
 | 
					  BmaConfig();
 | 
				
			||||||
  m_features.storage.InitBoot();
 | 
					  m_features.storage.InitBoot();
 | 
				
			||||||
 | 
					  m_features.wifi.InitBoot();
 | 
				
			||||||
  InitBoot();
 | 
					  InitBoot();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,8 @@
 | 
				
			||||||
#define DEFAULT_LONGITUDE 24.9375
 | 
					#define DEFAULT_LONGITUDE 24.9375
 | 
				
			||||||
#define DEFAULT_CITY_NAME "Helsinki"
 | 
					#define DEFAULT_CITY_NAME "Helsinki"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define WIFI_COUNTRY_CODE "FI"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "secrets.h"
 | 
					#include "secrets.h"
 | 
				
			||||||
#if !defined(WIFI_SSID) || !defined(WIFI_PASS)
 | 
					#if !defined(WIFI_SSID) || !defined(WIFI_PASS)
 | 
				
			||||||
#error "Please define WIFI_SSID and WIFI_PASS in secrets.h"
 | 
					#error "Please define WIFI_SSID and WIFI_PASS in secrets.h"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue