text: 
  #include <Esp.h>
  #include <ESP8266WiFi.h>
  
  #include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
  #include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
  #include <WiFiManager.h>
  #include <FS.h>
  
  #include <ArduinoJson.h>
  #define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
  #define TIME_TO_SLEEP 5        /* Time ESP32 will go to sleep (in seconds) */ //deprecated now using 555
  #define SLEEPTIME uS_TO_S_FACTOR * TIME_TO_SLEEP
  
  
  
  //work on getting this from some kind of ap mode config
  char device_name[64] = "master-bedroom";
  char device_type[12] = "thermostat";
  
  String name_str(device_name);
  String type_str(device_type);
  
  bool shouldSaveConfig = false;
  
  //callback notifying us of the need to save config
  void saveConfigCallback () {
    Serial.println("Should save config");
    shouldSaveConfig = true;
  }
  
  void connectWifi(){
  
  
    Serial.println("mounting FS...");
  
      if (SPIFFS.begin()) {
        Serial.println("mounted file system");
        if (SPIFFS.exists("/config.json")) {
          //file exists, reading and loading
          Serial.println("reading config file");
          File configFile = SPIFFS.open("/config.json", "r");
          if (configFile) {
            Serial.println("opened config file");
            size_t size = configFile.size();
            // Allocate a buffer to store contents of the file.
            std::unique_ptr<char[]> buf(new char[size]);
  
            configFile.readBytes(buf.get(), size);
            DynamicJsonBuffer jsonBuffer;
            JsonObject& json = jsonBuffer.parseObject(buf.get());
            json.printTo(Serial);
            if (json.success()) {
              Serial.println("\nparsed json");
  
              strcpy(device_type, json["device_type"]);
              strcpy(device_name, json["device_name"]);
  
  
            } else {
              Serial.println("failed to load json config");
            }
            configFile.close();
          }
        }
      } else {
        Serial.println("failed to mount FS");
      }
      //end read
  
  
  
      // The extra parameters to be configured (can be either global or just in the setup)
      // After connecting, parameter.getValue() will get you the configured value
      // id/name placeholder/prompt default length
      WiFiManagerParameter device_type_param("device_type", "Device Code", device_type, 12);
      WiFiManagerParameter device_name_param("device_name", "Device Name", device_name, 64);
  
      //WiFiManager
      //Local intialization. Once its business is done, there is no need to keep it around
      WiFiManager wifiManager;
  
      //set config save notify callback
      wifiManager.setSaveConfigCallback(saveConfigCallback);
  
  
      //add all your parameters here
      wifiManager.addParameter(&device_type_param);
      wifiManager.addParameter(&device_name_param);
  
      //reset settings - for testing
      //wifiManager.resetSettings();
  
      //set minimu quality of signal so it ignores AP's under that quality
      //defaults to 8%
      //wifiManager.setMinimumSignalQuality();
  
      //sets timeout until configuration portal gets turned off
      //useful to make it all retry or go to sleep
      //in seconds
      //wifiManager.setTimeout(120);
  
      //fetches ssid and pass and tries to connect
      //if it does not connect it starts an access point with the specified name
      //here  "AutoConnectAP"
      //and goes into a blocking loop awaiting configuration
      if (!wifiManager.autoConnect("janky-home", "janky-pass")) {
        Serial.println("failed to connect and hit timeout");
        delay(3000);
        //reset and try again, or maybe put it to deep sleep
        ESP.reset();
        delay(5000);
      }
  
      //if you get here you have connected to the WiFi
      Serial.println("connected...yeey :)");
  
      //read updated parameters
      strcpy(device_type, device_type_param.getValue());
      strcpy(device_name, device_name_param.getValue());
      
      //save the custom parameters to FS
      if (shouldSaveConfig) {
        Serial.println("saving config");
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.createObject();
        json["device_type"] = device_type;
        json["device_name"] = device_name;
        
        File configFile = SPIFFS.open("/config.json", "w");
        if (!configFile) {
          Serial.println("failed to open config file for writing");
        }
  
        json.printTo(Serial);
        json.printTo(configFile);
        configFile.close();
        //end save
      }
  
      Serial.println("local ip");
      Serial.println(WiFi.localIP());
  
  
    
  
  
  
  
  
  }
  
  
  void disconnectAndSleep(){
    WiFi.disconnect( true );
    ESP.deepSleep( SLEEPTIME);
  
  }
  