Avatar for MaBe

MaBe

Member since Nov 2015 • Last active May 2021

No matter what device you use, with Espruino you always have a lot of fun.

Espruino Rocks ūü§ü

Special thanks goes to Gordon.

Most recent activity

    • 6 comments
    • 1,458 views
  • in Interfacing
    Avatar for MaBe

    During tests I realized that it can happen that manufacturerData is missing because got some different advertisements, so it might be helpful to extend the filter.

    filter1 = [{ manufacturerData:{0x0590:{}}}];
    filter2 = [{ id:"d9:c7:0b:0a:48:20 random"}];
    filtersAll = filter1.concat(filter2);
    NRF.requestDevice({ filters: filtersAll }).then(
        function(d) { 
            if ( d.manufacturerData ) 
                console.log(JSON.parse(String.fromCharCo­de.apply(null, d.manufacturerData)));
            console.log('.');
        }
    );
    
    /* output
    =Promise: {  }
    { "w": 2953 }
    .
    */
    
    

    So it look's like the filters work as logic OR. Is there a way to change to AND?

  • in Interfacing
    Avatar for MaBe

    Yep, I am on my way to change this whole communication by manufacturer data to JSON5. For this approach I didn't wanted to have to many changes at the same time ......

  • in Interfacing
    Avatar for MaBe

    I've just updated the docs...

    Thanks

  • in Interfacing
    Avatar for MaBe

    Got the solution, the config.json has "mqtt_advertise_manufacturer_data": false.

    After setting "mqtt_advertise_manufacturer_data": true and restarting the EspruinoHub the manufacturer data is available.

  • in Interfacing
    Avatar for MaBe

    Used a second Puck to verify that JSON is valid

    // Puck.js : { "a": "1", "b": 2 }
    NRF.requestDevice({ filters: [ { id:"d9:c7:0b:0a:48:20 random"}]}).then(
      function(d) { 
       console.log(JSON.parse(String.fromCharCo­de.apply(null, d.manufacturerData)));
    } );
    /* output
    =Promise: {  }
    {
      "a": "1",
      "b": 2 }
    */
    
  • in Interfacing
    Avatar for MaBe

    Use a Puck to advertise data and try to read them via MQTT client, but data is not visible via mqtt client.

    Configuration and snipped to advertise taken from the the Espruino Hub repo page

    Device: d9:c7:0b:0a:48:20 - Puck.js 4820 (RSSI -59)

    snippet on for Puck.js 4820

    function onInit(){
          var data = {a:"1",b:2};
          NRF.setAdvertising({},{
                showName:false,
                manufacturer:0x0590,
                manufacturerData:JSON.stringify(data)
          });
    }
    
    setTimeout(save,1E3);
    

    Advertising is visible on Espruino Hub and BluefruitConnect.

    Connect to the mqtt server and subscribe to /ble/advertise/d9:c7:0b:0a:48:20/espruin­o and /ble/advertise/d9:c7:0b:0a:48:20/#. Get many payloads for the second sub but none for the first.

    Any hints what's missing?

  • in JavaScript
    Avatar for MaBe

    Yes, text in json will not be covered ....

    ok so let's sum it up

    var json = {a:"1",b:2};
    data = E.toJS(json);    // {a:\"1\",b:2}"
    j = eval('('+data+')');  // {  a: "1", b: 2 }
    
    

    So, JSON5 is possible on Espruino devices - thanks.

Actions