Browse Source

connect to wifi

master
n0m1s 6 years ago
parent
commit
478efbef5f
3 changed files with 45 additions and 0 deletions
  1. +6
    -0
      lamp.ino
  2. +19
    -0
      wifi.cpp
  3. +20
    -0
      wifi.h

+ 6
- 0
lamp.ino View File

@ -1,6 +1,8 @@
#include "settings.h" #include "settings.h"
#include "wifi.h"
Settings const* settings = nullptr; Settings const* settings = nullptr;
Wifi * wifi = nullptr;
bool ok = true; bool ok = true;
@ -18,8 +20,12 @@ void setup() {
} }
else else
Serial.println(" OK"); Serial.println(" OK");
wifi = new Wifi(settings->wifi);
} }
void loop() { void loop() {
if(!ok) {delay(3600000); return;} if(!ok) {delay(3600000); return;}
wifi->keep_alive_connection();
} }

+ 19
- 0
wifi.cpp View File

@ -0,0 +1,19 @@
#include "wifi.h"
Wifi::Wifi(WifiSettings const& settings):
m_wifi()
{
for(auto it = settings.networks_cbegin(); it != settings.networks_cend(); it = it->next())
m_wifi.addAP(it->ssid(), it->pass());
Serial.setDebugOutput(true);
}
void Wifi::keep_alive_connection()
{
m_wifi.run();
}
void Wifi::is_connected() const
{
return m_wifi.status() == WL_CONNECTED;
}

+ 20
- 0
wifi.h View File

@ -0,0 +1,20 @@
#ifndef WIFI_H
#define WIFI_H
#include <ESP8266WiFiMulti.h>
#include "wifi_settings.h"
class Wifi
{
public:
Wifi(WifiSettings const& settings);
void keep_alive_connection();
bool is_connected() const;
protected:
ESP8266WiFiMulti m_wifi;
};
#endif //WIFI_H

Loading…
Cancel
Save