[SOLVED] Can not Particle publish through bluz dk


#1

Hi,

I am new to the bluz world and trying to get a hand on things. I am using a very simple code to do particle publish on the particle console. I am using gateway shield with a photon as a gateway. I am able to successfully flash the code but after flashing the code when the device comes back online it does not publish anything. Am I missing anything here?

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

long currentMilli = 0;

void setup() {
    Serial.begin(9600);
}

void loop() {
    if(millis()-currentMilli > 3000)            //publish every 3 second
 {
    Particle.publish("Test Publish", "Hello World");
    currentMilli = millis();
 }
}

#2

Welcome!

For one, you don’t need the Serial.begin() command, so you can just remove that. It will consume a good amount of current.

More importantly, you shouldn’t use the SYSTEM_MODE(MANUAL); call. This will put bluz into manual mode where it does not connect to the cloud. If it isn’t connected to the cloud, it can’t publish. Also, you can’t flash new code, so you will need to reset the device before you can flash code again.

After you flashed this code, is the RGB LED blinking white? If so, you are in local mode. The best way out is a factory reset: http://docs.bluz.io/tutorials/bootloader/#performing-a-factory-reset

Once that is done, you can flash the code with the above two lines removed and it should work.


#3

Hi Eric,

The LED is not blinking white. After flashing the code the LED blinks green and then cyan. I removed these two lines and flashed the code again and it still doesn’t publish anything.


#4

Can I ask how you are verifying whether it is publishing or not?

I tried the code and it works as expected. I am verifying the published events through the Particle dashboard.


#5

I am verifying it through the particle console as well. I can see my device getting online and offline as events there but not the events I am publishing.

I also just tried the factory reset and after the factory reset the device goes into the safe mode. It is blinking yellow slowly which according to the documentation means it is connected to the cloud. I flashed the below code again and still the same thing. It also doesn’t blink cyan this time.

#include "application.h"

long currentMilli = 0;

void setup() {
}

void loop() {
    if(millis()-currentMilli > 3000)            //publish every 3 second
 {
    Particle.publish("Test Publish", "Hello World");
    currentMilli = millis();
 }

}

These are the events I see on the console -


#6

I am looking at the logs and it seems your device isn’t taking the OTA flash. I can see the app-hash still appears to be the original value, until the factory reset, then it is staying in safe mode and not getting new firmware.

What version of firmware are you building with in the Web IDE?


#7

It was set to default 1.1.47 and it also says that on the device it is 2.1.50.

Thinking this was the mistake I changed it to 2.1.50 in the web IDE. But now it says error 500 and won’t let me flash at all.


#8

Can you refresh and try again? You can also upgrade to 2.3.50 if you want, but I would recommend connecting through the app first as it will be slow through the gateway shield.

If you still see the 500 error, let me know and I will ping Particle. It is working for me, but there could still be some kind of issue. I think that is the source of the issue.


#9

Thanks, It works now. Didn’t work initially when I refreshed the page couple time but suddenly started working.

Also, I would appreciate if you could help me troubleshoot this another issue.

I now replaced the publish every 3 seconds line in the code to BLE.sendData() every 3 seconds as follows:

#include "application.h"

long currentMilli = 0;

void setup() {
}

void loop() {
    if(millis()-currentMilli > 3000)            //publish every 3 second
 {
    // Particle.publish("Test Publish", "Hello World");
    currentMilli = millis();
    uint8_t rsp[2] = {'H', 'i'};
    BLE.sendData(rsp, 2);
 }
}

and on the gateway side I am flashing the following code on photon:

// This #include statement was automatically added by the Particle IDE.
#include <bluz_gateway.h>

bluz_gateway gateway;

void handle_custom_data(uint8_t *data, uint16_t length) {
    Particle.publish("Data", String((char*)data));
}

void setup() {
    gateway.init();
    gateway.register_data_callback(handle_custom_data);
}

void loop() {
    gateway.loop();
}

Ideally, it should publish the data every three seconds on the console but it doesn’t do that.


#10

Did you go to http://console.bluz.io/ and verify if your gateway needs new firmware? Also, what version of the library are you using from the Web IDE for the Photon?

That code looks correct, it should work. Is it not publishing anything at all?


#11

It works now. I don’t know what happened. It started publishing after 2 minutes. But it is working now. Thanks!

However, I face this issue of code not being flashed properly a couple times. For example, I was able to flash code this morning and it was properly creating the app hash as well. But now suddenly it doesn’t create the app hash. According to the logs on the console - the flash gets started - success - device goes offline - device comes online - module info. I checked the firmware versions and they correctly match and moreover it is the same code that I flashed earlier which was working. What could be the possible reasons for that? Is it something that often happens?


#12

As long as the proper version of firmware is selected from the IDE, then you shouldn’t have issues flashing code. v1.X versions of FW are completely incompatible with v2.X as they start at different physical address in flash. So a 2.X system firmware with a 1.X app version won’t work since it is looking for it in the wrong spot.

The only other reason it shouldn’t flash the code it downloaded is if it doesn’t pass a checksum, but that would mean there is some kind of error as it is handed down. While that could happen rarely, it wouldn’t consistently be a problem.