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}")