Connectivity & Networking
Network & HTTP Client
Wi-Fi diagnostics, REST requests, and streaming HTTP client APIs.
8. Global Object: Network (REST, Streaming & Diagnostics)
The Network global object provides high-speed, secure HTTP/HTTPS REST communication, streaming downloads, and network diagnostics.
8.1 Network Diagnostics
Network.isConnected(): Returnstrueif connected to WiFi.Network.hasInternet(): Returnstrueif public internet (WAN) is verified via non-blocking captive portal check.Network.getIP(): Returns the local IP address string (e.g."192.168.1.104").Network.getSSID(): Returns the currently connected WiFi SSID name.Network.getRSSI(): Returns signal strength in dBm (e.g.-58).Network.showWiFiPrompt(): Explicitly displays the KryonOS "WiFi Not Connected" alert dialog.
8.2 HTTP / HTTPS REST Requests
All REST calls support TLS/HTTPS automatically (setInsecure() enabled) and yield to the FreeRTOS Task Watchdog Timer (TWDT) to prevent freezes.
Network.get(url, [headers], [timeoutMs = 8000], [showDialog = false])
- Returns:
{ status: Number, body: String, error: String } - Example:
var res = Network.get("https://api.weather.com/v1/forecast", { "Authorization": "Bearer xxx" }, 8000); if (res.status === 200) { var data = JSON.parse(res.body); System.print("Temp: " + data.temp); }
Network.post(url, body, [contentType = "application/json"], [headers], [timeoutMs = 8000], [showDialog = false])
- Returns:
{ status: Number, body: String, error: String }
Network.put(url, body, [contentType = "application/json"], [headers], [timeoutMs = 8000], [showDialog = false])
- Returns:
{ status: Number, body: String, error: String }
Network.delete(url, [headers], [timeoutMs = 8000], [showDialog = false])
- Returns:
{ status: Number, body: String, error: String }
Network.request(options)
- Parameters:
{ method: "GET"|"POST"|"PUT"|"DELETE", url: String, body: String, headers: Object, timeout: Number, showDialog: Boolean } - Returns:
{ status: Number, body: String, error: String }
8.3 Streaming File Downloads
Network.downloadFile(url, destPath, [onProgressCallback], [timeoutMs = 15000], [showDialog = false])
- Returns:
Boolean(trueon success) - Description: Streams chunks in 1024-byte buffers directly from network to flash storage (
/local/...) or SD Card (/sd/...) without RAM bloat. - Example:
Network.downloadFile("https://example.com/asset.bin", "/sd/asset.bin", function(bytesRead, totalBytes) { var percent = totalBytes > 0 ? Math.floor((bytesRead / totalBytes) * 100) : 0; System.print("Download progress: " + percent + "%"); });