Avatar for furuskog

furuskog

Member since Mar 2017 • Last active Apr 2017
  • 1 conversations
  • 19 comments

Webdeveloper and happy family guy.

Most recent activity

  • in Interfacing
    Avatar for furuskog

    I understand thank you for the answer.

  • in Puck.js
    Avatar for furuskog

    @Wilberforce thank you very much for the help. With a little googling and some other tutorials about the sensor in python I finally had success.

    This is the code I used to get the correct values.

    var currentSevice = false;
    
        function getData() {
          var gatt;
          NRF.connect("C4:7C:8D:62:0D:5A").then(fu­nction(g) {
            gatt = g;
            return gatt.getPrimaryService("00001204-0000-10­00-8000-00805f9b34fb");
          })
          .then(function(service) {
            currentService = service;
            return service.getCharacteristic("00001a00-0000­-1000-8000-00805f9b34fb");
         })
         .then(function(characteristic) {
             return characteristic.writeValue([0xa0, 0x1f]);
         })
         .then(() => {
             return currentService.getCharacteristic("00001a­01-0000-1000-8000-00805f9b34fb");
         })
         .then((characteristic) => {
            return characteristic.readValue();
         })
         .then(function(value) {
            console.log("temperature: ", value.getI­nt16(0, true)/10);
       console.log("Sunlight: ",value.getInt­32(3,true));
       console.log("Moister: ", value.getUin­t8(7,true));
    console.log("Fertility: ", value.getUint16(8,true));
            console.log(JSON.stringify(value.buffer)­);
           gatt.disconnect();
           console.log("Done!");
         })
           .catch(function(error){
             console.log("error", error);
           });
        }
    
        setWatch(function() {
          getData();
        }, BTN, { repeat:true, edge:"rising", debounce:50 });
    
  • in Puck.js
    Avatar for furuskog
    //In python 
    temperature, sunlight, moisture, fertility = unpack('<hxIBHxxxxxx',data)
    

    Format C Type Python type Standard size
    h short integer 2
    x pad byte no value
    I unsigned int integer 4
    B unsigned char integer 1
    H unsigned short integer 2

    How can I do this with the ArrayBuffer in JavaScript?

    var data = 
    new ArrayBuffer([215, 0, 0, 208, 13, 0, 0, 20, 53, 1, 2, 60, 0, 251, 52, 155]);
    
    // 21.5 C, type h
    var temp = data[0]/10;
    // ~ 3500 lux, data[2],data[3],data[4], 0,208,13, type I
    //var sunlight =  ?
    // 20 %, data[7], type B
    var moister = data[7];
    // 315,  data[8], data[9], type H
    //var fertility = ?
    

    I wonder if there is an easy solution to this?

  • in Interfacing
    Avatar for furuskog

    How is it going? Have anybody figured it out yet?

    It would be nice to use the puck.js as a mini web server. Is it then possible to make a web crawler out of it?

  • in Puck.js
    Avatar for furuskog

    Finally some success

    var currentSevice = false;
    
    function getData() {
      var gatt;
      NRF.connect("C4:7C:8D:62:0D:5A").then(fu­nction(g) {
        gatt = g;
        return gatt.getPrimaryService("00001204-0000-10­00-8000-00805f9b34fb");
      })
      .then(function(service) {
        currentService = service;
        return service.getCharacteristic("00001a00-0000­-1000-8000-00805f9b34fb");
     })
     .then(function(characteristic) {
         return characteristic.writeValue([0xa0, 0x1f]);
     })
     .then(() => {
         return currentService.getCharacteristic("00001a­01-0000-1000-8000-00805f9b34fb");
     })
     .then((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 });
    

    Output

    DataView {
      "buffer": new ArrayBuffer([207, 0, 0, 209, 12, 0, 0, 24, 124, 1, 2, 60, 0, 251, 52, 155])
       }
    

    Next is to format the values but I save that for this weekend :)

  • in Puck.js
    Avatar for furuskog

    @Gordon thanks. I will go through it step and try the things you mentioned. It sounds like it will work. Looks like I have something to tinker with this weekend to :)

  • in Puck.js
    Avatar for furuskog

    The nRF connect closes the connection after 2-3 seconds that why I suspect the miflora tries to save energy, it seems that you have to write to a characteristic first, then you could get the real values, otherwise it only return zeroes.

    wiki.hackerspace.pl/projects:xia­omi-flora

  • in Puck.js
    Avatar for furuskog

    I'm going to try the new firmware 1,92
    But the timeout is in the miflora sensor so I'm not sure it will help. Is there a way to influence the timeout from the puck.js?

  • in Puck.js
    Avatar for furuskog

    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: github.com/open-homeautomation/m­iflora/blob/master/miflora/miflora_polle­r.py, Any sudgestions?

Actions