More Puck EspruinoHub & MQTT

Posted on
  • I am far from a pro here but I can manage a way around. I have EspruinoHub on a rPi zero W and its seeing my puck - the puck also shows up on the bluefruit app. I can change a variable in the puck code from 0 to 1 and add that to the mfg data and i can see that in the bluefruit app. I have a few problems Im hoping to get help with; first, I cant seem to get mqtt explorer on mac to connect to EH even though Im using the same ip address that my browser is getting connected with. Ive tried ports 1888 and 1883 form the explorer and its not connecting. Second, the mac address for the puck seems to show up twice in the EH status data - why is that? I've added the first mac address to the config.json as per the thread posted by MaBe and still not getting joy. I am using my own UUID (0x0A42 and trying x0590) on the puck so maybe i need to config that somewhere in EH? Third, Im not sure i understand how to do what i have in mind. I want to send state change data for when its moving so i did this: I set a service and characteristic:

     NRF.setServices({
        0xBCDE : {
          0xABCD : {
            value : 0,
            maxLen : 1,
            notify: true
          }
        }
      });
    

    When the puck changes state, I modify it:

    function UpdateNewServiceValue (val){
      NRF.updateServices({
        0xBCDE : {
          0xABCD : {
              value : val,
              notify: true
          }
        }
      });
    }
    

    I know the state changing code works because i can see the mfgdata in bluefruit. I am trying to find reading material or any help to figure it out. I guess I was expecting to get the EspruinoHub up and would be seeing the mfgdata change with state and be able to subscribe to the service and characteristic? How would a person send the mqtt data to AWS or io.adafruit?

  • Hi,

    I cant seem to get mqtt explorer on mac to connect to EH even though Im using the same ip address that my browser is getting connected with

    Port 1883 should do it, however maybe you could log into the Pi and type mosquitto_sub -v -t "#" to see if you can connect to MQTT on the Pi? It's possible it isn't installed.

    It might also be qorth checking /etc/mosquitto/mosquitto.conf and /etc/mosquitto/conf.d to check there's nothing in there that's stopping it accepting outside connections. It seems an options called bind_addresss can end up locking it down.

    I want to send state change data for when its moving so i did this

    Ok, I think the issue is there are two different communication methods in Bluetooth:

    • Advertising - where you have your Manufacturer Data UUID like 0x0590. This is what gets broadcast to everyone (without a connection needed) and what EspruinoHub picks up normally
    • Services/Characteristics - with setServices/updateServices - these are only available when you're actually connected to a device. EspruinoHub can read these but you have to specifically request that it does it by MQTT messages.

    So I think realistically for what you want, you just want to do NRF.setAdvertising like the example at the bottom of: http://www.espruino.com/Reference#l_NRF_­setAdvertising

    So:

    function UpdateNewServiceValue (val){
    NRF.setAdvertising({},{
      showName:false,
      manufacturer:0x0590,
      manufacturerData:JSON.stringify(val)
    });
    }
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

More Puck EspruinoHub & MQTT

Posted by Avatar for motiosean @motiosean

Actions