     
 
     @IBAction func openButtonPressed(sender: UIButton) {
-        let rx = self.getRXCharacteristic()
-        if rx == nil { return }
-       
-        let peripheral = self.getActivePeripheral()
-        if peripheral == nil { return }
-        
-        if let pass = config.valueForKey("password") as? String {
-            var str = "0" + pass;
-            var data : NSData = str.dataUsingEncoding(NSUTF8StringEncoding)!
-        
-            peripheral?.writeValue(data, forCharacteristic: rx, type: CBCharacteristicWriteType.WithoutResponse)
-        } else {
-            println("Did not find valid password, so not writing anything")
-        }
-    }
-    
+        if self.currentState == States.Connected {
+            self.sendOpenCommand()
+            return
+        }
+        
+        if self.currentState == States.DeviceNotFound {
+            NSLog("GOOpener: button pressed: state: device not found")
+            if let discovery = self.discovery {
+                discovery.startScanning()
+            }
+            return
+        }
+    }
+    
+    
+    func sendOpenCommand() {
+        if let rx = self.getRXCharacteristic() {
+            if let peripheral = self.getActivePeripheral() {
+                if let pass = config.valueForKey("password") as? String {
+                    var str = "0" + pass;
+                    var data : NSData = str.dataUsingEncoding(NSUTF8StringEncoding)!
+                    
+                    peripheral.writeValue(
+                        data,
+                        forCharacteristic: rx,
+                        type: CBCharacteristicWriteType.WithoutResponse
+                    )
+                } else {
+                    println("Did not find valid password, so not writing anything")
+                }
+            }
+        }
+    }
     
     func getActivePeripheral() -> CBPeripheral? {
         if self.discovery == nil {

        self.lumValueLabel.text = ""
    }
    
    override func viewDidAppear(animated: Bool) {
        if self.needToShowCameraNotAuthorizedAlert == true {
            self.showCameraNotAuthorizedAlert()

        
        self.hasShownCameraNotAuthorized = true
    }
    
    
    func showCameraNotAuthorizedAlert() {
        let alert = self.captureCtrl.getCameraNotAuthorizedAlert()
