Skip to content

Commit e0d6df4

Browse files
authored
Update platform.py
1 parent af59ec9 commit e0d6df4

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

platform.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import contextlib
1717
import json
1818
import requests
19+
import socket
1920
import subprocess
2021
import sys
2122
import shutil
@@ -84,6 +85,13 @@
8485
# Configure logger
8586
logger = logging.getLogger(__name__)
8687

88+
def is_internet_available():
89+
"""Check if connected to Internet"""
90+
try:
91+
with socket.create_connection(("8.8.8.8", 53), timeout=3):
92+
return True
93+
except OSError:
94+
return False
8795

8896
def safe_file_operation(operation_func):
8997
"""Decorator for safe filesystem operations with error handling."""
@@ -301,17 +309,18 @@ def _configure_arduino_framework(self, frameworks: List[str]) -> None:
301309
self.packages["framework-arduinoespressif32"]["optional"] = False
302310
self.packages["framework-arduinoespressif32-libs"]["optional"] = False
303311

304-
# Use branch master
305-
url = ("https://raw.githubusercontent.com/espressif/arduino-esp32/"
306-
"master/package/package_esp32_index.template.json")
307-
try:
308-
response = requests.get(url, timeout=30)
309-
response.raise_for_status()
310-
packjdata = response.json()
311-
dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url']
312-
self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url
313-
except (requests.RequestException, KeyError, IndexError) as e:
314-
logger.error(f"Failed to fetch Arduino framework library URL: {e}")
312+
if is_internet_available():
313+
# Use branch master
314+
url = ("https://raw.githubusercontent.com/espressif/arduino-esp32/"
315+
"master/package/package_esp32_index.template.json")
316+
try:
317+
response = requests.get(url, timeout=30)
318+
response.raise_for_status()
319+
packjdata = response.json()
320+
dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url']
321+
self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url
322+
except (requests.RequestException, KeyError, IndexError) as e:
323+
logger.error(f"Failed to fetch Arduino framework library URL: {e}")
315324

316325
def _configure_espidf_framework(
317326
self, frameworks: List[str], variables: Dict, board_config: Dict, mcu: str

0 commit comments

Comments
 (0)