Hcsr ultrasonic and nodemcu

I use nodemcu and ultrasonic sensor for get water level in tank.i power off the whole system.when power off node not connected to wifi router.when i remove the echo pin and trig pin from node and reset the board from rest button after that it connected to router.how to solve without removing the echo and trig pin?and also i need to change the height of level how i change that?and also i need to add water tank widget to show the level like a graphic view how to do that?

Code is here

/#define CAYENNE_DEBUG
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid = “#####”;
char wifiPassword = “######”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “########”;
char password = “##########”;
char clientID = “############”;

unsigned long lastMillis = 0;

// defines pins numbers

const int trigPin = 2; //D4
const int echoPin = 0; //D3

// defines variables
long duration;
int distance;
int y;

void setup() {
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}

void loop() {
Cayenne.loop();

// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
y = map(distance, 95, 10, 0, 100);
y = constrain(y, 0, 100);
delay(500);
if (millis() - lastMillis > 10000) {
lastMillis = millis();
Cayenne.virtualWrite(10, distance);
Cayenne.virtualWrite(13, y, “t1”, “null”);
}
}

do not create multiple posts on same topic.

Sorry.i couldnt troubleshoot my problem.pls help me to solve this