RedFly-Shield for Arduino
Updates: watterott.net/projects/redfly-shield
Further infos: readme.txt
License: license.txt
Arduino Libraries
Arduino Examples
French description and additional functions: Librairie RedFly-Shield, RedFly-Shield
The RedFly uses the hardware serial port (8N2) of the Arduino. If you want to use the serial port for other things then you have to disable the communication with the RedFly (see enable() and disable()).
When sending commands to the RedFly you always have to check, that the input buffer doesn't contain data (see socketRead(), client.read() and server.read()).
Libraries
RedFly
Client (TCP)
Server (TCP)
RedFly
uint8_t init(uint32_t br, uint8_t pwr)
uint8_t init(uint8_t pwr) //br=9600
uint8_t init(void) //br=9600, pwr=HIGH_POWER
Initialize the WiFi module and set baud rate and transmitter power. Returns 0 if everything is okay.
br - Baud rate: 9600, 19200, 38400, 57600, 115200, 200000, 230400, 460800, 921600, 1843200, 3686400 (only baud rates up to 230400 are support by Arduino @16MHz)
pwr - Transmitter power: LOW_POWER, MED_POWER, HIGH_POWER
void enable(void)
Enable communication with the RedFly-Shield.
void disable(void)
Disable communication with the RedFly-Shield.
uint8_t getversion(char ver[])
Get the firmware version. The return value is 0 if the version is successfully copied to ver[].
ver - Pointer to a buffer to receive the version.
uint8_t getmac(uint8_t mac[])
Get the MAC address. The return value is 0 if the MAC is successfully copied to mac[].
mac - Pointer to a buffer to receive the address.
uint8_t getrssi(void)
Returns the signal strengh (in dBm) of the current connection.
uint8_t getip(char domain[], uint8_t ip[])
Returns 0 if the ip address of the domain is succefully received. (FW >= 4.3.0 required)
domain - Domain name
ip - IP address
uint8_t scan(void)
uint8_t scan(char ssid[], uint8_t *mode, uint8_t *rssi)
Scan for wireless networks and return SSID, Mode and RSSI. If the scanning was successful the return vaule is 0.
ssid - SSID (if set on function call, the module scans for networks with hidden SSID)
mode - Mode: 0=Open, 1=WPA, 2=WPA2, 3=WEP
rssi - RSSI (signal strengh)
uint8_t nextscan(char ssid[], uint8_t *mode, uint8_t *rssi)
Scan for next wireless networks and return SSID, Mode and RSSI. If the scanning was successful the return vaule is 0.
ssid - SSID
mode - Mode
rssi - RSSI
uint8_t join(char ssid[], char key[], uint8_t net, uint8_t chn, uint8_t authmode) //infrastructure or IBSS joiner / creator
uint8_t join(char ssid[], char key[], uint8_t net, uint8_t chn) //IBSS creator
uint8_t join(char ssid[], char key[], uint8_t net) //infrastructure or IBSS joiner
uint8_t join(char ssid[], uint8_t net, uint8_t chn) //IBSS creator
uint8_t join(char ssid[], uint8_t net) //infrastructure or IBSS joiner
uint8_t join(char ssid[], char key[]) //infrastructure
uint8_t join(char ssid[]) //infrastructure
Join wireless network. If everything is okay the return value is 0.
scan() has to be called before this function for infrastructure and IBSS joiner networks.
ssid - SSID
key - Key / Password
net - Network: INFRASTRUCTURE, IBSS_JOINER, IBSS_CREATOR
chn - Channel: 0...14, 0=all channels
authmode - Auth mode: 0=Open, 1=Shared Key
uint8_t disconnect(void)
Disconnect / disassociate wireless connection.
uint8_t begin(uint8_t ip[], uint8_t gateway[], uint8_t netmask[], uint8_t dns[])
uint8_t begin(uint8_t ip[], uint8_t gateway[], uint8_t netmask[])
uint8_t begin(uint8_t ip[], uint8_t gateway[]) //netmask=255.255.255.0
uint8_t begin(uint8_t ip[]) //netmask=255.255.255.0
uint8_t begin(void) //Use DHCP to get IP config.
Set IP configuration.
ip - IP address
gateway - Gateway address
netmask - Network mask
dns - DNS server (FW >= 4.3.0 required)
uint8_t socketConnect(uint8_t proto, uint8_t ip[], uint16_t port, uint16_t lport)
uint8_t socketConnect(uint8_t proto, uint8_t ip[], uint16_t port) //lport=1024
Connect to server. Returns the socket handle or 0xFF on an error.
proto - Protocol: PROTO_TCP, PROTO_UDP
ip - Server IP address
port - Server port
lport - Local port
uint8_t socketListen(uint8_t proto, uint16_t lport)
Listen on port. Returns the socket handle or 0xFF on an error.
proto - Protocol: PROTO_TCP, PROTO_UDP
lport - Local port
uint8_t socketClose(uint8_t socket)
Close socket.
socket - Socket handle
uint8_t socketClosed(uint8_t socket)
Is the socket closed? A return value >0 means that the socket is closed.
socket - Socket handle
uint8_t socketStatus(uint8_t socket)
Get socket status (0xFF=error).
socket - Socket handle
uint8_t socketSend(uint8_t socket, uint8_t stream[], uint16_t size, uint8_t ip[], uint16_t port)
uint8_t socketSendPGM(uint8_t socket, PGM_P stream, uint8_t ip[], uint16_t port)
uint8_t socketSend(uint8_t socket, char stream[], uint8_t ip[], uint16_t port)
uint8_t socketSend(uint8_t socket, uint8_t stream[], uint16_t size)
uint8_t socketSendPGM(uint8_t socket, PGM_P stream)
uint8_t socketSend(uint8_t socket, char stream[])
uint8_t socketSend(uint8_t socket, int value)
Send data on socket. ip and port only used on UDP connections.
Note: The input buffer has to be empty before sending data (see socketRead()).
socket - Socket handle
stream - Data
size - Data length
value - Data (int)
ip - Server IP address (only on UDP)
port - Server port (only on UDP)
uint16_t socketRead(uint8_t *socket, uint16_t *len, uint8_t ip[], uint16_t *port, uint8_t dst[], uint16_t dst_size) //UDP connection
uint16_t socketRead(uint8_t *socket, uint16_t *len, uint8_t dst[], uint16_t dst_size)
Read data. Returns data length in dst (0xFFFF=socket closed).
socket - Socket handle (set from function or if set on function call, only return data from this socket)
len - Complete data length
ip - Server IP address (only UDP)
port - Server port (only UDP)
dst - Receive buffer
dst_size - Receive buffer length
Example:
uint8_t socket=0xFF; //0xFF = return data from all sockets, otherwise return only data from specialized socket
uint16_t len; //complete data length, that is available
uint8_t ip[4]; //source IP, only on UDP connection
uint16_t port //source port, only on UDP connection
uint8_t dst[64]; //destination buffer for the data
uint16_t d_size=64; //size of destination buffer
uint16_t received_len; //data copied to destination buffer
received_len = socketRead(&socket, &len, ip, &port, dst, d_size); //ip and port only on UDP connections
received_len = socketRead(&socket, &len, dst, d_size);
Error codes
255 (-1) Waiting for the connection from peer.
254 (-2) Socket not available.
253 (-3) Deauthentication from the Access Point.
252 (-4) Illegal IP/Port parameters.
251 (-5) TCP/IP configuration failure.
250 (-6) Invalid socket.
249 (-7) Association not done.
248 (-8) Error in cmd.
247 (-9) Error with byte stuffing for escape characters.
246 (-10) IP Lease expired.
245 (-11) TCP connection closed.
244 (-12) Pre-Shared Key not set for connection to a secure Access Point.
243 (-13) No Access Points scanned
242 (-14) INIT cmd already issued. This error is sent when the INIT cmd is sent more than once.
241 (-15) JOIN cmd already issued. This error is sent when the JOIN cmd is sent more than once.
240 (-16) DHCP Failure.
239 (-17) Baud Rate not supported.
Client
uint8_t begin(void)
uint8_t begin(uint8_t *ip, uint16_t port)
uint8_t connect(void)
uint8_t connect(uint8_t *ip, uint16_t port)
Start the TCP-Client. Returns 1 if everything is okay.
ip - Client ip to connect
port - Client port to connect
uint8_t connected(void)
Is the Client connected? The return value is 1 if yes.
void stop(void)
Stop the Client.
uint8_t status(void)
Returns the Client status. 0 means an open connection.
The status will be directly read from the WiFi module.
uint8_t getSocket(void)
Returns the socket handle for the connection.
int available(void)
Returns the size of available data.
int read(void)
Get the received data. On -1 an error occurred.
size_t read(uint8_t *s, size_t size)
Returns the received data len.
s - Destination buffer
s - Buffer size
void flush(void)
Flushes the receive buffer.
void write(uint8_t b)
void write(const char *s)
void write(const uint8_t *s, size_t size)
Write data to the connected device.
Note: The input buffer has to be empty before sending data (see read()).
b - Byte to write
s - String or Array to write
void print(text)
void print(int, base)
void println(text)
void println(int, base)
Print text from RAM.
text, int - String, Char, Integer, Long, Float (RAM)
base - DEC, HEX, OCT, BIN
void print_P(PGM_P s)
void println_P(PGM_P s)
Print text from Flash.
s - Pointer to string (Flash), example: PSTR("test"), further infos about using flash memory: Link
Server
uint8_t begin(void)
uint8_t connect(void)
Start the TCP-Server. Returns 1 if everything is okay.
uint8_t connected(void)
Is the Server port open? The return value is 1 if yes.
void stop(void)
Stop the Server.
uint8_t status(void)
Returns the Server status. 0 means an open connection.
The status will be directly read from the WiFi module.
uint8_t getSocket(void)
Returns the socket handle for the connection.
int available(void)
Returns the size of available data.
int read(void)
Get the received data. On -1 an error occurred.
size_t read(uint8_t *s, size_t size)
Returns the received data len.
s - Destination buffer
s - Buffer size
void flush(void)
Flushes the receive buffer.
void write(uint8_t b)
void write(const char *s)
void write(const uint8_t *s, size_t size)
Write data to the connected device.
Note: The input buffer has to be empty before sending data (see read()).
b - Byte to write
s - String or Array to write
void print(text)
void print(int, base)
void println(text)
void println(int, base)
Print text from RAM.
text, int - String, Char, Integer, Long, Float (RAM)
base - DEC, HEX, OCT, BIN
void print_P(PGM_P s)
void println_P(PGM_P s)
Print text from Flash.
s - Pointer to string (Flash), example: PSTR("test"), further infos about using flash memory: Link
Examples
Client/Server API
Paint
TwitterRSSReader
WebClient
WebServer
Socket API
EchoTest_Socket
TwitterTest_Socket
TwitterWriter_Socket
WebClient_Socket
WebServer_Socket
Other
WLANScan