mbed official WiflyInterface (interface for Roving Networks Wifly modules)
Dependents: Wifly_HelloWorld Websocket_Wifly_HelloWorld RPC_Wifly_HelloWorld HTTPClient_Wifly_HelloWorld ... more
WiflyInterface.cpp
00001 #include "WiflyInterface.h" 00002 00003 WiflyInterface::WiflyInterface( PinName tx, PinName rx, PinName reset, PinName tcp_status, 00004 const char * ssid, const char * phrase, Security sec) : 00005 Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec) 00006 { 00007 ip_set = false; 00008 } 00009 00010 int WiflyInterface::init() 00011 { 00012 state.dhcp = true; 00013 reset(); 00014 return 0; 00015 } 00016 00017 int WiflyInterface::init(const char* ip, const char* mask, const char* gateway) 00018 { 00019 state.dhcp = false; 00020 this->ip = ip; 00021 strcpy(ip_string, ip); 00022 ip_set = true; 00023 this->netmask = mask; 00024 this->gateway = gateway; 00025 reset(); 00026 00027 return 0; 00028 } 00029 00030 int WiflyInterface::connect() 00031 { 00032 return join(); 00033 } 00034 00035 int WiflyInterface::disconnect() 00036 { 00037 return Wifly::disconnect(); 00038 } 00039 00040 char * WiflyInterface::getIPAddress() 00041 { 00042 char * match = 0; 00043 if (!ip_set) { 00044 if (!sendCommand("get ip a\r", NULL, ip_string)) 00045 return NULL; 00046 exit(); 00047 flush(); 00048 match = strstr(ip_string, "<"); 00049 if (match != NULL) { 00050 *match = '\0'; 00051 } 00052 if (strlen(ip_string) < 6) { 00053 match = strstr(ip_string, ">"); 00054 if (match != NULL) { 00055 int len = strlen(match + 1); 00056 memcpy(ip_string, match + 1, len); 00057 } 00058 } 00059 ip_set = true; 00060 } 00061 return ip_string; 00062 }
Generated on Tue Jul 12 2022 18:24:22 by 1.7.2