Black Lives Matter - Action and Equality.
0

connection dropping out
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

connection dropping out

by cbrucewarren on Sun Apr 12, 2020 1:13 am

I am getting this error, some times after a few hours, sometimes after a day or so .. the timing is not consistent.
The error output is:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 80, in create_connection
raise err
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7586e8d0>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/cbrucewarren/feeds/rpi-testing/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7586e8d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/MyPython/testBMP.py", line 30, in <module>
aio.send("rpi-testing", bmp280.temperature)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 154, in send_data
return self.create_data(feed, payload)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 254, in create_data
return Data.from_dict(self._post(path, data._asdict()))
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 126, in _post
data=json.dumps(data))
File "/usr/lib/python3/dist-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/cbrucewarren/feeds/rpi-testing/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7586e8d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))


Whenever I restart the program, it connects immediately.
here is the simple code I am running to test the Adafruit IO:

Code: Select all | TOGGLE FULL SIZE
import time

import board

# import digitalio # For use with SPI
import busio

import adafruit_bmp280
from Adafruit_IO import *

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
aio = Client( 'cbrucewarren','i deleted the key ')  # user ID and Key
# OR create library object using our Bus SPI port
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bmp_cs = digitalio.DigitalInOut(board.D10)
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)

# change this to match the location's pressure (hPa) at sea level
bmp280.sea_level_pressure = 1011.25
count = 0
while True:
    print("\nTemperature: %0.1f C" % bmp280.temperature)
    print("Pressure: %0.1f hPa" % bmp280.pressure)
    print("Altitude = %0.2f meters" % bmp280.altitude)
    print("Data Count = %0.1f" % count)
    # print((bmp280.temperature,))
    count = count +1
    aio.send("rpi-testing", bmp280.temperature)
    aio.send("rpi-pressure", bmp280.pressure)
    aio.send("rpi-count",count)
    time.sleep(300)

cbrucewarren
 
Posts: 66
Joined: Sun Mar 09, 2014 1:57 pm

Re: connection dropping out

by brubell on Wed Apr 15, 2020 12:52 pm

This error means that the network is unreachable, there is a problem with the connection to the internet. Likely due to your network or potential firewall/proxy settings.

Do you have a proxy connection enabled on the the hardware you're using.

or, do you have a firewall for your network?

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Re: connection dropping out

by cbrucewarren on Fri Apr 17, 2020 1:56 am

No proxy or firewall.

cbrucewarren
 
Posts: 66
Joined: Sun Mar 09, 2014 1:57 pm

Re: connection dropping out

by brubell on Sat Apr 18, 2020 9:52 am

Ok, "Network is unreachable" sounds like your Pi can't find (DNS resolve) io.adafruit.com. DNS servers, ISP, your router, the RPi itself? Basically, any piece of the networking stack in between the device and Adafruit IO's servers could be at fault :(

Since it seems to be consistent and on a clock, if it were me, I'd check my router's settings and Pi's crontab. After that, I'd try to attach some sort of network check script or schedule a network check at the same time. For example, echo "[$(date)] $(curl --head https://www.google.com | head -n1)" to get a timestamp + status check on a this-really-ought-to-be-reachable address.

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.