 #define HC_05_PWR2            6
 
 #define DHT_PIN 7
+#define ONE_WIRE_BUS 9
 
-#define CMD_W                 1100 // msec
+#define LOOP_TIME                 1000 // msec
 
 #define msg(x) Serial.println(x)
 
-const int board = 0; // 0 -- for outdoor, 1 -- indor module
-
 SoftwareSerial BTSerial(HC_05_TXD_ARDUINO_RXD, HC_05_RXD_ARDUINO_TXD); // RX | TX
 DHT dht(DHT_PIN, DHT22);
-
-
-enum BTDeviceState {
-  error = -2,
-  off = -1,
-  data = 0,
-  at = 1,
-};
-
-class BTDevice 
-{
-private:
-  BTDeviceState m_state;
-  
-public:
-  BTDevice(): m_state(off) {  };
-
-  void setState(BTDeviceState state) {
-    if (m_state == state) {
-      msg("try to set BT to the same state " + state);
-      
-      return;
-    }
-    switch (state) {
-      case off: {
-        
-        msg("Power off");
-        digitalWrite(HC_05_PWR1, LOW);
-        digitalWrite(HC_05_PWR2, LOW);  
-        delay(CMD_W);
-        m_state = off;
-        return;        
-      }
-      case data: {
-        if (m_state == off) {
-          digitalWrite(HC_05_SETUPKEY, LOW);  // Set command mode when powering up
-          delay(CMD_W);       
-          digitalWrite(HC_05_PWR1, HIGH);
-          digitalWrite(HC_05_PWR2, HIGH);  
-          delay(CMD_W);
-                    
-          m_state = data;
-          return;        
-        }
-      }
-      case at: {
-        if (m_state == off) {
-          digitalWrite(HC_05_SETUPKEY, HIGH);  // Set command mode when powering up
-          delay(CMD_W);       
-          digitalWrite(HC_05_PWR1, HIGH);
-          digitalWrite(HC_05_PWR2, HIGH);  
-          delay(CMD_W);        
-
-          m_state = at;
-          return;
-        }
-        
-      }
-      
-    }
-  };
-
-  BTDeviceState state() {return m_state;};
-  
-};
-
-/*
-void BTDevice::initPins() {
-  pinMode(HC_05_SETUPKEY, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
-  pinMode(HC_05_PWR1, OUTPUT);      // Connect in parallel to HC-05 VCC
-  pinMode(HC_05_PWR2, OUTPUT);      // Connect in parallel to HC-05 VCC
-};
-*/
-
-BTDevice *bt = new BTDevice();
-
+OneWire oneWire(ONE_WIRE_BUS);
+DallasTemperature sensors(&oneWire);
 SFE_BMP180 pressure;
 
-void setup()   /****** SETUP: RUNS ONCE ******/
+void setup() 
 {
 
   pinMode(HC_05_SETUPKEY, OUTPUT);  


void loop()
{
  int btIn = -1;

  if (BTSerial.available() && (btIn = BTSerial.read()) ) {
    Serial.write(btIn);
  }

  if (Serial.available()) {
    char inChar = (char)Serial.read();

    if (inChar == '*') {
      bt->setState(off);
      bt->setState(data);
    }
    if (inChar == '?') {
      bt->setState(off);
      bt->setState(at);
    }
    
    String fromSerialStr = String(inChar);
    
    BTSerial.write(fromSerialStr.c_str());
    Serial.write(fromSerialStr.c_str());
    //BTSerial.print(fromSerialStr);
    //Serial.print(fromSerialStr);
  }


  v0 = analogRead(A0);
  v1 = analogRead(A1);
  v2 = analogRead(A2);

  d10 = digitalRead(10);
  d8 = digitalRead(8);

  float h = dht.readHumidity();
  float t = dht.readTemperature();

  getPT(P, T);
  
  sensors.requestTemperatures();
  float tX = sensors.getTempCByIndex(0);

  unsigned long CurrentTime = millis();
  unsigned long ElapsedTime = CurrentTime - StartTime;
  unsigned long dt = ElapsedTime > LOOP_TIME ? 0 : LOOP_TIME - ElapsedTime;

  bt_echo_send("(")
  fbt_echo_send(cnt); 
  fbt_echo_send(v0); 
  fbt_echo_send(tX);
  fbt_echo_send(t);
  fbt_echo_send(v1); 
  fbt_echo_send(d8);
  fbt_echo_send(d10);
  fbt_echo_send(T);
  fbt_echo_send(P);
  fbt_echo_send(h);
  fbt_echo_send(dt);
  bt_echo_send(")");

  bt_echo_send("\r\n");
  
  delay(dt);

  cnt++;
}

