I’ve seen multiple things I’d do differently but each of them by itself wouldn’t explain your issue.
However, they might interact in some non-obvious way to lead to some undesirable effects.
e.g. I’d not do this
attachInterrupt(WindSensorPin, isr_rotation, FALLING);
delay(3000);
detachInterrupt(WindSensorPin);
I’d rather leave the interrupt attached and avoid the delay()
.
I already have previously suggested some better way to update your display here (I’m somewhat wondering why I wasted my time to offer these suggestions since I didn’t even get a reply on that post).
Additionally these elaborate calculations may also benefit from some rework.
BTW, what kind of WindSensor are you using?
Does it have an external pull-up resistor attached?
If not, you need to set pinMode(WindSensorPin, INPUT_PULLUP);
However, one thing that would cause your code to block while it’s not connected is that you are calling Particle.publish()
irrespective of the connection. This is bad.
But this shouldn’t prevent an automatic reconnect.
Try this (slightly) cleand-up code
https://go.particle.io/shared_apps/5ce1777bec6e390005e3f612