title: Raspberry Pi access to internal ESP8266 webserver fails, but Pi and ESP8266 are online in general
body: <p>OK, trying to troubleshoot a problem that is sort of difficult for me to describe. I have a simple webpage being hosted on an ESP8266. The webpage displays the results of a current sensor attached to my sump pump. It works great and I am able to access it from my phone via internal IP address.</p>
  <p>I decided to expand the project a year ago and scrape that webpage to collect pump runs, combine it with some rainfall data, and make a simple plot. This has worked quite steadily for almost a year, but lately some problems have crept in, and I am struggling to understand what is going on.</p>
  <p>The ESP8266 seems to be functioning just like it always has. I can access its simple webpage at any time, no problem. I have limited access to it (hardware) and did not set up OTA, so I have been treating it as a fixed thing, at least until I convince myself otherwise.</p>
  <p>On the Pi (Pi 0 W) I am using the requests module to get the webpage data, then using pandas to extract the &quot;last run&quot; table entry and log it if it has changed.</p>
  <pre><code>   # The function to grab the current value
  def getPoint():
          IPaddress = 888
          try:
                  IPaddress = socket.gethostbyname(&quot;myPi0.local&quot;)
                  url             = 'http://192.168.1.32' # update ESP sensor IP address if needed
                  readData = requests.get(url,timeout=5.0)
                  data            = pandas.read_html(readData.content)
                  data2           = data[0] # grab first one
                  data3           = pandas.DataFrame(data2) # frame it so the values are accessible
                  data4           = [data3.loc[1,1],data3.loc[2,1]]   # status is first row second column
          except:
  #               IPaddress = socket.gethostbyname(socket.gethostname())
                  data4           = [9990,IPaddress]
          return  data4  #.astype('object') # send it back as object (may not be needed)
  </code></pre>
  <p>The socket.gethostbyname line was an attempt to check if the Pi was online from some early programming iterations. The except block has functioned to show some times when I had the router offline.</p>
  <p>So that function should timeout after 5 seconds. (I notice that if it times out, I am not sure what returns. So that is something to determine.) It send back the data point and other logic deal with daily run numbers and logs it.</p>
  <p>This was all running without any noticed problems for months until just a couple weeks ago. I noticed that the logged runs did not reflect reality, with runs being missed. So I ran another script that also tries to grab the data and times how long it takes, and if it fails it logs that fact.</p>
  <p>With that logger running I starting noticing large chunks where <code>requests.get(url)</code> was failing. But, I could still access the ESP8266 webpage. So I thought maybe the Pi was somehow going offline.</p>
  <p>But I noticed I was able to SSH (via putty) into the Pi and everything seemed to be working fine. Everything except for being able to communicate with the ESP8266.</p>
  <p>While logged into the Pi, I try to ping the ESP8266, fail. But again, from my phone no problem accessing the ESP8266. I try pinging the base router (just to try something) and it works. I try pinging google (8.8.8.8) and it works.</p>
  <p>Without having a real good reason for doing it, I issued a</p>
  <pre><code>sudo ifconfig wlan0 down &amp;&amp; sudo ifconfig wlan0 up
  </code></pre>
  <p>command. And then I was able to ping the ESP8266, and everything seems to run normal until the next time it fails. Maybe a day later, maybe a couple days, maybe a few hours.</p>
  <p>I am not sure where to go from here. Sorry the explanation is not super clear.</p>
  <ol>
  <li>ESP8266 is running via ESPAsyncTCP.h on port 80</li>
  <li>Router is Nighthawk RAX48, and this was new a couple months ago and no issues noticed at first (I think...)</li>
  <li>Pi is running PRETTY_NAME=&quot;Raspbian GNU/Linux 10 (buster)&quot;</li>
  <li>The main Pi script only waits 10 seconds in between checks, and the 'checker' script is not running all the time.</li>
  <li>There is nothing else running on the Pi continuously from me. A weekly and monthly one time scripts do run via crontab.</li>
  <li>I have kept the Pi updated and upgraded semi-regularly.</li>
  </ol>
  <p>Anyone have some other troubleshooting steps to recommend?</p>
  <p>Thanks</p>