logo elektroda
logo elektroda
X
logo elektroda

How do I send a message from the ESP32 to a specific IP over WiFi?

madiz08 873 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18544511
    madiz08
    Level 14  
    Code: C / C++
    Log in, to see the code
    .
    I can, using the above commands, send a reply back to the sender. In the above case, that message would be " return text1 ".
    What I don't know is how to initiate sending a message via wifi to a specific IP address.
    Let's say I want to send "perform_task_1" to a device with address 192.168.0.99, something like:
    192.168.0.99/wykonaj_zadanie_1
    Normally I do this in reverse order by sending something like this to the ESP32 and in response I use client.println(); ( WiFiClient), but now I'd like to do it the other way around, on the principle that the ESP32 sends a message and receives an acknowledgement
  • ADVERTISEMENT
  • Helpful post
    #2 18544593
    ekrzychoooo
    Level 17  
    madiz08 wrote:
    to the device with address 192.168.0.99
    .
    This device should be the server. This can be done in a number of ways see Link .
  • ADVERTISEMENT
  • #3 18544629
    madiz08
    Level 14  
    I don't think so, after all it is a wifi client in this link. i.e. when something comes into the ESP32 and the ESP32 responds, and I would like it to be the ESP32 that initialises the sending of the data

    Added after 18 [minutes]:

    But anyway my phone with address 192.168.0.99 must be the server? In that case, I think it would be more convenient to do it on the basis of continuous polling of the ESP32, and when the feedback is as expected, further actions will be performed.
    In general, I have several modules at home for suppli, light, blinds, etc., which can be activated via appropriate links. I also have a voice recognition module. I wanted the phone to be voice activated (via esp32 which has this voice module). The phone then activates voice listening and already accepts a specific command
  • Helpful post
    #4 18544689
    ekrzychoooo
    Level 17  
    For the sake of this discussion, I think it is necessary to name these devices, because there will be a lot of misunderstandings
    - ESP_A device receives an http request and, based on that, performs an action - server
    - ESP_B device sends an http request - client

    and now: on device A there should be a server-type soft
  • Helpful post
    #5 18545566
    khoam
    Level 42  
    madiz08 wrote:
    and I'd like it to be the ESP32 that initialises the sending of data
    .
    This would mean that the smartphone would have to "listen" on a specific IP port to see if any packets from the ESP32 have come in, all the while being logged into the same WiFi network as the ESP32. Not a good idea, because opening a port on a smartphone in this way is asking for trouble (just verifying the sender's address is not enough).

    madiz08 wrote:
    I wanted the phone to be voice activated (via esp32 having this voice module). then the phone activates voice listening and already accepts a specific command
    .
    You also have BLE on the ESP32, so you could make something like a "remote control" for the smartphone.
    https://randomnerdtutorials.com/esp32-bluetooth-low-energy-ble-arduino-ide/
    https://iotbyhvm.ooo/esp32-ble-tutorials/
    https://github.com/espressif/arduino-esp32/tree/master/libraries/BLE/examples

    Of course, the alternative is still to initiate connectivity via the smartphone and regularly query the ESP32 (server) to see if there is something 'to do'.
  • ADVERTISEMENT
  • #6 18545594
    madiz08
    Level 14  
    Well, yes, Bluetooth! I'm going to sit down to this topic right away!
  • #7 18545629
    TvWidget
    Level 38  
    madiz08 wrote:
    Well, Bluetooth! I'm going to sit down to this topic right away!
    .
    The main problem you'll encounter is forcing the app to work when the smartphone goes to sleep. Newer versions of the Android system have more restrictions in this respect.
  • ADVERTISEMENT
  • Helpful post
    #8 18546618
    LED5W
    Level 34  
    If this has to be handled by the browser then the simplest solution is long polling. Another way is to use WebSocket. There is also Push API , but still in experimental version.
    In any case, you have to send something every now and then to check if the connection is broken. You have to send from the browser, because only the browser can make the connection, it cannot be the server.

Topic summary

The discussion revolves around sending messages from an ESP32 device to a specific IP address over WiFi. The user seeks to initiate communication from the ESP32 to a smartphone at IP 192.168.0.99, sending a command like "perform_task_1". Responses clarify that the ESP32 can act as a client, sending HTTP requests to a server (the smartphone), which must be set up to listen for incoming requests. Suggestions include using long polling, WebSocket, or Bluetooth Low Energy (BLE) for communication. Concerns about smartphone security and app functionality during sleep mode are also raised, emphasizing the need for a reliable connection method.
Summary generated by the language model.
ADVERTISEMENT