#!/usr/bin/env bash
# AutoSense Flash Tool - ESP8266 (NodeMCU v2 / 4MB flash)
# Requires: Python + esptool (pip install esptool)
set -e

read -p "Enter the serial port your ESP8266 is connected to (e.g. /dev/ttyUSB0 or /dev/cu.usbserial-XXXX): " PORT

python3 -m esptool --chip esp8266 --port "$PORT" --baud 460800 write_flash -z \
  --flash_mode dout --flash_freq 40m --flash_size 4MB \
  0x0      bin/esp8266/firmware.bin \
  0x300000 bin/esp8266/littlefs.bin

echo "Done. Disconnect and power-cycle the device."
