|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import os
|
| 16 | +import socket |
16 | 17 | import contextlib
|
17 | 18 | import requests
|
18 | 19 | import json
|
|
37 | 38 | python_exe = get_pythonexe_path()
|
38 | 39 | pm = ToolPackageManager()
|
39 | 40 |
|
| 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 | + |
40 | 49 | class Espressif32Platform(PlatformBase):
|
41 | 50 | def configure_default_packages(self, variables, targets):
|
42 | 51 | if not variables.get("board"):
|
@@ -128,11 +137,22 @@ def install_tool(TOOL, retry_count=0):
|
128 | 137 | if "arduino" in frameworks:
|
129 | 138 | self.packages["framework-arduinoespressif32"]["optional"] = False
|
130 | 139 | 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") |
136 | 156 |
|
137 | 157 | if variables.get("custom_sdkconfig") is not None or len(str(board_sdkconfig)) > 3:
|
138 | 158 | frameworks.append("espidf")
|
|
0 commit comments