You are reading a single comment by @furuskog and its replies. Click here to read the full conversation.
  • Im trying to connect to a MI FlowerCare sensor. Im having a issue thoe.

    function getData() {
       var gatt;
       NRF.connect("C4:7C:8D:61:FB:E0").then(fu­nction(g) {
     gatt = g;
     return gatt.getPrimaryService("00001204-0000-10­00-8000-00805f9b34fb");
     }).then(function(service) {
     return service.getCharacteristic("00001a01-0000­-1000-8000-00805f9b34fb");
     }).then(function(characteristic) {
     return characteristic.readValue();
     }).then(function(value) {
     console.log(value);
     gatt.disconnect();
     console.log("Done!");
     }).catch(function(error){
     console.log("error", error);
     });
    }
    
    setWatch(function() {
     getData();
    }, 
     BTN, { repeat:true, edge:"rising", debounce:50 });
    

    I get error disconnected it seems that the flower sensor gets disconnected (I get error disconnected) :) in order to save battery there is a automatic disconnect after like 2 secs. Is there something I can do? Is my code correct ? I got the values using the gatttool on a raspberry Pi. I also found some clues here: https://github.com/open-homeautomation/m­iflora/blob/master/miflora/miflora_polle­r.py, Any sudgestions?

    (Update)

    function getDevices() {
    var devices;
    NRF.findDevices(function(d) {
      devices = d;
      console.log(devices);
    }, 1000);
    }
    
    setWatch(function() {
      getDevices();
    }, 
      BTN, { repeat:true, edge:"rising",    debounce:50 });
    

    Outputs :::::::

    Before watering

    BluetoothDevice {
      "id": "c4:7c:8d:61:fb:e0 public",
      "rssi": -50,
        "services": [
        "fe95"
       ],
      "data": new ArrayBuffer([2, 1, 6, 3, 2, 149, 254, 21, 22, 149, 254, 113, 2, 152, 0, 183, 224, 251, 97, 141, 124, 196, 13, 7, 16, 3, 0, 0, 0])
     }
    

    After watering

    BluetoothDevice {
    "id": "c4:7c:8d:61:fb:e0 public",
    "rssi": -52,
    "services": [
      "fe95"
     ],
    "data": new ArrayBuffer([2, 1, 6, 3, 2, 149, 254, 19, 22, 149, 254, 113, 2, 152, 0, 129, 224, 251, 97, 141, 124, 196, 13, 8,  16, 1, 67])
    }
    

    So now I'm wondering if I can get the moister value from the data ArrayBuffer?

About

Avatar for furuskog @furuskog started