ESP8266 12F sudden failure to connect to any access point.

Hello, I’ve had my ESP8266 running all fine reading from an I2C connected “LIPO FUELGAUGE” module and a light sensor via ESP analog port for a day or so and it connected to my webspace and uploaded the readings to a log file.
yesterday it stopped logging so I went out and found that the ESP was slightly warm. I disconnected and reastarted it and it worked for one data sample then stopped.
Its refused to connect to the router and my phone set as an access point (worked fine before). I therefore assumed it was damaged in some way. So I got another new one out and connected that up.
well that one doesnt work either. Im at a loss as to what has happened.
Power supply is good , Ive had power problems before but this is different. the unit powers up and outputs my crude debuging info to the serial port but it just refuses to do any WIFI magic.
Ive included my shoddy program below for a laugh.
Can anyone tell me what Im doing wrong? I just don’t get it as it had been working fine and now nothing on two units!

#include “MAX17043.h”
#include “Wire.h”
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
MAX17043 batteryMonitor;
String stringone, stringtwo, stringthree, stringfour, stringfive, payload1, payload2;
int sensorPin = A0; // select the input pin for the potentiometer

void setup() {
pinMode(A0, INPUT);
Wire.pins(4,5);
Wire.begin();
Serial.begin(115200);
Serial.println("\n\r MAX17043 Example: reading voltage and SoC /n/r");
Serial.println();

batteryMonitor.reset();
batteryMonitor.quickStart();
delay(1000);

float cellVoltage = batteryMonitor.getVCell();
Serial.print(“Voltage:\t\t”);
Serial.print(cellVoltage, 4);
Serial.println(“V”);

float stateOfCharge = batteryMonitor.getSoC();
Serial.print(“State of charge:\t”);
Serial.print(stateOfCharge);
Serial.println("%");

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t–) {
USE_SERIAL.printf("[SETUP] WAIT %d… \n\r", t);
USE_SERIAL.flush();
delay(1000);
}
USE_SERIAL.printf(“Connecting…\n\r”);
// BELOW ARE LINES OF CODE SUGGESTED BY VARIOUS FORUMS TO WAKE THE MODULE UP. BUT THEY DONT MAKE ANY DIFFERENCE.
// WiFi.mode(WIFI_AP_STA);
// wifi_station_connect();

// WiFi.forceSleepWake();
// WiFi.mode(WIFI_STA);
// wifi_station_connect();
// WiFi.begin(“SSID”, “PASSWORD”);

WiFiMulti.addAP(“SSID”, “PASSWORD”);
USE_SERIAL.printf(“Should be connected now \n\r”);
// wait for WiFi connection

if((WiFiMulti.run() == WL_CONNECTED))
{
USE_SERIAL.printf(“Connected”);
HTTPClient http;
int sensorValue = analogRead(A0);
int finalvalue = 0;
int averagevalue = 0;
USE_SERIAL.printf(“SensorValue %d sent to webpage. \n\r”, sensorValue);
USE_SERIAL.printf("\n\r");

USE_SERIAL.flush();
stringone = “http://www.MYWEBSPACE/test01.php?SOC=”;
stringtwo = stringone + stateOfCharge; // two = http://www.MYWEBSPACE/test01.php?SOC=12.34
stringthree = “&LIGHT=”; //three = &LIGHT=
stringfour = stringtwo + stringthree; // four = http://www.MYWEBSPACE/test01.php?SOC=12.34&LIGHT=
stringfive = stringfour + sensorValue; // five = http://www.MYWEBSPACE/test01.php?SOC=12.34&LIGHT=1024

USE_SERIAL.printf(“HTTP to send = “);
USE_SERIAL.println(stringfive);
USE_SERIAL.printf(”\n\r”);

http.begin(stringfive); //HTTP
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
USE_SERIAL.printf(“HTTP header sent and responce handled \n\r”);
// HTTP header has been send and Server response header has been handled
// file found at server
if(httpCode == HTTP_CODE_OK) {
USE_SERIAL.printf(“Getting responce back from php script \n\r”);
// Get responce back from .php script and display (Data added ##### times to the log) or similar.
String payload1 = http.getString();
USE_SERIAL.println(payload1);
USE_SERIAL.printf("\n\r");
}
} else
{
USE_SERIAL.printf(“Connection Failed”);
delay(5000);
}
// Fetch required delay in seconds stored in file Test_Sleep.txt
USE_SERIAL.printf(“getting sleep timer \n\r”);
stringthree = “http://www.MYWEBSPACE/Test_Sleep.txt”;
http.begin(stringthree); //HTTP
// start connection and send HTTP header
int httpCode1 = http.GET();
// httpCode will be negative on error
if(httpCode1 > 0) {
// HTTP header has been send and Server response header has been handled
// file found at server
if(httpCode1 == HTTP_CODE_OK) {
// Fetch ASCII text from above Test_Sleep.txt file into payload2
String payload2 = http.getString();
// Convert the ASCII pauload2 contents to Numeric value and store in variable paul
long paul = strtol(payload2.c_str() ,NULL ,10);

// USE_SERIAL.printf(“Sleeping for %d seconds”),paul; doing this way gives sleeping for 25 seconds? where is 25 from?
USE_SERIAL.printf(“Sleeping for %d seconds”, paul);
USE_SERIAL.printf("\n\r");
USE_SERIAL.println(payload2);
USE_SERIAL.printf("\n\r");
ESP.deepSleep(paul *1000 *1000, WAKE_RF_DEFAULT);
delay(1000);
}
} else
{
USE_SERIAL.printf(“Some sort of HTTP Error.”);
ESP.deepSleep(60 * 1000 * 1000, WAKE_RF_DEFAULT); //Send unit to sleep for 60 seconds, hopefully when it restarts we will be good.
delay(5000);
}
delay(5000);
}
USE_SERIAL.printf(“Failed to connect\r\n”);
USE_SERIAL.printf(“This didn’t used to happen but it fails now… weird \r\n”);
}
void loop() {
ESP.deepSleep(10 * 1000 * 1000, WAKE_RF_DEFAULT); //Send unit to sleep for 60 seconds, hopefully when it restarts we will be good.
}