[SOLVED] Bluz Gateway Photon+Bluz DK Local Communication-Not Publishing


#1

@Eric;

I am trying out your example from here:

http://docs.bluz.io/tutorials/local_communication/

When I compile code for Gateway Photon, it failed at this line:

bluz_peripherals_available++ (not declared)

So I declared it as integer and flash it successfully. Using Gateway Library version 1.6.

On the DK side, the sample code flash successfully. I restart the Gateway Photon and wait till it gets connected to Particle cloud then turned on Bluz_DK but I don’t see any publish event (Bluz Devices Online) from DK on Particle Console.

What am I missing???

Thanks


#2

Thanks for the notice on the missing line! I fixed that in the docs so it will get pushed out to production soon, it is on staging currently.

As for the example, I just tried this again to make sure and everything is working ok here. A few questions:

  1. Is the DK blinking white? This indicates it is connected to the gateway but not to the cloud. If it is blinking green, then it isn’t connecting to the gateway at all.
  2. You mentioned that you don’t see any events from the DK, but this is expected. The Photon would send the events on behalf of the DK. You should also see polling responses from the Photon indicating there are devices online, this should happen regardless of whether there are DK’s connected. Do you see events like this?

If you aren’t seeing the “Bluz Devices Online” event from the Photon at all, then I suspect it wasn’t flashed properly with the example in the tutorial. If you do, but it always says “O O O”, which indicates no devices are connected, then there is probably an issue with getting the DK connected to the gateway.

If you do see that Bluz Devices Online event with “X O O” but not any data from the DK (“Hi” in this example), then I suspect the DK didn’t get updated properly.

Let me know


#3

@eric, please see my answers below:

  1. Yes, DK is blinking white.
  2. I meant DK events were not get published by Photon. Sorry. No, I do NOT see any polling responses like you mentioned. All I saw were “module-info” and “bluz gateway device id” in particle console.

I do not see any “Bluz Device Online” event with “X O O” or “O O O”. How do I put the DK back to AUTOMATIC mode without connecting D6. Is there a factory reset mode? I want to flash it again. But when I did it DK flash seems to be successful.

Thanks.


#4

If the DK is blinking white, you probably have the correct code on it. If the Photon is not publishing the “Bluz Devices Online” event, then it sounds like the Photon does not have the proper code.

You should try re-flashing the Photon with the example code, I think that is the issue.


#5

@eric, I just re-flashed the Photon Gateway with the code below but still NO Bluz DK events.

// This #include statement was automatically added by the Particle IDE.
#include “bluz_gateway/bluz_gateway.h”

#define POLL_CONNECTIONS_INTERVAL 30000

SYSTEM_MODE(SEMI_AUTOMATIC);
bluz_gateway gateway;
int bluz_peripherals_available;

void handle_custom_data(uint8_t data, uint16_t length) {
//if you use BLE.send from any connected DK, the data will end up here
Particle.publish(“Bluz Custom Data”, String((char
)data));
}

void handle_gateway_event(uint8_t event, uint8_t *data, uint16_t length) {
//will return any polling queries from the gateway here
uint8_t rsp[2] = {‘H’, ‘i’};
switch (event) {
case CONNECTION_RESULTS:
String online_devices = “”;
for (int i = 0; i < length; i++) {
if (data[i] == 0) {
online_devices +="O ";
} else {
online_devices +="X ";
gateway.send_peripheral_data(i, rsp, 2);
bluz_peripherals_available++;
}
}
Particle.publish(“Bluz Devices Online”, online_devices);
break;
}
}

void setup() {
gateway.init();

//register the callback functions
gateway.register_data_callback(handle_custom_data);
gateway.register_gateway_event(handle_gateway_event);

}

long timeToNextPoll = POLL_CONNECTIONS_INTERVAL;
void loop() {
gateway.loop();
if (millis() > timeToNextPoll) {
timeToNextPoll = POLL_CONNECTIONS_INTERVAL + millis();
gateway.poll_connections();
}
}


#6

@eric, I also just re-flashed the bluz-dk, and re-start gateway and dk. Still no DK events published by Photon. What am I missing? I am using Bluz_Gateway library 1.6.0.

Bluz_DK code:

#include "application.h"
SYSTEM_MODE(MANUAL);

bool sendData = false;

void dataCallbackHandler(uint8_t *data, uint16_t length) {
sendData = true;
}

void setup() {
BLE.registerDataCallback(dataCallbackHandler);

pinMode(D6, INPUT_PULLDOWN);
if (digitalRead(D6) == HIGH) {
    SYSTEM_MODE(AUTOMATIC);
}

}

void loop() {
System.sleep(SLEEP_MODE_CPU);
if (sendData)
{
uint8_t rsp[2] = {‘H’, ‘i’};
BLE.sendData(rsp, 2);
sendData = false;
}
}

Thanks.


#7

Can you add a Particle.publish somewhere else in the code? Or if you flash simple publish code to the Photon, does it work? If the Photon isn’t publishing basic events, then there is something wrong with the device.


#8

@eric, Photon is publish, please is below. Looks like DK is not sending event to Photon to publish.


#9

@eric, looks like the callbacks are not getting called.

gateway.register_data_callback(handle_custom_data);
gateway.register_gateway_event(handle_gateway_event);


#10

Can you try updating your gateway to he latest firmware here: http://staging-console.bluz.io/

After you login, it should show you the gateway and just have a button to update. It can take a minute or two, but then you should be able to try again.


#11

@eric, i tried staging but after I login all I see was header on the page saying Welcome to the bluz console Gateways. There is noting for me to click on or do anything with it. Please explain??


#12

The only reason you shouldn’t see the device in there is if your Photon doesn’t have the correct variable.

There is a Particle.variable inside the blua-gateway library called gatewayID. When the Photon starts, it polls the nrf51 on-board for the gateway for it’s ID and stores it in this variable. The console then looks for all Photons with that specific variable on your account, and if it finds one, it lists it.

So if it isn’t showing up in console, then it can’t find the Photon or it can’t find the variable on it.

A few questions:

  • Did you login to console with the same account that your Photon is claimed to?
  • Can you open the (new) Particle app and look at the Photon? It gives you a list of variables under the “Data” tab and you should see one called gatewayID listed with another ID like “b1e2…”. Alternatively, you could look at the Particle CLI if that is easier.

#13

@eric, I got it working. Thanks for your help. Just FYI, for very first Custom Data, meaning right after Photon reboot, the data only comes through “i” instead of “Hi” but consequent publish events come thru “Hi.”