My Photon weather station sends data to a serial LCD display via a pair of RN42 (Sparkfun BlueSmirf Gold) modules. Normally, this works very well but a couple of times a month, the connection mysteriously drops and both modules start flashing red. I have to manually connect to the Photon’s RN42 from my phone’s Bluetooth terminal app, put the RN42 into command mode, and then reboot it (“R,1”). That’s a pain.
I have it in auto mode so it immediately recoonects upon booting. But I’d like the Photon to reboot the Bluetooth automatically when the connection drops. But how to do that?
The RN42 manual shows a GPIO pin, GPIO2 that does exactly what I want. When this pin is high, the device is connected. When it’s low, it’s disconnected. I could have the Photon monitor this and send a R,1 whenever GPIO2 goes low. Unfortunately, on the RN42 all the GPIO “pins” are virtual and their state can only be accessed via the UART. But that’s busy sending data. The Photon happily continues to send data to the RN42 even after the connection drops.
It’s not really an option to continually put the RN42 in command mode to check for an event that only happens a few times a month. The manual doesn’t give a command to read GPIO2 anyway. So is there any way to read GPIO2 out of band on the RN42?
One thing I thought of would be to just connect RX to TX on the receiving RN42 to echo all its received data back out and then periodically do a serial.read on the Photon. If that fails, then the connection has been lost. Would that work? Is there a better way?