wifly/socket interface for wifly modules

Dependents:   WiFi neurGAI_WIFI thingspeak thingspeak2

Committer:
samux
Date:
Thu Aug 23 12:59:19 2012 +0000
Revision:
7:a92dbed32890
Parent:
4:74bfdd00362a
Child:
11:b912f91e3212
add security enum

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:6ffb0aeb3972 1 #include "WiflyInterface.h"
samux 0:6ffb0aeb3972 2
samux 7:a92dbed32890 3 WiflyInterface::WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec) :
samux 7:a92dbed32890 4 Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec) {ip_set = false;}
samux 0:6ffb0aeb3972 5
samux 0:6ffb0aeb3972 6 int WiflyInterface::init() {
samux 0:6ffb0aeb3972 7 dhcp = true;
samux 0:6ffb0aeb3972 8 reset();
samux 0:6ffb0aeb3972 9 return 0;
samux 0:6ffb0aeb3972 10 }
samux 0:6ffb0aeb3972 11
samux 0:6ffb0aeb3972 12 int WiflyInterface::init(const char* ip, const char* mask, const char* gateway) {
samux 0:6ffb0aeb3972 13 dhcp = false;
samux 0:6ffb0aeb3972 14 this->ip = ip;
samux 0:6ffb0aeb3972 15 strcpy(ip_string, ip);
samux 0:6ffb0aeb3972 16 ip_set = true;
samux 0:6ffb0aeb3972 17 this->netmask = mask;
samux 0:6ffb0aeb3972 18 this->gateway = gateway;
samux 0:6ffb0aeb3972 19
samux 0:6ffb0aeb3972 20 reset();
samux 0:6ffb0aeb3972 21 return 0;
samux 0:6ffb0aeb3972 22 }
samux 0:6ffb0aeb3972 23
samux 0:6ffb0aeb3972 24 int WiflyInterface::connect() {
samux 0:6ffb0aeb3972 25 return join();
samux 0:6ffb0aeb3972 26 }
samux 0:6ffb0aeb3972 27
samux 0:6ffb0aeb3972 28 int WiflyInterface::disconnect() {
samux 0:6ffb0aeb3972 29 return leave();
samux 0:6ffb0aeb3972 30 }
samux 0:6ffb0aeb3972 31
samux 0:6ffb0aeb3972 32 char * WiflyInterface::getIPAddress() {
samux 0:6ffb0aeb3972 33 char * match = 0;
samux 0:6ffb0aeb3972 34 if (!ip_set) {
samux 4:74bfdd00362a 35 if (!sendCommand("get ip a\r", NULL, ip_string))
samux 4:74bfdd00362a 36 return NULL;
samux 0:6ffb0aeb3972 37 exit();
samux 0:6ffb0aeb3972 38 match = strstr(ip_string, "<");
samux 0:6ffb0aeb3972 39 if (match != NULL) {
samux 0:6ffb0aeb3972 40 *match = '\0';
samux 0:6ffb0aeb3972 41 }
samux 0:6ffb0aeb3972 42 if (strlen(ip_string) < 6) {
samux 0:6ffb0aeb3972 43 match = strstr(ip_string, ">");
samux 0:6ffb0aeb3972 44 if (match != NULL) {
samux 0:6ffb0aeb3972 45 int len = strlen(match + 1);
samux 0:6ffb0aeb3972 46 memcpy(ip_string, match + 1, len);
samux 0:6ffb0aeb3972 47 }
samux 0:6ffb0aeb3972 48 }
samux 0:6ffb0aeb3972 49 ip_set = true;
samux 0:6ffb0aeb3972 50 }
samux 0:6ffb0aeb3972 51 return ip_string;
samux 0:6ffb0aeb3972 52 }