Number of Bluz connected to Gateway Shield


How can I find out the number of Bluz units connected to the Gateway Shield (with an Electron)?

Thanks in advance.


The default tutorial shows how to poll the gateway for the devices connected, it returns an array with either a 0 or 1. You can use that to count and then do whatever you need to with the data from the Electron:


The tutorial shows that this is done by polling (gateway.send_peripheral_data(i, rsp, 2);).

Is this the only way to find out? I thought the Gateway shield would keep internally the number of clients it sees without the need for polling?



The gateway shield does have that count internal, the polling mechanism is simply asking the shield for the count. It doesn’t poll out to each bluz device when you ask the gateway shield.

Is there a reason this wouldn’t work for your situation? We can discuss options if this won’t work for some reason


Thanks @eric. In this case it will work fine, I was under the impression that the shield goes out to each DK which would take too much time.

Can you please refer me to simple code of how to send an integer from the Photon on the Shield and read it on the DK units?

Thanks again.


You can see in the tutorial how to send data to and from DK devices: So the function you want is send_peripheral_data, you can see the doc here:

The only difference is, this takes an array of unsigned integers, that is, one byte at a time. If you can fit your data into one byte (an integer less than 255 if unsigned) then you can just call it as such:

uint8_t data[1] = {42};
send_peripheral_data(0, data, 1);

That will send the int 42 to the DK at index 0.

If you need a larger integer, you have to encode it into a byte array and send that. You can do that with byte shifting, as seen in the examples here: