Wifi
Properties
AccessDenied boolean read only
Will return
true
if network access is denied. See Permissions for more information.
Methods
Send a web HTTP GET request, return a numeric handle to identify the request
WebPutData( url string, data string ) number
Send a web HTTP PUT request, return a numeric handle to identify the request
WebPostData( url string, data string ) number
Send a web HTTP POST request, return a numeric handle to identify the request
WebPostForm( url string, form table ) number
Send a web HTTP POST request, return a numeric handle to identify the request
WebCustomRequest( url string, method string, customHeaderFields table, contentType string, contentData string ) number
Send a web request, return a numeric handle to identify the request
WebAbort( handle number ) boolean
Abort a web request
GetWebUploadProgress( handle number ) number
Returns a percentage (0-100) representing the progress of the current upload associated with the given handle
GetWebDownloadProgress( handle number ) number
Returns a percentage (0-100) representing the progress of the current download associated with the given handle
Clear stored cookies
ClearUrlCookieCache( url string )
Only cookies that apply to this
url
will be removed from the cache
Events
WifiWebResponseEvent : { RequestHandle number, ResponseCode number, IsError boolean, ErrorType string, ErrorMessage string, ContentType string, Text string, Data string, Type string }
Sent when a web request is completed by the remote server.
*RequestHandle
is the handle of the request, which matches the number returned by the function that initiated it.
*ResponseCode
is the HTTP code returned by the server.
*IsError
is a boolean value which indicates if the response wasn't successful.
*ErrorType
andErrorMessage
elaborate on the error encountered by the request.
*ContentType
is the MIME type of the content the server returned.
*Text
is the UTF8 encoded content of the response.
*Data
is the binary content of the response.
*Type
is"WifiWebResponseEvent"
.
Examples
When making a web request to a URL, the request function will give you only a handle to keep track of said request. To get the actual response from the server, since it's an asynchronous process, we need to use an event. Here is an example which uses World Time API to get information about the current time in the London timezone:
gdt.Wifi0:WebGet("http://worldtimeapi.org/api/timezone/Europe/London.txt")
function eventChannel1(sender, response)
if response.IsError == false then
log(response.Text)
end
end
The call to WebGet
, outside of the update
function, will run only once when the gadget is powered on. Then, once the server is done replying to us, the eventChannel1
function will trigger. If our response is not an error code, the text content of the response will be shown in the Multitool debug screen.
Note: In order for this example to work, your WiFi module must be set on your CPU's event channel 1, and you must enable network permissions for your gadget.