 #include <EEPROM.h>
 
 // Update these with values suitable for your network.
+ESP8266WebServer server(80);
+IPAddress mqtt_server(192,168,0,100);
 
 String pointID;
 char red[5];
 const char* mqttUser = "mqttUser";
 const char* mqttPw = "mqttuser";
 const char* ssid = "test";
-const char* passphrase = "testpassword1";
+const char* passphrase = "testpassword";
 String esid;
 String epass = "";
 
 String st;
 String content;
 int statusCode;
-ESP8266WebServer server(80);
-IPAddress mqtt_server(192,168,0,100);
+
 
 WiFiClient espClient;
-//PubSubClient client(espClient);
 void callback(char* topic, byte* payload, unsigned int lent);
 PubSubClient client(mqtt_server, 1883, callback, espClient);
 long lastMsg = 0;

  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  pinMode(0, INPUT);
  reconnect();
  
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {

//  if (!client.connect("arduinoClient", "mqttUser", "mqttuse")) {
//    reconnect();
//  }
  if (!client.connected() && (WiFi.status() == WL_CONNECTED)) {
    Serial.println("rwwwiaiau");
    reconnect();
  }
  /*else
  {
     Serial.println("Connected to MQTT server ");
  }*/
  
  client.subscribe("inTopic");
  client.loop();
  
//   if (digitalRead(0)==false)
//  {
//    Serial.println("button pressed");
//    joinControlNet();
//    delay(250);
//  }

   if (digitalRead(0)==false){
    startTime=millis();  
    while (digitalRead(0)==false){
        timeHeld=millis()-startTime;
        Serial.print("Timeheld is: ");
        Serial.println(timeHeld);        
     }    
  }
  if (timeHeld>1000) {Serial.println("time is long time");setupAP();}
  if (timeHeld>50 && timeHeld<750) {Serial.println("time is good");joinControlNet();}
  timeHeld=0;
   
}

void setup() {
  Serial.begin(115200);
  EEPROM.begin(512);
  //pinMode(0, INPUT);
  pinMode(2, INPUT);
  WiFi.begin();
  delay(1000);
  Serial.println("");
  Serial.println("delay done");
  Serial.println(digitalRead(2));
   if (digitalRead(2)==false)
  { 
    Serial.println("button pressed at beginning");
    delay(250);
     if (digitalRead(2)==true)setupAP();
     while(1){server.handleClient();delay(10);}
    
  }
  else{
  Serial.println(""); 
  redEEPromRead();
  Serial.println("");
