Network API
Handles Networking related operations.
network.disable
Signatures
disable()
Description
Disable network connectivity.
Adds a traffic control rule to simulate a network outage. This effectively disconnects the device from the network.
Note: If rate limiting was active before the network was disabled,
the setting will not be restored after the network is re-enabled. You must
call network.enableRateLimit()
again to re-enable rate limiting.
Example
-- Disable network connectivity
network.disable()
network.disableRateLimit
Signatures
disableRateLimit(opts \ [])
Description
Disable network rate limiting.
Removes any active bandwidth restrictions and returns network to full speed.
Options
delay
- Delay in milliseconds before disabling rate limiting (default: 0)
Example
-- Disable rate limiting immediately
network.disableRateLimit()
-- Disable rate limiting after 1 second
network.disableRateLimit({delay = 1000})
network.enable
Signatures
enable()
Description
Enable network connectivity.
Removes applied traffic control rules to restore normal network operation. If network is already enabled, this function has no effect.
Note: If rate limiting was active before the network was disabled,
the setting will not be restored after the network is re-enabled. You must
call network.enableRateLimit()
again to re-enable rate limiting.
Example
-- Enable network connectivity
network.enable()
network.enableRateLimit
Signatures
enableRateLimit(limit_down_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit, opts)
Description
Enable network rate limiting with download speed limit only.
Restricts the download bandwidth to the specified limit. Upload bandwidth remains unlimited.
Note: This function requires network connectivity to be enabled.
If the network is currently disabled (e.g. network.disable()
was called),
you must call network.enable()
first before enabling rate limiting.
Parameters
limit_down_mbit
- Download speed limit in megabits per second
Example
-- Limit download to 10 Mbps
network.enableRateLimit(10)
network.enableRateLimit
Signatures
enableRateLimit(limit_down_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit, opts)
Description
Enable network rate limiting with both download and upload speed limits.
Restricts both download and upload bandwidth to the specified limits.
Note: This function requires network connectivity to be enabled.
If the network is currently disabled (e.g. network.disable()
was called),
you must call network.enable()
first before enabling rate limiting.
Parameters
limit_down_mbit
- Download speed limit in megabits per secondlimit_up_mbit
- Upload speed limit in megabits per second
Example
-- Ensure network is enabled first
network.enable()
-- Then limit download to 10 Mbps and upload to 5 Mbps
network.enableRateLimit(10, 5)
network.enableRateLimit
Signatures
enableRateLimit(limit_down_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit)
enableRateLimit(limit_down_mbit, limit_up_mbit, opts)
Description
Enable network rate limiting with download, upload limits and additional options.
Restricts both download and upload bandwidth with support for delayed activation.
Note: This function requires network connectivity to be enabled.
If the network is currently disabled (e.g. network.disable()
was called),
you must call network.enable()
first before enabling rate limiting.
Parameters
limit_down_mbit
- Download speed limit in megabits per secondlimit_up_mbit
- Upload speed limit in megabits per secondopts
- Options table
Options
delay
- Delay in milliseconds before enabling rate limiting (default: 0)
Example
-- Enable rate limiting after 2 seconds
network.enableRateLimit(10, 5, {delay = 2000})
network.isEnabled
Signatures
isEnabled()
Description
Check if network connectivity is currently enabled.
Returns the current status of network connectivity.
Returns true
if network is enabled, false
if network is disabled.
Example
local is_enabled = network.isNetworkEnabled()
if is_enabled then
print("Network is currently enabled")
else
print("Network is currently disabled")
end
network.isRateLimitActive
Signatures
isRateLimitActive()
Description
Check if network rate limiting is currently active.
Returns the current status of network rate limiting.
Returns true
if rate limiting is enabled, false
otherwise.
Example
local is_limited = network.isRateLimitActive()
if is_limited then
print("Network rate limiting is currently active")
else
print("Network is running at full speed")
end
network.request
Signatures
request(url, opts \ [])
Description
Makes an HTTP request and returns the response.
Options
- method: HTTP method (e.g., "GET", "POST", "PUT", "DELETE")
- headers: A table of HTTP headers
- body: The request body (for POST, PUT, etc.). Maximum size is 10 MB.
- auth: Authentication method and credentials
- params: Query parameters
- timeout: Request timeout in milliseconds
Returns a table with:
- status: HTTP status code
- body: Response body (decoded)
- error: Error message (if any)
Example
local response = network.request("https://api.example.com/data", {
method = "GET",
headers = {["Content-Type"] = "application/json"},
auth = {type = "bearer", token = "my-token"},
params = {limit = 10, offset = 0}
})
Only supports json at the moment
network.stats
Signatures
stats()
Description
Get network interface statistics.
Returns detailed network statistics including bytes transferred, packets, errors, and other network metrics.
Returns a table containing network statistics with the following fields:
rx_bytes
- Bytes receivedtx_bytes
- Bytes transmittedrx_packets
- Packets receivedtx_packets
- Packets transmittedrx_errors
- Receive errorstx_errors
- Transmit errorsrx_dropped
- Dropped received packetstx_dropped
- Dropped transmitted packetsmulticast
- Multicast packetscollisions
- Network collisions
Example
local stats = network.stats()
for i, stat_table in ipairs(stats) do
for j, stat in ipairs(stat_table) do
local name, value = stat[1], stat[2]
print(name .. ": " .. value)
end
end