@@ -31,9 +31,7 @@ class ThingerWifiClient : public ThingerClient {
3131
3232public:
3333 ThingerWifiClient (const char * user, const char * device, const char * device_credential) :
34- ThingerClient (client_, user, device, device_credential),
35- wifi_ssid_ (NULL ),
36- wifi_password_ (NULL )
34+ ThingerClient (client_, user, device, device_credential)
3735 {}
3836
3937 ~ThingerWifiClient (){
@@ -48,15 +46,23 @@ class ThingerWifiClient : public ThingerClient {
4846
4947 virtual bool connect_network (){
5048 unsigned long wifi_timeout = millis ();
51- THINGER_DEBUG_VALUE (" NETWORK" , " Connecting to network " , wifi_ssid_);
5249
53- if (wifi_password_!=NULL ){
50+ if (wifi_ssid_!=nullptr ){
51+ THINGER_DEBUG_VALUE (" NETWORK" , " Connecting to network " , wifi_ssid_);
5452 WiFi.begin ((char *)wifi_ssid_, (char *) wifi_password_);
55- }else if (wifi_ssid_!=NULL ){
56- WiFi.begin ((char *)wifi_ssid_);
57- }else {
53+ }
54+ // espressif esp8266 and esp32 can connect to last network just with begin() (used with WiFiManager)
55+ #if defined(ESP8266) || defined(ESP32)
56+ else {
57+ THINGER_DEBUG (" NETWORK" , " Connecting to stored network" );
5858 WiFi.begin ();
5959 }
60+ #else
61+ else {
62+ THINGER_DEBUG (" NETWORK" , " Cannot connect to WiFi. SSID not set!" );
63+ return false ;
64+ }
65+ #endif
6066
6167 while ( WiFi.status () != WL_CONNECTED) {
6268 if (millis () - wifi_timeout > 30000 ) return false ;
@@ -80,16 +86,16 @@ class ThingerWifiClient : public ThingerClient {
8086
8187public:
8288
83- void add_wifi (const char * ssid, const char * password=NULL )
89+ void add_wifi (const char * ssid, const char * password=nullptr )
8490 {
8591 wifi_ssid_ = ssid;
8692 wifi_password_ = password;
8793 }
8894
8995protected:
9096 Client client_;
91- const char * wifi_ssid_;
92- const char * wifi_password_;
97+ const char * wifi_ssid_ = nullptr ;
98+ const char * wifi_password_ = nullptr ;
9399};
94100
95101#define ThingerWifi ThingerWifiClient<WiFiClient>
0 commit comments