ACTUALIZED LIBRARY 0 Open (Default) 1 WEP-128 2 WPA1 3 Mixed WPA1 & WPA2-PSK 4 WPA2-PSK 5 Not Used 6 Adhoc, Join any Adhoc network

Dependents:   mbed_Arduino_sensor

Fork of WiflyInterface by Samuel Mokrani

WiflyInterface.cpp

Committer:
sherckuith
Date:
2012-08-24
Revision:
11:002225507f44
Parent:
7:a92dbed32890

File content as of revision 11:002225507f44:

#include "WiflyInterface.h"

WiflyInterface::WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec) : 
    Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec) {ip_set = false;}
    
int WiflyInterface::init() {
    dhcp = true;
    reset();
    return 0;
}

int WiflyInterface::init(const char* ip, const char* mask, const char* gateway) {
    dhcp = false;
    this->ip = ip;
    strcpy(ip_string, ip);
    ip_set = true;
    this->netmask = mask;
    this->gateway = gateway;
    
    reset();
    return 0;
}

int WiflyInterface::connect() {
    return join();
}

int WiflyInterface::disconnect() {
    return leave();
}

char * WiflyInterface::getIPAddress() {
    char * match = 0;
    if (!ip_set) {
        if (!sendCommand("get ip a\r", NULL, ip_string))
            return NULL;
        exit();
        match = strstr(ip_string, "<");
        if (match != NULL) {
            *match = '\0';
        }
        if (strlen(ip_string) < 6) {
            match = strstr(ip_string, ">");
            if (match != NULL) {
                int len = strlen(match + 1);
                memcpy(ip_string, match + 1, len);
            }
        }
        ip_set = true;
    }
    return ip_string;
}