Giter Site home page Giter Site logo

Comments (13)

jrickard avatar jrickard commented on June 12, 2024 6

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);
}

}

from hornbill-examples.

collin80 avatar collin80 commented on June 12, 2024 3

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. ;)

from hornbill-examples.

shirish47 avatar shirish47 commented on June 12, 2024 1

@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.

from hornbill-examples.

ikorman avatar ikorman commented on June 12, 2024

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

Thx.
Ivan

from hornbill-examples.

ikorman avatar ikorman commented on June 12, 2024

Any progress on this topic?

from hornbill-examples.

eugene-mobile avatar eugene-mobile commented on June 12, 2024

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

from hornbill-examples.

sweetillusions0 avatar sweetillusions0 commented on June 12, 2024

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.

from hornbill-examples.

SaheblalBagwan avatar SaheblalBagwan commented on June 12, 2024

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

from hornbill-examples.

paulmand3l avatar paulmand3l commented on June 12, 2024

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

from hornbill-examples.

shirish47 avatar shirish47 commented on June 12, 2024

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?

from hornbill-examples.

winnieaswin avatar winnieaswin commented on June 12, 2024

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

from hornbill-examples.

reubenfinch avatar reubenfinch commented on June 12, 2024

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

from hornbill-examples.

abicas avatar abicas commented on June 12, 2024

Same issue, worked like a charm ! Thanks !

from hornbill-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.