 
 #include "wifi_creds.h"
 
-#define DHTPIN            D5         // Pin which is connected to the DHT sensor.
-#define DHTTYPE           DHT11      // DHT 11 
-
-DHT_Unified dht(DHTPIN, DHTTYPE);
-U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
-#define SCREEN_WIDTH 128
-#define SCREEN_HEIGHT 32
-
-static char sensor_buffer[] = "TT,YY";
-String postData = String("temperature=");
-
-HTTPClient http;
-String localIP;
-
 #define FINAL 0
 
 #if FINAL


	dht.begin();
	u8g2.begin();
	checkWiFi();
	/*
	while (WiFi.status() != WL_CONNECTED)
	{
		Serial.print(".");
		delay(500);
	}
	*/
}

void button_pressed() {

#define DEBUG_PRINT(...)	Serial.print(__VA_ARGS__)
#endif

static unsigned int const DHTPIN = D5;      // Pin which is connected to the DHT sensor.
static unsigned int const DHTTYPE = DHT11;      // DHT 11 

DHT_Unified dht(DHTPIN, DHTTYPE);
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

String postData = String("temperature=");

HTTPClient http;

static const uint8_t WIFI_FRAMES[5][8] = {
	0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,
	0x0,0x0,0x0,0x0,0x4,0x4,0x5,0x5,
	0x0,0x0,0x10,0x10,0x14,0x14,0x15,0x15,
	0x40,0x40,0x50,0x50,0x54,0x54,0x55,0x55,
	0x40,0x40,0x40,0x51,0x4a,0x44,0x4a,0x51,
};

class WiFiConnection
{
public:

	WiFiConnection() : lastWiFiBegin(0) {}

	void checkWiFi()
	{
		if (WiFi.status() != WL_CONNECTED)
		{
			DEBUG_PRINTLN("Connecting...");
			if (lastWiFiBegin == 0 || (millis() - lastWiFiBegin > INTERVAL_BETWEEN_CONNECT_MS))
			{
				WiFi.begin(WIFI_NAME, WIFI_PASS);
				lastWiFiBegin = millis();
			}
			localIP = "No connection.";
			Serial.println(WiFi.status());
		}
		else
		{
			localIP = WiFi.localIP().toString();
			long rssi = WiFi.RSSI();
			Serial.print("RSSI:");
			Serial.println(rssi);
		}
	}

	const bool isConnected()
	{
		return WiFi.status() == WL_CONNECTED;
	}

	const String& getPublicIP()
	{
		return localIP;
	}

	const unsigned int getSignalStrength()
	{
		if (isConnected())
		{
			if (WiFi.RSSI() > -100)
				return (100 + WiFi.RSSI()) * 5 / 100;
			else
				return 0;
		}
		else
		{
			return 0;
		}
	}

private:
	unsigned long lastWiFiBegin;
	String localIP;
	static unsigned long const INTERVAL_BETWEEN_CONNECT_MS = 5000;
};

WiFiConnection wifiConnection;

void setup()
{
