Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish failed! #2

Open
Abishek05 opened this issue Sep 24, 2017 · 13 comments
Open

Publish failed! #2

Abishek05 opened this issue Sep 24, 2017 · 13 comments

Comments

@Abishek05
Copy link

hornbill.publish(TOPIC_NAME,payload) fails to return zero sometimes. In my case it fails once every 3 times.
publish_failed

@ikorman
Copy link

ikorman commented Oct 18, 2017

I'm experiencing the same problem: every n-th publish request fails. Can you pls track and resolve this?

Thx.
Ivan

@ikorman
Copy link

ikorman commented Nov 9, 2017

Any progress on this topic?

@eugene-mobile
Copy link

Look at the error code and compare it to aws_iot_error.h. This will give you some info

@sweetillusions0
Copy link

Does anyone know how to correctly include the certificates in the .ino file?

I have tried adding them one by one after this line "char rcvdPayload[512];" but I keep getting this error > "E (2195740) aws_iot: failed! mbedtls_x509_crt_parse returned -0x2180 while parsing root cert
E (2195747) AWS_IOT: Error(-19) connecting to apvo8rqcqjnk3.iot.us-east-2.amazonaws.com:8883,"

Any help will be appreciated.

@SaheblalBagwan
Copy link
Member

Check this tutorial.
http://exploreembedded.com/wiki/AWS_IOT_with_Arduino_ESP32

Include the certificates in this file. Do not forget to add '\n' at the end of each line except for the last line.
https://github.com/ExploreEmbedded/Hornbill-Examples/blob/master/arduino-esp32/AWS_IOT/src/aws_iot_certficates.c

@paulmand3l
Copy link

So I can't include different certificates per project? I have to put them in the library itself?

@shirish47
Copy link

@paulmand3I look at #9
You can go to AWS_IOT.cpp file and remove

#include "aws_iot_certificates.c"

and add a file in Arduino sketch say AWS_certs.h
in that file, you can copy define all certs with

extern extern const char aws_root_ca_pem[] = {""}
extern const char certificate_pem_crt[] = {""}
extern const char private_pem_key[] = {""}

and your certs in that. Atleast that worked for me.

@shirish47
Copy link

Hi, Also get this every 6th publish is failing.

Connected to wifi
Connected to AWS
Subscribe Successfull
return -30
Publish failed
Publish Message:Hello from hornbill ESP32 : 1
Received Message:Hello from hornbill ESP32 : 1
Publish Message:Hello from hornbill ESP32 : 2
Received Message:Hello from hornbill ESP32 : 2
Publish Message:Hello from hornbill ESP32 : 3
Received Message:Hello from hornbill ESP32 : 3
Publish Message:Hello from hornbill ESP32 : 4
Received Message:Hello from hornbill ESP32 : 4
Publish Message:Hello from hornbill ESP32 : 5
Received Message:Hello from hornbill ESP32 : 5
return -30
Publish failed
Publish Message:Hello from hornbill ESP32 : 7
Received Message:Hello from hornbill ESP32 : 7
Publish Message:Hello from hornbill ESP32 : 8
Received Message:Hello from hornbill ESP32 : 8
Publish Message:Hello from hornbill ESP32 : 9
Received Message:Hello from hornbill ESP32 : 9
Publish Message:Hello from hornbill ESP32 : 10
Received Message:Hello from hornbill ESP32 : 10
Publish Message:Hello from hornbill ESP32 : 11
Received Message:Hello from hornbill ESP32 : 11
return -30
Publish failed
Publish Message:Hello from hornbill ESP32 : 13
Received Message:Hello from hornbill ESP32 : 13

according to aws_iot_error.h it is MQTT_CLIENT_NOT_IDLE_ERROR = -30
So just one question. Would I be able to publish a stream of ADXL345 data very fast to AWS IoT in that case?

@jrickard
Copy link

jrickard commented Oct 7, 2018

We've been fighting this for days. The "Publish failed" message is in the example code itself.
The real error returned is -30. This corresponds to The client state is not idle when request is being made

I think we have it fixed. It has to do with a Yield function in AWS_IOT.cpp

We have reduced the yield time to 5ms and the TaksDelay to 550; Try that.

void aws_iot_task(void *param) {

IoT_Error_t rc = SUCCESS;

while(1)
{
    //Max time the yield function will wait for read messages
    rc = aws_iot_mqtt_yield(&client, 5);
    
    if(NETWORK_ATTEMPTING_RECONNECT == rc)
    {
        // If the client is attempting to reconnect we will skip the rest of the loop.
        continue;
    }     
    vTaskDelay(550/ portTICK_RATE_MS);
}

}

@collin80
Copy link

collin80 commented Oct 8, 2018

And to elaborate on why you should change the aws_iot_task to use 5ms timeout and 550 task delay. Previously the settings were 200ms timeout and 1 second delay. Let's put that in perspective. That means that 200/1200 of the time (1/6th of the time) the library was waiting for MQTT traffic in the call to aws_iot_mqtt_yield. Because it is running in a separate thread it could do this behind your back. So, when you try to publish you have a 1 out of 6 chance of the library actually being in the wait state inside of aws_iot_mqtt_yield. Changing this timeout to 5ms but doing it about twice as often yields a 5/555 chance (1/111) which is MUCH better odds. You don't need to spend forever in each call to aws_iot_mqtt_yield. The underlying networking stack will queue frames for you and unless you've got a lot of subscribed messages you aren't going to stack them up. If you do have a lot of subscribed messages coming in then just lower the wait time and the delay time. There's no reason to wait more than 1-2 milliseconds if no message is pending to be received. So, 1ms wait and like 100ms delay would be fine if you don't think you'd get more than 10 MQTT messages per second. At any rate, you can calculate your chances of this library killing your publishes as (yieldtime)/(yieldtime + delaytime).

A potentially better solution is to move the call to aws_iot_mqtt_yield to your sketch's loop function. This could be done by exposing a method from the AWS_IOT class that you call in loop. I understand why the author didn't do this. It would make it more complicated to use and people would have to actually add the call to loop. But, it then yields a basically 0% chance of a publish failure due to client state not idle.

And that's all I have to say about that. ;)

@winnieaswin
Copy link

winnieaswin commented Apr 25, 2019

void aws_iot_task(void *param) {

IoT_Error_t rc = SUCCESS;

while(1)
{
    //Max time the yield function will wait for read messages
    rc = aws_iot_mqtt_yield(&client, 5);
    
    if(NETWORK_ATTEMPTING_RECONNECT == rc)
    {
        // If the client is attempting to reconnect we will skip the rest of the loop.
        continue;
    }     
    vTaskDelay(550/ portTICK_RATE_MS);
}

}

I changed in AWS_IOT.cpp, I don't receive Public fail anymore

@reubenfinch
Copy link

Thanks for this fix. Saved a bunch of code trying to deal with the occasional failure.

@abicas
Copy link

abicas commented Dec 28, 2020

Same issue, worked like a charm ! Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests