question

sevencheng avatar image
sevencheng asked

How to implement an AVS interaction through the C language on Linux embedde

Hi Alexa, I want to develop the function of AVS on an embedded device. I am using http/2 client library is :nghttp2+libcurl. i already read the Getting Started Guide. I'm going to implement a Alexa AVS based on the link:Structuring an HTTP/2 Request to the Alexa Voice Service and Managing an HTTP/2 Connection with the Alexa Voice Service, but I have encountered a problem: * SSL_write() returned SYSCALL, errno = 32 err message log: * Trying 54.239.26.171... * Connected to avs-alexa-na.amazon.com (54.239.26.171) port 443 (#0) * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * Server certificate: * subject: C=US; ST=Washington; L=Seattle; O= Amazon.com, Inc.; CN= latinum.amazon.com * start date: Oct 28 00:00:00 2015 GMT * expire date: Oct 16 23:59:59 2016 GMT * subjectAltName: avs-alexa-na.amazon.com matched * issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4 * SSL certificate verify ok. > POST /v20160207/events HTTP/1.1 Host: avs-alexa-na.amazon.com Path: /v20160207/events Authorization:Bearer Atza|IQEBLjAsAhRyEq3-rnxUHMrE3vMuXVlsLk04JAIUWCr3M0vd7zGdWRojJ8DjK8oBpiwQK9T_JFPPZp5Ky4Oo_pPNGvgf8vg5RhBZTekdFLQ-D8mHhN_l0EJqn_FniR-oFaXhcgkvKiqvwO1qXVHnMXSDS1IC-IgV3nSfEG1Iuu0wGcSYm9gtsLPSk4PeA1f52IRkKGzuUGD1ECdR2YwCk-UnfQfFjR1FXdm0NPEGQHTrQrk7ICWvCa2hyaiVohyyQreEearGdXz0PCLpgNEiRjbOTogaSGbHbtwHYltRHBMiHJXuyh6co3ThG1OWwUstd4jZM38clrjxdb0DH4RoArA2nerinAhuXcn7hjy77oJ_Vhj1_likBK7QLaJn-eoy4FuWOQT6N9Yy9V_2JFPrdqtsoCR9ZBM5rWMxiwdCAxrLomV7yPf0TDjA4ualrnbxHrI8CJy8z7noVxvSre0ITLBdMyZXV1Xf-s_-NDSU7nS2JqmCTWEu8JWMKXx3yFa31Jnx9TkjnbARtbCitofjyGqFiRzhc9j6KYmjMVSmrBErphXyQ7Bwlkq4DPni_uk9jjc5 Transfer-Encoding: chunked Content-type: multipart/form-data; boundary=------------------------8b6319f10989fd5c * SSL_write() returned SYSCALL, errno = 32 * Closing connection 0 CURL_EASY_PERFORM_ERR:55 I donot know why this is the cause of the problem? :( The libcurl already is installed with SSL support, using the base system OpenSSL and the libcurl is latest version - v7.48.0 Have any ideas on how to fix this or debug further?
alexa voice service
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

hi seven,

I also need to use C to implement AVS. But it is first to use libcurl and http/2. Cloud you share your test code to me too? My email is yangjun9772@126.com. Thx

0 Likes 0 ·
swasey@amazon avatar image
swasey@amazon answered
What version of OpenSSL are you using? You need to be using OpenSSL >= 1.0.2 as that is when ALPN support was added. Versions prior to that only had support for NPN, which our server no longer supports. You can determine this easily by doing curl --version and it will list out the versions of OpenSSL/nghttp2/etc that are used in the build. Also, as an aside, you'll want to use the libcurl multi interface, not the easy interface. The multi interface is required to use a multiplexed connection so that all requests are made using the same connection. If you use just the easy interface you'll have to re-use handles to re-use the connection, which won't allow for having a downchannel open at the same time as event request/response. The server will start to reject requests made on multiple connections and it'll start to cause a headache. Examples of how to use the multi interface with HTTP2 can be see in the curl source under docs/examples/http2-download.c, and docs/examples/multi-app.c.
5 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

We also have this problem,I see you said that: "The multi interface is required to use a multiplexed connection so that all requests are made using the same connection". but libcurl doesn't support multi thread to used ths same multi handle to make requests. Do you have some example to show us how to use libcurl make AVS request used the same connection? and how can I keep the connection alive, beause my downchannel request is send in other thread? I downchannel and event send in the same thread, how can I add another event in this connection? waiting for you answer soon, TKS !!!!!!

0 Likes 0 ·

Hey benghopy, you can get around the issue of not being able to use the multi_handle on multiple threads by implementing a simple Producer/Consumer queue. You can push your easy_handles onto a threadsafe queue from any thread, and have your main multi_handle thread pop off those easy_handles and add to the multi when it loops around.

For better performance you can use an event loop like libevent, and when you add your easy_handles to the queue from any other thread you can trigger a user-initiated event on libevent which will execute as soon as it can on the same thread as the multi-handle, and add to it.

Libcurl example code that instead of using a user-triggered event or a queue data structure, uses a FIFO named piped to trigger events, but it's the same basic concept: https://curl.haxx.se/libcurl/c/hiperfifo.html

For triggering user initiated events: http://rxwen.blogspot.com/2012/11/user-event-in-libevent.html

0 Likes 0 ·

Hi swasey, does the events can be send at the same time, such as I have volume change event and music stoped event, can I send them at the same time or I have to send them in order. I also found that if one of easy handle is quit whith timeout or other problem exit the request, the libcurl will reconnect the downchannel's connection, the APP will shows device offline and then online.

0 Likes 0 ·
Show more comments
Show more comments
sevencheng avatar image
sevencheng answered
Thanks for your reply! I have already solved the problem and I will try your advice that using multi interface.:)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swasey@amazon avatar image
swasey@amazon answered
I'm glad you figured out your problem! Do you mind explaining what the problem was? There's another user experiencing the exact same issue, so it'd be great to be able to help that user out as well. Was it not using a newer version of OpenSSL like I suggested, or something else?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sevencheng avatar image
sevencheng answered
Right, this is indeed a casue of openssl and i have upgraded OpenSSL ver. to 1.0.2e.
10 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I'm very glad to see your attempt to implement an AVS interaction through the C language,I have also read the java code for several days.But I got very little things from the code,because I'm a newbie in java and I encountered many problems.When I learned the AVS used HTTP2 protocol,so I searched what is HTTP2,then I found some opensource codes which already implement the protocol,such as nghttp2,Apache HTTP Server 2.4.17+,Deuterium and so on.The website is https://github.com/http2/http2-spec/wiki/Implementations .Nevertheless,I still could not know how to send stream to AVS or how to receive stream from AVS.After several days attempt,I really don't know how to do it,so I searched the questions in this forum again and luckily to see your achievement.I don't know if I can get your help.My Email is : wheretogo0815@163.com .Thank you very much.

0 Likes 0 ·

I have a same plan to development AVS in embedded board. But I can't use libcurl library and so on. Could you share your test code? Please send via email. My email is "skypiri@gmail.com". It will be very helpful to start. Thank you very much.

0 Likes 0 ·

hi, sevencheng. I am using libcurl 7.51.0 openssl 1.0.2 nghttp2 1.17.0, I am writing curl demo to keep long connection with the avs. I am new at this. Can you share your test curl code to me? My email is jian.gao@ingenic.com. Thank you very much!

0 Likes 0 ·
sevencheng avatar image sevencheng newuser-45d680e7-5a81-4274-88b4-756a1fee63ae ·

i only have a simple code and have sent to you email.

0 Likes 0 ·

Hi sevencheng, Could you send the avs demo code to my e-mail jackie.networking@gmail.com?Thanks a lot.

0 Likes 0 ·
Show more comments

hi, sevencheng,

I also have this problem about using curl easy interface to send data fail. Could you kindly share the example about using curl easy interface to send event to AVS?

Since using HTTP/2 is necessary , and I do not know how to use http/2 in cURL. Any input is very appreciated.

my e-mail:soho123.2012@gmail.com

thanks a lot

0 Likes 0 ·

Hi,

You can try to download alexa_demo simple code form CSDN, link:http://blog.csdn.net/sevenjoin/article/details/53581831

0 Likes 0 ·

Hi Seven,

Thank you for your demo.

0 Likes 0 ·
Show more comments
newuser-f2dd0cc4-ba93-4422-bf4d-1d1e4906df1e avatar image
newuser-f2dd0cc4-ba93-4422-bf4d-1d1e4906df1e answered

Hi All,

Can someone send this piece of code to my email : tp.sudhakar@gmail.com As am not able to download the file from the above website.

Thanks,

Paul Sudhakar.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-e362e8ea-17d9-446d-beab-964f6600e293 avatar image
newuser-e362e8ea-17d9-446d-beab-964f6600e293 answered

Hi,

Can someone send this code to my email : SridharVasanth@gmail.com I am unable to download the code from this website.

Thanks.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.