Wifi

**Wifi** is a module in *Retro Gadgets*. It allows a gadget to communicate over the web.

## Properties

read only
**AccessDenied** boolean
Will return true if network access is denied. See Permissions for more information.

## Methods

**WebGet**( url string ) number
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.

**ClearCookieCache**( )
Clear stored cookies.

**ClearUrlCookieCache**( url string )
Only cookies that apply to this url will be removed from the cache.

**DrawSprite**( position vec2, spriteSheet SpriteSheet, spriteX number, spriteY number, tintColor color, backgroundColor color ) number
Draws a specific sprite frame from the spriteSheet.

* Position is the on-screen sprite desired position starting from the top left corner,
* spriteSheet is the SpriteSheet asset containing the sprite frame to draw,
* spriteX and spriteY are the coordinates to identify the desired sprite frame starting from the, top left corner, expressed in grid units.
	+ spriteX=0 and spriteY=0 are the coordinates of the first sprite, top left.
* tintColor is the color multiplier used to draw the sprite frame. Color(255,255,255) or color.white will leave the sprite frame unaffected.
* backgroundColor is the color used to replace the transparent areas of the spriteFrame. Using ColorRGBA(0,0,0,0) or color.clear will leave the transparency as it is.

**DrawCustomSprite**( position vec2, spriteSheet SpriteSheet, spriteOffset vec2, spriteSize vec2, tintColor color, backgroundColor color ) number
Draw a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid.

**DrawText**( fontSprite vec2, spriteSheet SpriteSheet, text string, tintColor color, backgroundColor color ) number
Draw a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid.

**RasterSprite**( position1 vec2, position2 vec2, position3 vec2, position4 vec2, spriteSheet SpriteSheet, spriteX number, spriteY number, tintColor color, backgroundColor color ) number
Draws a specific sprite frame from the spriteSheet mapping it on a quad identified by position1, position2, position3, position4

**DrawCustomSprite**( position1 vec2, position2 vec2, position3 vec2, position4 vec2, spriteSheet SpriteSheet, spriteOffset vec2, spriteSize vec2, tintColor color, backgroundColor color ) number
Draws a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid mapping it on a quad identified by position1, position2, position3, position4.

## Events

**WifiWebResponseEvent** : { RequestHandle number, ResponseCode number, IsError boolean, ErrorType string, ErrorMessage string, ContentType string, Text 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 and ErrorMessage elaborate on the error encountered by the request.
* ContentType is the MIME type of the content the server returned.
* Text is the 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, it's necessary 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 the 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, the WiFi module must be set on the CPU's event channel 1, and network permissions must be enabled for the gadget.