Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Smart-WiFly-WebServer PUB_WiflyInterface_Demo
Fork of WiflyInterface by
EthernetInterface Class Reference
Interface using Wifly to connect to an IP-based network. More...
#include <EthernetInterface.h>
Inherits Wifly.
Public Member Functions | |
| EthernetInterface (PinName tx, PinName rx, PinName reset, PinName tcp_status, const char *ssid=NULL, const char *phrase=NULL, Security sec=NONE) | |
| Construct the WiFlyInterface. | |
| int | init () |
| Initialize the interface with DHCP. | |
| int | init (const char *ip, const char *mask, const char *gateway) |
| Initialize the interface with a static IP address. | |
| void | setSecurity (const char *ssid=NULL, const char *phrase=NULL, Security sec=NONE) |
| Set security parameters for the interface. | |
| int | connect () |
| Connect Bring the interface up, start DHCP if needed. | |
| int | disconnect () |
| Disconnect Bring the interface down. | |
| char * | getMACAddress () |
| Get the MAC address of your Ethernet interface. | |
| char * | getIPAddress () |
| Get IP address. | |
| const char * | getName (void) |
| getName | |
| int | get_connection_speed (void) |
| get the speed of the connection. | |
| void | SetSecurity (const char *ssid, const char *phrase, Security sec) |
| Optional means to set/reset the security. | |
| bool | configure () |
| Configure the wifi module with the parameters contained in the constructor. | |
| bool | join () |
| Connect the wifi module to the ssid contained in the constructor. | |
| bool | connect (const char *host, int port) |
| Open a tcp connection with the specified host on the specified port. | |
| bool | setProtocol (Protocol p) |
| Set the protocol (UDP or TCP) | |
| void | reset () |
| Reset the wifi module. | |
| bool | reboot () |
| Reboot the wifi module. | |
| int | readable () |
| Check if characters are available. | |
| int | writeable () |
| Check if characters are available. | |
| bool | is_connected () |
| Check if associated with an access point (was checking if tcp link is active) | |
| char | getc () |
| Read a character. | |
| void | flush () |
| Flush the buffer. | |
| int | putc (char c) |
| Write a character. | |
| bool | cmdMode () |
| To enter in command mode (we can configure the module) | |
| bool | exit () |
| To exit the command mode. | |
| bool | close () |
| Close a tcp connection, and exit command mode. | |
| int | send (const char *str, int len, const char *ACK=NULL, char *res=NULL, int timeout=DEFAULT_WAIT_RESP_TIMEOUT) |
| Send a string to the wifi module by serial port. | |
| bool | sendCommand (const char *cmd, const char *ack=NULL, char *res=NULL, int timeout=DEFAULT_WAIT_RESP_TIMEOUT) |
| Put the device in command mode. | |
| bool | isDHCP () |
| Return true if the module is using dhcp. | |
| bool | gethostbyname (const char *host, char *ip) |
| gets the host ip address | |
| bool | baud (int baudrate) |
| Set the baud rate between the ARM and the WiFly. | |
| void | setConnectionState (bool state) |
| Sets the connection state. | |
| char * | getWiflyVersionString () |
| Get the version information from the Wifly module. | |
| float | getWiflyVersion () |
| Get the software version from the Wifly module. | |
| bool | SWUpdateWifly (const char *file) |
| Update the software in the Wifly module. | |
| bool | isCmdMode () |
| determine if the module is in command mode | |
Protected Member Functions | |
| bool | FixPhrase (char *dst, size_t dstLen, const char *src) |
| Allocate space for the parameter (ssid or passphrase) and then fix it (change ' ' to '$'). | |
| void | GatherLogonInfo () |
| Gather the Wifly module version information for later queries. | |
Detailed Description
Interface using Wifly to connect to an IP-based network.
Definition at line 36 of file EthernetInterface.h.
Constructor & Destructor Documentation
| EthernetInterface | ( | PinName | tx, |
| PinName | rx, | ||
| PinName | reset, | ||
| PinName | tcp_status, | ||
| const char * | ssid = NULL, |
||
| const char * | phrase = NULL, |
||
| Security | sec = NONE |
||
| ) |
Construct the WiFlyInterface.
API Precedence:
* EthernetInterface() -->
* +------------------+ +---------------------------+
* v ^ v ^
* -> init() -+----------------->+-> connect() -+-------------------------->+-> disconnect() --|
* | ^ +-> getName() --------------+
* +-> setName() -----+ +-> getIPAddress() ---------+
* | | +-> getMACAddress() --------+
* +-> setSecurity() -+ +-> Wifly APIs -------------+
* +-> get_connection_speed() -+
* - Note:
- The optional ssid, phrase, and sec parameters may be deferred, or overridden prior to the connect().
- Parameters:
-
tx mbed pin to use for tx line of Serial interface rx mbed pin to use for rx line of Serial interface reset reset pin of the wifi module () tcp_status connection status pin of the wifi module (GPIO 6) ssid optional parameter which is the ssid of the network phrase optional parameter which is the WEP or WPA key/phrase sec optional security type (NONE[default], WEP_128 or WPA)
Definition at line 24 of file EthernetInterface.cpp.
Member Function Documentation
| bool baud | ( | int | baudrate ) | [inherited] |
Set the baud rate between the ARM and the WiFly.
This will set the WiFly module baud rate first and then set the ARM interface to match it. If it cannot get the proper acknowledge response, it will go on a hunt through the range of standard baud rates.
- Note:
- Baud rate must be one of 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, or 921600. (See Wifly manual 2.3.64)
- Baud rate of 230400 has been seen to be marginal w/o flow control.
- Setting a baud rate to a 460800 or above may be unrecoverable without resetting the Wifly module.
- Parameters:
-
baudrate is the desired baudrate.
- Returns:
- true if it succeeded, which means that communications can continue,
- false if it failed to establish a communication link.
| bool close | ( | ) | [inherited] |
| bool cmdMode | ( | ) | [inherited] |
| bool configure | ( | ) | [inherited] |
| int connect | ( | ) |
Connect Bring the interface up, start DHCP if needed.
- Returns:
- 0 on success, a negative number on failure
Definition at line 60 of file EthernetInterface.cpp.
| bool connect | ( | const char * | host, |
| int | port | ||
| ) | [inherited] |
| int disconnect | ( | ) |
Disconnect Bring the interface down.
- Returns:
- 0 on success, a negative number on failure
Reimplemented from Wifly.
Definition at line 65 of file EthernetInterface.cpp.
| bool exit | ( | ) | [inherited] |
| bool FixPhrase | ( | char * | dst, |
| size_t | dstLen, | ||
| const char * | src | ||
| ) | [protected, inherited] |
Allocate space for the parameter (ssid or passphrase) and then fix it (change ' ' to '$').
- Parameters:
-
dst is a reference to the private member pointer. dstLen is the size of the destination buffer src is a pointer to a passed in string.
- Returns:
- true if the src phrase was placed in the dst buffer.
| void GatherLogonInfo | ( | ) | [protected, inherited] |
| int get_connection_speed | ( | void | ) |
get the speed of the connection.
- Returns:
- the connection speed, which can range from 1 to 54 (Mb/s)
- 0 if the information could not be acquired.
Definition at line 168 of file EthernetInterface.cpp.
| char getc | ( | ) | [inherited] |
| bool gethostbyname | ( | const char * | host, |
| char * | ip | ||
| ) | [inherited] |
| char * getIPAddress | ( | ) |
Get IP address.
- Returns:
- a pointer to a string containing the IP address
Definition at line 108 of file EthernetInterface.cpp.
| char * getMACAddress | ( | ) |
Get the MAC address of your Ethernet interface.
- Returns:
- a pointer to a string containing the MAC address
Definition at line 73 of file EthernetInterface.cpp.
| const char * getName | ( | void | ) |
getName
Get the network name for this device.
- Returns:
- pointer to the name (or null)
Definition at line 163 of file EthernetInterface.cpp.
| float getWiflyVersion | ( | ) | [inherited] |
| char * getWiflyVersionString | ( | ) | [inherited] |
| int init | ( | const char * | ip, |
| const char * | mask, | ||
| const char * | gateway | ||
| ) |
Initialize the interface with a static IP address.
Initialize the interface and configure it with the following static configuration (no connection at this point).
- Parameters:
-
ip the IP address to use mask the IP address mask gateway the gateway to use
- Returns:
- 0 on success, a negative number on failure
Definition at line 42 of file EthernetInterface.cpp.
| int init | ( | ) |
Initialize the interface with DHCP.
Initialize the interface and configure it to use DHCP (no connection at this point).
- Returns:
- 0 on success, a negative number on failure
Definition at line 33 of file EthernetInterface.cpp.
| bool is_connected | ( | void | ) | [inherited] |
Check if associated with an access point (was checking if tcp link is active)
Follow this example to improve the automatic recovery after a lost association.
WiflyInterface eth(p28, p27, p23, p24, "ssid", "pass", WPA); if (0 == eth.init()) { eth.baud(230400); // speed up the interface do { if (0 == eth.connect()) { linkup = true; // led indicator while (eth.is_connected()) { wait_ms(1000); } linkup = false; // led indicator eth.disconnect(); wait_ms(1000); } } while (1); } else { wait(5); // ... failed to initialize, rebooting... mbed_reset(); }
- Returns:
- true if successful
| bool isCmdMode | ( | ) | [inherited] |
| bool isDHCP | ( | ) | [inherited] |
| bool join | ( | ) | [inherited] |
| int putc | ( | char | c ) | [inherited] |
| int readable | ( | ) | [inherited] |
| bool reboot | ( | ) | [inherited] |
| int send | ( | const char * | str, |
| int | len, | ||
| const char * | ACK = NULL, |
||
| char * | res = NULL, |
||
| int | timeout = DEFAULT_WAIT_RESP_TIMEOUT |
||
| ) | [inherited] |
Send a string to the wifi module by serial port.
This function desactivates the user interrupt handler when a character is received to analyze the response from the wifi module.
Useful to send a command to the module and wait a response.
- Parameters:
-
str string to be sent len string length ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknowledged. (default: NULL) res this field will contain the response from the wifi module, result of a command sent. This field is available only if ACK == NULL AND res != NULL (default: NULL) timeout is the time in msec to wait for the acknowledge
- Returns:
- true if ACK has been found in the response from the wifi module.
- false if there is not a correct response in the timeout.
| bool sendCommand | ( | const char * | cmd, |
| const char * | ack = NULL, |
||
| char * | res = NULL, |
||
| int | timeout = DEFAULT_WAIT_RESP_TIMEOUT |
||
| ) | [inherited] |
Put the device in command mode.
- Parameters:
-
str string to be sent ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO") res this field will contain the response from the wifi module, result of a command sent. This field is available only if ACK = "NO" AND res != NULL (default: NULL) timeout is the time in msec to wait for the acknowledge
- Returns:
- true if successful, false if it failed.
| void setConnectionState | ( | bool | state ) | [inherited] |
| bool setProtocol | ( | Protocol | p ) | [inherited] |
| void setSecurity | ( | const char * | ssid = NULL, |
| const char * | phrase = NULL, |
||
| Security | sec = NONE |
||
| ) |
Set security parameters for the interface.
Prior to connect, this interface permits changing the security parameters. This can be most useful when the Wifly module may be used where there are multiple access points to be connected to. With this, the interface can be brought online far enough to scan for available access points.
- Parameters:
-
ssid optional parameter which is the ssid of the network phrase optional parameter which is the WEP or WPA key/phrase sec optional security type (NONE[default], WEP_128 or WPA)
Definition at line 55 of file EthernetInterface.cpp.
| void SetSecurity | ( | const char * | ssid, |
| const char * | phrase, | ||
| Security | sec | ||
| ) | [inherited] |
Optional means to set/reset the security.
If join() has not been called, then you can revise the security parameters from those in the constructor.
- Parameters:
-
ssid ssid of the network phrase WEP or WPA key sec Security type (NONE, WEP_128, WPA1, WPA | WPA_MIXED, WPA2_PSK, WEP_64 )
| bool SWUpdateWifly | ( | const char * | file ) | [inherited] |
Update the software in the Wifly module.
This attempts to connect to the microchip site, download a software update, install it as the primary image, and reboot to activate that image. It is compile-time defined to try for 30 seconds.
- Parameters:
-
file is the name of the file to fetch, to update to. The strlen(file) cannot exceed 60, and is typically like this: "Wifly7-475.mif"
- Returns:
- true if success or false for failure.
Generated on Tue Jul 12 2022 16:14:58 by
1.7.2
