Communicating to ESP32 from PC Host - Designing for Production

fermienrico
Posts: 11
Joined: Sat Oct 14, 2017 6:31 am

Communicating to ESP32 from PC Host - Designing for Production

Postby fermienrico » Sat Oct 14, 2017 6:50 am

Hello,

First of all, thank you to the wonderful people that make up the ESP community. I have a general question, which hopefully, I can narrow down to enough specifics to better present my issue.

I am working on a project which is in a prototype stage, but we plan to eventually mass produce it (Approx 1000 quantity). It is an industrial IOT device and that communicates to a PC (Windows or Linux). ESP32-embedded device is physically close to the PC and has all methods of communication available - i.e., USB, UART, BT, Wifi.
  • Communication is bidirectional - PC <--> ESP32
  • Bandwidth requirement is very minimal - only a few bytes of data every 1 second.
  • PC application is not finalized and can be written in any language (Python, C, C# .Net, Java). There is a lot of flexibility with regards to the host software.
  • No power requirements or limitations. ESP32-device board is already planned to be powered using a USB power rail.
  • If ESP32-device is connected, PC host needs to automatically detect the device and start communicating.
  • When PC host boots, ESP32-device (if it is already connected) should be ready for transfer of data.
  • If needed, we can purchase a Vendor ID for USB protocol.
I am seeking advice as to how best to approach this type of communication?

I am exploring the following options:
  • UART - The problem is that the device connected is through a COM port and it is not possible to burden the user to select the correct port.
  • USB - I am looking at options for developing a full fleged windows driver but it seems like a daunting task. USB protocol is very complex for a beginner. I've been reading about PyUSB and other easy to use USB libraries.
Would Bluetooth or Wifi be easier?

Thank you, I apologize if my question is too broad - it is mainly because of my lack of familiarty in building peripheral devices and I am happy to learn more.

- Fermi

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Communicating to ESP32 from PC Host - Designing for Production

Postby kolban » Sat Oct 14, 2017 3:31 pm

From what I am hearing you say, BT, UART and WiFi all seem to be in play. Playing devils advocate here ... why not be generic and support all three? That way you will be super-loosely coupled between the PC and the ESP32 no matter what comes along. However if I were to choose just one, I'd likely suggest WiFi as it offers the most flexibility. You didn't mention what is available on the PC side of the house... whether we can be assured of WiFi, BT and/or UART always being available. The down-side of WiFi is that you would likely have to provide a mechanism to configure your ESP32 devices to connect to your environmental WiFi access point but that is surmountable and has been solved on previous occasions.

The use of BT BLE is also attractive and would require minimal setup ... but would require that the PC also supports BLE. If it isn't native to the PC, a USB BLE attachment can be picked up relatively cheaply. I'd also suggest running a field test in example locations to ensure that in your industrial location there is no significant radio interference that would preclude one or the other.

Above the communication transport you next need to start thinking about payload formats and protocols. If you only have a few bytes per second then almost everything is open. From my perspective, this could be either REST requests or MQTT as a protocol with JSON as the data encoding.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

fermienrico
Posts: 11
Joined: Sat Oct 14, 2017 6:31 am

Re: Communicating to ESP32 from PC Host - Designing for Production

Postby fermienrico » Sat Oct 14, 2017 3:54 pm

@nkolban

Thank you for your insight. Yes, indeed, all options are available to us and we can generically implement all. However, we must start with a solid comm protocol and then add, say, for instance, BLE & Wifi later.

I am leaning towards UART/USB, but a follow-up question I have tried to Google on StackOverflow and other support sites but with no answers.
  • Regardless of the device protocol, how can the host be 100% sure that our ESP32 is connected? Using USB, there is the idea of Vendor ID / Product ID. How does it work with Wifi / BLE? Is there a standard or we just need to program our own homegrown solution for surveying devices > sending an identification message > esp32 responds with an acknowledgment.
Payload - Thanks, I will try to research your suggestions. JSON might be the easiest as I am familiar with it.

Regarding USB:
- Can ESP32 act as a USB host and the PC as a slave?

fermienrico
Posts: 11
Joined: Sat Oct 14, 2017 6:31 am

Re: Communicating to ESP32 from PC Host - Designing for Production

Postby fermienrico » Sat Oct 14, 2017 4:37 pm

I am sorry, I just realized that ESP32 doesn't have native USB support. Hence the confusion.

Ok, so at this point, for serial port comm, I am thinking of using a USB to UART chip, perhaps the same exact one that is built into the ESP32-DevKitC module from SI Labs. They also offer a handy USB Driver Customization tool:

https://www.silabs.com/documents/public ... /an220.pdf

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Communicating to ESP32 from PC Host - Designing for Production

Postby kolban » Sat Oct 14, 2017 8:25 pm

Depending on the nature of your application, a protocol such as MQTT over TCP/IP over WiFi might be suitable. One of the strengths of MQTT is that it is a queuing mechanism meaning that if there is a disruption in communication, messages need not be lost and can be locally queued for either pickup or delivery.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Champ76
Posts: 2
Joined: Fri Feb 16, 2018 8:30 am

Re: Communicating to ESP32 from PC Host - Designing for Production

Postby Champ76 » Fri Feb 16, 2018 1:40 pm

I am also doing development similar to @fermienrico.
I have developed code for ESP32 in Arduino IDE. ESP32 working in access point mode.
I have developed Java code on windows machine which scan nearby WiFi device and connect to it. I am able to connect to ESP32 from windows machine and both side (ESP32 and windows machine) I am able to get MAC address but not able to get IP address.
I need to communicate with ESP32 means need to send data in JSON format and but I don't have any idea how to achieve it.

Can anyone help me to solve problem? Any help would be greatly appreciated!

Who is online

Users browsing this forum: No registered users and 101 guests