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

GRPC Example? (IDFGH-1026) #3352

Open
eagi223 opened this issue Apr 23, 2019 · 21 comments
Open

GRPC Example? (IDFGH-1026) #3352

eagi223 opened this issue Apr 23, 2019 · 21 comments

Comments

@eagi223
Copy link

eagi223 commented Apr 23, 2019

This isn't an issue, but more of a feature request I suppose. This has been asked in the forum, but the thread hasn't had a reply since February...

here

So it looks like the ESP Voice Assistant SDK uses Google Dialogflow through the gRPC hooks. Is there any way we could get a generic example of using gRPC in the IDF? Or maybe someone out there has some code they'd like to share where they've implemented gRPC on the ESP32?

@github-actions github-actions bot changed the title GRPC Example? GRPC Example? (IDFGH-1026) Apr 23, 2019
@dhrishi
Copy link
Collaborator

dhrishi commented Apr 25, 2019

Hi @eagi223 We will add this to the to-do list. Although, for now, I do not have concrete timelines for that.

@eagi223
Copy link
Author

eagi223 commented Apr 25, 2019

That would be great! In the meantime I'll keep trying to figure it out.

@kroggen
Copy link

kroggen commented Jun 10, 2019

I'm interested in the gRPC example on ESP32 too.

I checked the esp-va-sdk repo but was not able to find anything. The code appears to be inside of the libdialogflow.a library.

By the way, there are people interested in this topic since 2016:

https://twitter.com/proppy/status/800767976244854784

@kroggen
Copy link

kroggen commented Jun 13, 2019

Could you inform if you are using Juniper/grpc-c or just sending the raw protocol buffer packets via HTTP2 ?

Are you using sh2lib for that?

@SERIDJ
Copy link

SERIDJ commented Jan 20, 2020

hi, @eagi223 @dhrishi @kroggen someone have news about grpc in ESP device . ?

@sh0umik
Copy link

sh0umik commented Jan 20, 2020

i am interested too .. any news or solutions ?

@kroggen
Copy link

kroggen commented Jan 21, 2020

I did it manually encoding and decoding the protocol-buffers packets using nanopb and sending them using sh2lib.

I cannot share the code now but you can check these tutorials:

https://techtutorialsx.com/2018/10/19/esp32-esp8266-arduino-protocol-buffers/

https://techtutorialsx.com/2019/01/04/esp32-http-2-post-request-with-headers/

@SERIDJ
Copy link

SERIDJ commented Jan 21, 2020

@kroggen , Thanks very much for your quick reply, i have run encoding code in esp32 using first tutorial , but i dont know more about deconding data from my server (visual studio c#).

and what u thing about PJON-GRPC : https://github.com/Halytskyi/PJON-gRPC ??

@kroggen
Copy link

kroggen commented Jan 21, 2020

This PJON is new to me. I never used it.

But if you have control over the server, why not just use a simple JSON or Binn and simple HTTP?

I had to use GRPC simply because the server already exists and the only option was to comply with it.

Protocol-buffers in C sucks!

@SERIDJ
Copy link

SERIDJ commented Jan 21, 2020

@kroggen i dont know if i can use it and i want to HTTPS i hope that not a problem ?

@99bit
Copy link

99bit commented May 17, 2020

@kroggen

Is there any updates about gRPC ??!

@kroggen
Copy link

kroggen commented May 18, 2020

Hi,

I don't know any easy solution to use GRPC on ESP32, but I can share what I did.

I separated the process in 2 parts:

  1. Encoding and decoding the messages using nanopb (check the examples above)
  2. Calling the service function via HTTP2 using sh2lib and sending the encoded message as payload (and decoding the received message)

Just the protobuf encoded message is not sufficient as payload, we need to add 5 bytes before to comply with the HTTP2 spec. The first byte must be zero (meaning no compression) and the remaining 4 bytes are the size of the message in big endian.

I just released the project that uses this method. You can check the sources here

You can start by the send_grpc_request function

@Hiabuto-de
Copy link

Hm. Any Updates on this ? - We wan't to start a bigger Project with Ethernet, gRPC and CAN on ESP32, but gRPC is neccesary for this :-/

@tomatac
Copy link

tomatac commented Feb 28, 2021

This is a very interesting idea! Is anybody working on this feature? It would be great.

@adammruk
Copy link

Same - grpc example would be great

@Davide-Di-Do
Copy link

Hi everyone, I'm currently working on an IoT system where the device and the backend communicate with GRPC protocol. Take a look here with minimal working code. https://github.com/iot-tetracube-red/iot-grp-tech-demo

@DatanoiseTV
Copy link

@Davide-Di-Do Seems like your repo is no longer existent. Could you give me some insight?

@JohnGalt1717
Copy link

I'd love to see this too.

@chrisomatic
Copy link

Hi,

I don't know any easy solution to use GRPC on ESP32, but I can share what I did.

I separated the process in 2 parts:

  1. Encoding and decoding the messages using nanopb (check the examples above)
  2. Calling the service function via HTTP2 using sh2lib and sending the encoded message as payload (and decoding the received message)

Just the protobuf encoded message is not sufficient as payload, we need to add 5 bytes before to comply with the HTTP2 spec. The first byte must be zero (meaning no compression) and the remaining 4 bytes are the size of the message in big endian.

I just released the project that uses this method. You can check the sources here

You can start by the send_grpc_request function

@kroggen Thanks for sharing your code and suggestions here. It helped me quite a bit. And it seems like you're right about the prepended 5 bytes. My example code is working now. But looking at the HTTP2 spec, I can't find any mention of these bytes.

https://datatracker.ietf.org/doc/html/rfc7540

The DATA frame just has optional padding bytes, and the frame format is quite different. I figured NGHTTP2 handles most of this formatting for me, but clearly the first 5 bytes are required. Maybe I'm missing something, am I looking at the wrong spec?

Thanks,
Chris

@kroggen
Copy link

kroggen commented Aug 22, 2022

@chrisomatic
It has been a long time, I do not remember where I got that information. Probably read on some source-code or analyzed data packets

@chrisomatic
Copy link

@chrisomatic It has been a long time, I do not remember where I got that information. Probably read on some source-code or analyzed data packets

Thanks for your reply! I just found the reason for this so Ill document it here.

The 5 bytes (no compression + length) are a gRPC Message header for the HTTP/2 DATA frames. More details here: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

Screenshot_20220822-182516_Brave

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