Cellular Network Unhealthy

I flashed the code again - which I had done multiple times last night so a bit confused as it now seems to working. Stupidly I unplugged the power supply to see if that was the issue - which made two changes at once. I should have not done both at once but I did plug power supply back in and it seems to be still working. So perhaps for some reason though it has said the code was flashed successfully it was not.
Here is the code.
To see if it flashed correctly I added a duplicate temperature to send to ThingSpeak to see if it flashed correctly and ThingSpeak is getting the new variable.

I will let this run and increase the interval later in the day to see if it works.

If the Electron is in System.Sleep mode I assume you can not flash code. I have been sending code either near the time it is connecting (flashing green) or put in Safe Mode and re- flash. Is this a correct assumption? When I get this works it will be sitting in a building across town. How do you flash it if not in physical proximity?]
Thanks.

Here is the code…


// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// Sensor type
#define DHTTYPE DHT22    	// DHT 22 (AM2302)

// DHT22 sensor pinout:
// Pin 1 (on the left): +3.3V
// Pin 2: output
// Pin 4 (on the right): GROUND
#define DHT_5V_PIN D1
#define DHT_SENSOR_PIN D2
#define DHT_GROUND_PIN D4

DHT dht(DHT_SENSOR_PIN, DHTTYPE);

/* Thingspeak */
TCPClient client;
unsigned long myChannelNumber = *****;
const char * myWriteAPIKey = "******";

//set timer soft delay

inline void softDelay(uint32_t t) {
  for(uint32_t ms = millis(); millis() - ms < t; Particle.process());

}
void setup() {
    
//line 34 5o 36  added in order to make sure cellular module working see https://community.particle.io/t/cellular-network-unhealthy/47802/6
  Cellular.on(); // just to be on the safe side due to open issue
  Cellular.connect();
  if (waitFor(Cellular.ready, 300000)) { // wait up to 5 minutes for the connection to establish

    // Connect to ThingSpeak
    ThingSpeak.begin(client);

    // Give power to the sensor
    pinMode(DHT_5V_PIN, OUTPUT);
    pinMode(DHT_GROUND_PIN, OUTPUT);
    digitalWrite(DHT_5V_PIN, HIGH);
    digitalWrite(DHT_GROUND_PIN, LOW);

    // Wait for the sensor to stabilize
    softDelay(5000);



    // Initialize sensor
    dht.begin();

    // Read Sensor
    double temperature = dht.getTempCelcius();
    double humidity = dht.getHumidity();
    //Temperature here to see if code was upated being sent to ThinkSpeak
    double temperature2 = dht.getTempCelcius();



    // Update the 2 ThingSpeak fields with the new data
    ThingSpeak.setField(1, (float)temperature);
    ThingSpeak.setField(2, (float)humidity);
    ThingSpeak.setField(3, (float)temperature2);

    // Write the fields that you've set all at once.
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    
     // Give time for the message to reach ThingSpeak
     softDelay(5000);
  }
    
    
  

    // Sleep for 15 changed to a minute save data costs, 15 gives a 20 minute interval.
    //Change back to 15 and see what that gives 02212019 change to 10 to test sleep not messing up connections
    //Line 81 to 82 added for cellular potential see link lin 33
    Cellular.off();
    for(uint32_t ms = millis(); millis() - ms < 500; Particle.process());
    System.sleep(SLEEP_MODE_DEEP, 10 * 60);
}

void loop() {
    // This will run because the system is sleeping
      
}