2

I have an ESP32 recording values from an ADC at a rate of 1 sample/second.

I need the ESP32 to send new values to a device (let's say a smartphone app for now, eventually via a server), as they are recorder on the ADC.

I've been wondering which is the best way to go about this :

  • Option 1: [what I've got set up now] The iOS app sens a request for a new value every second. The ESP32 then sends a response, which contains an array of every value recorded since the last request. Problem: This seems costly and very... 'lazy' (can't word it better, it just doesn't feel like a good approach)

  • Option 2: the iOS app sends a request to 'subscribe' for changes in the ESP's ADC. Is this considered good practice ? which is the best way to go about this ? Google search with keywprds 'ESP32' 'http' 'stream' 'ADC' yielded results with audio and video applications

  • Option 3: ESP POSTs new values to server. iOS app then retrives them by requesting them from server OR server pushes latest values to app.

I've been researching this for the past two days, unsuccessfully. I'm not very experienced with this, which means I don't know the right terms & keywords to research this without asking for a lead...

kmn
  • 121
  • 1

1 Answers1

5

From what you're asking, I believe you should use MQTT protocol, it seems to fit your architecture. You'll need to have a mqtt server/broker that will receive the data from the device and then send them to the app.

Simply put in MQTT protocol you'd have "topics" that the client (your app) will subscribe to. The device will push it's data to the topic and the subscriber will receive the new data on a notification.

For instance :

you'll subscribe to the topic at your_broker.com/mqtt/deviceA/temperature the device A will push it's data to the broker (whenever it can), and then the broker will send the new data (if possible) to all client that have subscribed to the topic deviceA/temperature.

See : http://mqtt.org/ and https://github.com/espressif/esp-mqtt

You can try to build another custom architecture but this one is pretty good and pretty lightweight. Plus it's very easy to deploy and to scale.

YCN-
  • 473
  • 2
  • 10