How do you connect your pucks to the world?

Posted on
  • Hi,

    these days I received my puck and I wonder how you connect your pucks to some REST/mqtt services.
    For example: I have a openhab automated "smart home" and I want to push some data from the puck to the REST API of openhab (btn click, temp, light, mag etc).
    First I tried to use the fantastic EspruinoHub project, but BLE4 HTTP Proxy seems a bit limited with only 20bytes payload (and yes uri's are payload too :D). I hacked a bit the sources and get it working by "encoding" some requests, for example the request

    require("ble_http").httpRequest(device, "myItem/state", function(d) {})
    

    will be made to http://openhab:8080/rest/items/myItem/st­ate. This can be a direction to go, but it needs some work.

    Another way would be the MQTT feature of EspruinoHub, but I didnt get it working (especially with custom data).

    What are you guys using for connecting your pucks to the world?

    Btw:
    Whats the proper way to ask for temperature via mqtt?
    Tried /ble/read/puck1/1809/2A1C so far

  • Yes - pushing via HTTP is more difficult. I think EspruinoHub currently ignores the headers and body characteristics when sending, but if it used it could give you a bit more space.

    Whats the proper way to ask for temperature via mqtt?

    You'd have to first expose it using NRF.setServices/.updateServices, then you can use /ble/read as you were doing.

    However I've just been doing:

    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : [Math.round(E.getTemperature())]
      });
    }, 30000);
    

    Then EspruinoHub picks up the advertising automatically and creates MQTT events. You can use a 16 bit temperature too if you want to.

    I guess another option is to add a /ble/uart endpoint that connects, sends data via the UART, and then sends another packet back with the response in. That way you could just send something like E.getTemperature() and then listen for the response.

    ... of course eventually I'll be adding IPv6 to the Puck itself, so that'll make everything a bit easier.

  • I guess I got it now :)
    I finally receive something on /ble/advertise/puck1/1809
    Is it possible/"allowed" to reuse other BLE Service UUIDs for custom data (Light,Mag,Temp, BTN state) ?

    Thank you. !

  • Note:
    I wonder how to "control" the puck in some way. I tried your advice at https://www.espruino.com/Puck.js+Node-RE­D.

    So I published {"payload": "LED1.set();\n"} (and also LED1.set();\n) to /ble/write/puck1/nus/nus_tx
    But all I get is:

    MQTT>/ble/write/puck1/nus/nus_tx => "{\"payload\": \"LED1.set();\\n\"}"
    Service 	6e400001b5a3f393e0a9e50e24dcca9e
    Characteristic 	6e400002b5a3f393e0a9e50e24dcca9e
    <Connect> Error Connecting
    

    Am I missing some advertising?

  • Hmm. You should definitely just be sending only LED1.set();\n - but I wonder whether this is a bug in the hub software when sending to named devices...

    Can you try removing the puck1 name, and then sending to /ble/write/ad:dr:es:ss:00/nus/nus_tx ?

  • I missed this one:

    Is it possible/"allowed" to reuse other BLE Service UUIDs for custom data (Light,Mag,Temp, BTN state) ?

    Yes, it's possible, but you'd get in trouble if you shipped a product that did it. It's not going to interfere with anything, but there is some small possibility that some other software might try and 'claim' your Puck. I definitely wouldn't lose any sleep over doing it in my own house though :)

    There's also a 16 bit UUID for 'custom data' or something (I can't remember the exact name) - but I'm pretty sure you could just dump whatever you wanted in there.

  • Sorry for my late response. I tried your advice to remove the naming, but the output is identical.

    Config loaded
    MQTT Connected
    <HTTPProxy> Bleno State poweredOn
    <HTTPProxy> Bleno.startAdvertising Success
    <HTTPProxy> Bleno.setServices Success
    Scanning started...
    MQTT>/ble/write/c9:88:f0:97:da:57/nus/nu­s_tx => "LED1.set();\\n"
    Service 	6e400001b5a3f393e0a9e50e24dcca9e
    Characteristic 	6e400002b5a3f393e0a9e50e24dcca9e
    <Connect> Error Connecting
    
    Tue Dec 13 2016 19:30:16 GMT+0100 (CET)
    
    5a:8b:0c:72:57:56 - ? (RSSI -66)
    68:d9:3c:8e:46:b3 - ? (RSSI -43)
    c9:88:f0:97:da:57 - Puck.js da57 (RSSI -84)
      1809 => {"temp":102}
    
  • Try updating now. I make it work with names and/or addresses.

    Having said that, for some reason I don't understand it looks like Noble has broken. It just hangs when trying to get the list of services - but it may work on yours as mine definitely gets past where you were.

  • Same problem after git pull. It keeps erroring while connecting (with and without named devices) :/

    There is a new error (after a fresh successfully npm i) noble: unknown peripheral null connected!

  • Have you tried doing an apt-get update and apt-get dist-upgrade? I did that today and the new Kernel (or something else that appeared) seemed to really help.

    If you updated node you'd need to re-run the setcap thing as well or it wouldn't have permissions.

  • Sorry no chance to get this working :/
    The other way works great. I'm able to advertise arbitrary data via BLE and get messages back :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How do you connect your pucks to the world?

Posted by Avatar for otbe @otbe

Actions