Change R2 to 2.2K and add a shunt 300 ohm from
the long wire's close-in end to ground. That will make
a safe-ish 3.2V from 24V which your switch can further
jam to GND when closed.
You might add some parallel C to your new resistor,
to both debounce and suppress HF radiated EMI
incoming.
You might consider adding a cheap 3.3V CMOS logic
Schmitt trigger inverter as a "bouncer at the door",
socketed even, so that you can learn about the ugly
realities along and at the far end of the wire with less
pain. Then your uC will be guaranteed to receive logic
level signals and not latch up while you're messing.