Wi-Fi extensions

This pages lists the extensions available in the version of uLisp for the ESP8266, ESP32, and Raspberry Pi Pico W. For examples of their use see Wi-Fi examples.

Summary

Status functions

available, connected, wifi-localip

Wi-Fi functions

wifi-connect, wifi-server, wifi-softap, with-client

 


available function

Syntax: (available stream)

Returns the number of bytes available for reading from the stream, or zero if no bytes are available.

connected function

Syntax: (connected stream)

Returns t or nil to indicate if the client on stream is still connected.

wifi-connect function

Syntax: (wifi-connect [ssid password])

Connects to the Wi-Fi network ssid using password password. It returns the IP address as a string. It may take a few seconds to connect. For example:

> (wifi-connect "Geronimo" "topsecret")
"10.0.1.28"

With no parameters wifi-connect disables the network connection.

Note that the ESP8266 stores the last used access point in EEPROM, so if it loses the connection for some reason it will reconnect to the last used access point once it is back online and you do not need to give a wifi-connect command again.

wifi-localip function

Syntax: (wifi-localip)

Returns the IP address of the local network as a string.

wifi-server function

Syntax: (wifi-server)

Starts a server running. It returns nil.

wifi-softap function

Syntax: (wifi-softap ssid [password channel hidden])

Set up a soft access point to establish a Wi-Fi network. Returns the IP address as a string or nil if unsuccessful. For example:

> (wifi-softap "Buckyball")
"192.168.4.1"

With one parameter ssid it sets up an open Wi-Fi network. One or more of the remaining parameters can be specified:

  • Specify password to protect the network with a password.
  • The channel is an optional channel, default 1.
  • If hidden is set to non-nil the access point will be hidden (not supported on Raspberry Pi Pico).

With no parameters wifi-softap disables the currently-active soft access point (not supported on Raspberry Pi Pico).

with-client special form

Syntax: (with-client (stream [address port]) form*)

The with-client form evaluates the forms with stream bound to a wifi-stream.

If address and port are specified, with-client allows you to communicate with the IP address defined by address and port. The address can be an integer representing a 32-bit IP address, a string representing an IP address, or a string representing a domain name.

If with-client is called with just the stream parameter it allows you to communicate with a client connected to a server started with wifi-server. If there are no active clients with-client returns nil immediately without evaluating the forms. 

In each case you can then use the standard uLisp I/O functions to write to or read from the stream. See Wi-Fi examples for examples of using with-client.