esp32s3 - how to read IP address from serial port?

mgsanava
Posts: 4
Joined: Thu Sep 07, 2023 6:10 am

esp32s3 - how to read IP address from serial port?

Postby mgsanava » Thu Sep 07, 2023 6:22 am

I want to read the IP address assigned to esp32s3 board via serial port (/dev/ttyACM0)

This board is connected to internet via SPI-Ethernet module (w5500) and will be connected to internet on boot up.

Is it possible to read IP address (refer attached image) from bash script?
Attachments
2023-09-07 11-48-44.png
2023-09-07 11-48-44.png (69.99 KiB) Viewed 4584 times

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: esp32s3 - how to read IP address from serial port?

Postby vanBassum » Thu Sep 07, 2023 10:10 am

What is the underlying problem you want to solve?
What you want is possible, but I have a gut feeling that it's not the right solution.

mgsanava
Posts: 4
Joined: Thu Sep 07, 2023 6:10 am

Re: esp32s3 - how to read IP address from serial port?

Postby mgsanava » Thu Sep 07, 2023 11:17 am

I need to upload few files to a location in the server that is running inside the esp32s3 using -

Code: Select all

curl -F 'file=@somefile.zip' http://ipaddr/app/main/
where ipaddr is the local ip address that was assigned to the board.
I'm trying to write a bash script to automate this process.
Something like reading ip address before from board via serial port and then pass it to another script as an argument.
Any better ideas are welcome!

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: esp32s3 - how to read IP address from serial port?

Postby vanBassum » Thu Sep 07, 2023 2:13 pm

How about the otherway around? So the esp uploads to a server?
Or use a broadcast message when the device boots that the other device detects.

btw, still not explaining what the underlying problem is that you want to solve.

mgsanava
Posts: 4
Joined: Thu Sep 07, 2023 6:10 am

Re: esp32s3 - how to read IP address from serial port?

Postby mgsanava » Sat Sep 09, 2023 10:05 am

vanBassum wrote: How about the otherway around? So the esp uploads to a server?
esp is the one that has the a tiny web server running inside it
btw, still not explaining what the underlying problem is that you want to solve.
I am not sure what you are expecting.
The device boots and connects automatically to internet.
Or I can issue this command via bash script (echo "$CMD" > "$PORT") to connect manually - https://realtimelogic.com/ba/ESP32/sour ... etwork-cfg
It then prints out some IP address (192.168.xxx.xxx) which I use to upload files like in my previous posts.

Similarly, is there any command to read that obtained IP address from bash script itself?
I checked the documentation but could not find information related to IP address.

Hope I am clear now. Let me know if you need any other information..

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: esp32s3 - how to read IP address from serial port?

Postby vanBassum » Mon Sep 11, 2023 6:07 am

It's certainly possible to extract the IP address, although I'm not proficient in bash scripting. You might want to explore regular expressions (regex) for this purpose.

However, I'd like to reiterate the importance of understanding the underlying problem you're trying to solve. Currently, you're describing the solution you have in mind, but it's crucial to clarify the specific problem you're addressing with this solution. For instance, is the problem something like this:
"During production, I need to configure the ESP project with a settings file before shipping to the customers."

In my previous message, I suggested an alternative approach where the ESP32 acts as a client and downloads the required files from a web server. This change in perspective can simplify your setup and potentially lead to a more effective solution. But to evaluate its suitability, I need to grasp the core issue you're aiming to resolve.

Could you please provide more details about the problem you're trying to solve? This will enable us to offer a more targeted and effective solution.

If you really want to stick with your solution, I guess you can do something like this: (This script came from AI, haven't tested this.)

Code: Select all

#!/bin/bash

# Serial port device
SERIAL_PORT="/dev/ttyACM0"

# Command to send to ESP32 to obtain IP address
CMD="get_ip_address_command"  # Replace with the actual command

# Send the command to the ESP32 and capture the output
IP_ADDRESS=$(echo "$CMD" > "$SERIAL_PORT" && cat "$SERIAL_PORT")

# Parse the IP address from the captured output (adjust this part based on the actual output format)
IP_ADDRESS=$(echo "$IP_ADDRESS" | grep -oE "Ethernet ip: ([0-9]{1,3}\.){3}[0-9]{1,3}")

mgsanava
Posts: 4
Joined: Thu Sep 07, 2023 6:10 am

Re: esp32s3 - how to read IP address from serial port?

Postby mgsanava » Fri Sep 22, 2023 7:18 am

Thanks! It is working.
Actually I'm using a script which is very similar to what you have posted. Of course it was generated by AI as well.

I will surely look into your suggestion about the other way of downloading data via server when I get time.

Who is online

Users browsing this forum: Google [Bot] and 96 guests