Skip to content

Commit ee24881

Browse files
authored
check for Inet before trying to fetch newest develop Arduino (#193)
* check for Inet and fallback to standard config
1 parent 381a557 commit ee24881

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

platform.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import socket
1617
import contextlib
1718
import requests
1819
import json
@@ -37,6 +38,14 @@
3738
python_exe = get_pythonexe_path()
3839
pm = ToolPackageManager()
3940

41+
def is_internet_available():
42+
"""Check if connected to Internet"""
43+
try:
44+
with socket.create_connection(("8.8.8.8", 53), timeout=3):
45+
return True
46+
except OSError:
47+
return False
48+
4049
class Espressif32Platform(PlatformBase):
4150
def configure_default_packages(self, variables, targets):
4251
if not variables.get("board"):
@@ -128,11 +137,22 @@ def install_tool(TOOL, retry_count=0):
128137
if "arduino" in frameworks:
129138
self.packages["framework-arduinoespressif32"]["optional"] = False
130139
self.packages["framework-arduinoespressif32-libs"]["optional"] = False
131-
# use branch master
132-
URL = "https://raw.githubusercontent.com/espressif/arduino-esp32/master/package/package_esp32_index.template.json"
133-
packjdata = requests.get(URL).json()
134-
dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url']
135-
self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url
140+
if is_internet_available():
141+
try:
142+
# use branch master
143+
URL = (
144+
"https://raw.githubusercontent.com/espressif/arduino-esp32/master/"
145+
"package/package_esp32_index.template.json"
146+
)
147+
response = requests.get(URL, timeout=10)
148+
response.raise_for_status()
149+
packjdata = response.json()
150+
dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url']
151+
self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url
152+
except (requests.RequestException, ValueError, KeyError, IndexError) as e:
153+
print(f"Error loading latest Arduino ESP32 libs: {e}")
154+
else:
155+
print("No Internet connection - using local/standard configuration")
136156

137157
if variables.get("custom_sdkconfig") is not None or len(str(board_sdkconfig)) > 3:
138158
frameworks.append("espidf")

0 commit comments

Comments
 (0)