Avatar for Andrea

Andrea

Member since May 2019 • Last active Mar 2021
  • 3 conversations
  • 19 comments

Most recent activity

  • in Interfacing
    Avatar for Andrea

    Hi, with the custom firmware everything works perfectly!

    After flashing, following these directions: https://github.com/pvvx/ATC_MiThermomete­r

    @Vlad's code fetches values without problems:

    var temp = null;
        var humidity = null;
        var battery = null;
        function getSensorData() {
            NRF.findDevices(function(devices) {
                    if (devices[0] && devices[0].serviceData.fe95) {
                        var data = devices[0].serviceData.fe95;
                        // console.log(data);
                        var flag = data[11];
                        // console.log(flag);
                        
                        switch (flag) {
                            case 4: {
                                // temp
                                temp = (data[14] | data[15] << 8) / 10;
                                break;
                            }
                            case 6: {
                                // humidity
                                humidity = (data[14] | data[15] << 8) / 10;
                                break;
                            }
                            case 10: {
                                // battery
                                battery = devices[0].serviceData.fe95[14];
                                break;
                            }
                            case 13: {
                                // temp and humidity
                                temp = (data[14] | data[15] << 8) / 10;
                                humidity = (data[16] | data[17] << 8) / 10;
                                break;
                            }
                            default : {
                                print("Unknown flag: " + flag);
                            }
                        }
                    }
                    for (var i = 0; i < devices.length; i++) {
                        devices[i] = null;
                    }
                    devices = null;
                }, {
                    filters: [
                        {serviceData:{"fe95":{}}}
                    ],
                    timeout: 2000
                }
            );
        }
        setInterval(function () {
            print("Temp: " + temp + " humidity: " + humidity + " battery: " + battery);
            getSensorData();
        }, 5000);
    

    THANK YOU ALL!

  • in Interfacing
    Avatar for Andrea

    Hi @fanoush, you are right, in the next few days I will hack one :-)

    See you soon!

  • in Interfacing
    Avatar for Andrea

    Hi @fanoush, thanks for the link, I initially saw something about: https://github.com/atc1441/ATC_MiThermom­eter

    Then I saw that through Python, without any hacks, you can get the values easily.

    Maybe later, I sacrifice one in the name of science :-)

  • in Interfacing
    Avatar for Andrea

    Hi @Gordon, I uploaded this code to Pixl.js (2v08)

    var deviceInfo = {};
    
    function parseDevice(device) {
      var d = new DataView(device.serviceData["fe95"]);
      var frame = d.getUint16(0, true);
      var offset = 5;
    
      console.log("FRAME: " + frame);
    
      if (frame&16) offset+=6; // mac address
      if (frame&32) offset+=1; // capabilitities
      if (frame&64) { // event
        var l = d.getUint8(offset+2);
        var code = d.getUint16(offset,true);
        if (!deviceInfo[device.id]) deviceInfo[device.id]={id:device.id};
        event = deviceInfo[device.id];
        switch (code) {
          case 0x1004: event.temperature = d.getInt16(offset+3,true)/10; break;
          case 0x1006: event.humidity = d.getInt16(offset+3)/10; break;
          case 0x100D:
            event.temperature = d.getInt16(offset+3,true)/10;
            event.humidity = d.getInt16(offset+5)/10; break;
          case 0x1008: event.moisture = d.getUint8(offset+3); break;
          case 0x1009: event.fertility = d.getUint16(offset+3,true)/10; break;
          // case 0x1007: break; // 3 bytes? got 84,0,0 or 68,0,0
          default: event.code = code;
            event.raw = new Uint8Array(d.buffer, offset+3, l);
            break;
        }
        print(event);
      }
    
    };
    
    setInterval(function () {
        NRF.setScan(parseDevice, { filters: [{serviceData:{"fe95":{}}}], timeout: 2000 });
    }, 5000);
    

    It always prints FRAME, and when the temperature or humidity changes it prints the event:

    FRAME: 22616
    {
      "id": "a5:c2:83:xx:xx:xx public",
      "code": 50578,
      "raw": new Uint8Array([208, 117, 0, 0, 58, 221, 132, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
     }
    
    FRAME: 22616
    {
      "id": "a5:c2:83:xx:xx:xx public",
      "code": 15670,
      "raw": new Uint8Array([121, 182, 117, 0, 0, 185, 254, 166, 227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
     }
    

    I have no idea how to extract the temperature and humidity :-)

    Can I get some useful info from this Python code (0x80, 0x7F)?

    https://github.com/adafruit/Adafruit_Cir­cuitPython_BLE_LYWSD03MMC/blob/main/adaf­ruit_ble_lywsd03mmc.py

    THANK YOU

  • in Interfacing
    Avatar for Andrea

    Hi @Gordon, thanks for the reply.

    As soon as I have time, I try the code on my Pixl.js and tell you!

    See you soon :-)

  • in Interfacing
    Avatar for Andrea

    Hi @Gordon, hi @Vlad

    I have a Xiaomi LYWSD03MMC Thermometer / Hygrometer and with this CircuitPython library I can fetch its values:

    https://github.com/adafruit/Adafruit_Cir­cuitPython_BLE_LYWSD03MMC/blob/main/adaf­ruit_ble_lywsd03mmc.py

    Now I'd like to make everything work on Espruino thanks to your code.

    I changed filters: [{serviceData: {"fe95": {}}}] the device is found (although its serviceData should be "ebe0ccb0") but all values remain null.

    How do you think it could be solved?

    THANK YOU

  • in Other Boards
    Avatar for Andrea

    OK, thanks anyway ... if I solve, I'll write you how I did!

    :-)

  • in Other Boards
    Avatar for Andrea

    Hi Gordon!

    Programming via Bluetooth is OK, but via USB it is only powered, it is not recognized and the "MICROBIT" drive is not mounted ... I don't know how to update to 2.06

    I've tried both on Mac and Windows (with related drivers) and with different USB cables.

    THANK YOU SO MUCH

  • in Other Boards
    Avatar for Andrea

    Hello. In this situation, exist a way to update / restore to factory defaults via drag n drop, Espruino Web IDE, WebUSB, BLE DFU App, Serial Port Terminal?

    There is a key combination or "jumper-bridge" between pins to activate the bootloader?

    :-(

    THANK YOU

Actions