#include "configuration.h"
#include "defines.h"

#include <stdint.h>
#include <Wire.h>  
#include "HT_SSD1306Wire.h"

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>

SSD1306Wire  confDisplay(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED);; // addr , freq , i2c group , resolution , rst

const char *ssid = "ModbusLoraConf";
char password[12];


void configurationSetup() {
	digitalWrite(Vext,LOW);
	confDisplay.init();
	confDisplay.setFont(ArialMT_Plain_10);
	confDisplay.setTextAlignment(TEXT_ALIGN_LEFT);
	confDisplay.clear();
	confDisplay.drawString(1, 1, "Configuration Mode starting");
	confDisplay.display();

    memset(password, 0, sizeof(password));
    for (int i = 0; i < sizeof(password) - 1; i++) {
        password[i] = random(65, 90);
    }

    WiFi.softAP(ssid, password);
    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);
    char buf[64];
    memset(buf, 0, sizeof(buf));
    sprintf(buf, "SSID: %s", ssid);
    confDisplay.drawString(1, 15, buf);
    memset(buf, 0, sizeof(buf));
    sprintf(buf, "Key: %s", password);
    confDisplay.drawString(1, 30, buf);
    confDisplay.display();


	delay(2000);

}


void configurationLoop() {

}