Wifi
Properties
AccessDenied boolean read only
Will return
trueif network access is denied. See Permissions for more information.
AudioStreams {AudioSample} read only
Table containing the active audio streams. The key of the table is the connection handle.
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
WebGetAudioStream( url string ) number
Opens a web audio stream, return a numeric identifier 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
urlwill be removed from the cache
Events
WifiWebResponseEvent : { Url string, RequestHandle number, ResponseCode number, IsError boolean, ErrorType string, ErrorMessage string, ContentType string, Text string, Data string, AudioSample AudioSample, PixelData PixelData, Type string }
Sent when a web request is completed by the remote server.
*Urlthe url of the request
*RequestHandleis the handle of the request, which matches the number returned by the function that initiated it.
*ResponseCodeis the HTTP code returned by the server.
*IsErroris a boolean value which indicates if the response wasn't successful.
*ErrorTypeandErrorMessageelaborate on the error encountered by the request.
*ContentTypeis the MIME type of the content the server returned.
*Textis the UTF8 encoded content of the response.
*Datais the binary content of the response.
*AudioSampleis the streaming AudioSample (only when usingWebGetAudioStream(url)).
*PixelDataif the response contains an image, this field contains the decoded data.
*Typeis"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.