Number of Bluz connected to Gateway Shield


#1

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

Thanks in advance.


#2

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: http://docs.bluz.io/tutorials/local_communication/


#3

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?

Thanks.


#4

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


#5

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.


#6

You can see in the tutorial how to send data to and from DK devices: http://docs.bluz.io/tutorials/local_communication/. So the function you want is send_peripheral_data, you can see the doc here: http://docs.bluz.io/reference/bluz_gateway/#send_peripheral_datauint8_t-id-uint8_t-data-uint16_t-length

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: https://stackoverflow.com/questions/3784263/converting-an-int-into-a-4-byte-char-array-c