0

I have a Pi Zero that is always running a Python script connected to a MySQL database on a website I am hosting. Every 5 seconds, the Pi updates a time field in the database, and there is a cron job that runs on the website every minute which checks that the timestamp has been updated within the past 60 seconds. If not, it sends an email to notify me that the Pi is down, and once the timestamp in the database has been updated, it notifies me that the Pi is up again.

I have noticed when my home Internet goes down for a short period of time like a few minutes or less, it often takes the Pi approximately 15 minutes to reconnect. Other devices on my network reconnect as soon as the Internet is up again. I am using the official Raspberry Pi USB Wi-Fi dongle with my Zero, and have observed the same behavior on a Pi 2.

I don't understand why there is this delay for the Internet on the Pi to reconnect. Has anyone else experienced this and figured out how to fix it? Thank you.

tjohnson
  • 408
  • 2
  • 12
  • 1
    Very applicable: https://raspberrypi.stackexchange.com/q/4120/24224 – Aloha Aug 04 '17 at 09:07
  • Thank you, I had seen that question before but ignored the downvoted answer. It turned out that it contained the link which was most useful for me: http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/ – tjohnson Aug 08 '17 at 04:09
  • This is a problem for me again now, with Raspbian Stretch the old method doesn't work – tjohnson Oct 26 '17 at 01:56
  • Turns out the problem had nothing to do with Wi-Fi staying disconnected. If the SQL database lost connection, the query would hang for up to 15 minutes trying to reconnect and failing for some reason. To work around this, I ended up using the multiprocessing module to run each query as a separate process, with a forced timeout. – tjohnson Feb 19 '18 at 21:41

0 Answers0