You have the node wired: a reed switch on GPIO4, an LED on GPIO5. Now write the loop the chip runs forever: read the input, decide, drive the output, and do it without ever stopping to watch. Pick the right line at each step. The wrong lines are the bugs that look fine and fail on the bench.
Every line you kept is the one that survives contact with the bench. Here is how that loop behaves, pass by pass; the exact serial strings will be whatever your node prints, captured on the bench: