26 #define SET_IP_ADDRESS "set ip address %s\r\n"
27 #define SET_IP_BACKUP "set ip backup %s\r\n"
28 #define SET_IP_DHCP "set ip dhcp %d\r\n"
29 #define SET_IP_FLAGS "set ip flags %x\r\n"
30 #define SET_IP_GATEWAY "set ip gateway %s\r\n"
31 #define SET_IP_HOST "set ip host %s\r\n"
32 #define SET_IP_LOCAL_PORT "set ip localport %d\r\n"
33 #define SET_IP_NET "set ip net %s\r\n"
34 #define SET_IP_NETMASK "set ip netmask %s\r\n"
35 #define SET_IP_PROTO "set ip proto %d\r\n"
36 #define SET_IP_REMOTE "set ip remote %d\r\n"
37 #define SET_IP_TCP_MODE "set ip tcp-mode %x\r\n"
39 #define SET_COM_REM "set com remote %s\r\n"
40 #define SET_OP_FORMAT "set option format %d\r\n"
41 #define SET_UART_MD "set uart mode %x \r\n"
42 #define SET_UART_BAUD "set uart baud %d \r\n"
43 #define SET_UART_INST "set uart instant %d \r\n"
45 #define SET_WLAN_TX "set wlan tx %d \r\n"
47 #define SET_WLAN_AUTH "set wlan auth %d\r\n"
48 #define SET_WLAN_KEY "set wlan key %d\r\n"
49 #define SET_WLAN_PHRASE "set wlan phrase %s\r\n"
50 #define SET_WLAN_SSID "set wlan ssid %s\r\n"
51 #define SET_WLAN_JOIN "set wlan join %d\r\n"
52 #define SET_WLAN_CHAN "set wlan chan %d\r\n"
53 #define SET_DNS_NAME "set dns name %s\r\n"
57 #define GET_ADHOC "get adhoc\r\n"
58 #define GET_MAC "get mac\r\n"
59 #define GET_IP "get ip a\r\n"
60 #define GET_WLAN "get wlan\r\n"
61 #define GET_VER "ver\r\n"
64 #define SHOW_RSSI "show rssi\r\n"
65 #define SHOW_TIME "show time\r\n"
66 #define SHOW_CONNECTION "show connection\r\n"
70 #define AP_MODE "apmode %s %d"
72 #define CHG_DT "exit\r\n"
73 #define FACTORYRESET "factory RESTORE\r\n"
74 #define CLOSE "close\r\n"
75 #define JOIN "join %s\r\n"
76 #define LEAVE "leave\r\n"
77 #define PING "ping %s\r\n"
78 #define OPEN_CONN "open %s %d\r\n"
79 #define REBOOT "reboot\r\n"
80 #define FACTORY_RESET "factory RESET\r\n"
81 #define SLEEP "sleep\r\n"
84 #define SAVE "save\r\n"
92 static uint32_t wiflyPortNum;
93 static uint32_t wiflyBaudRate;
94 static uint32_t wiflyLogSev= 0;
97 static uint8_t WiFlyMode =
DATA_M;
100 static uint8_t WiflyWLANConnected =
FALSE;
101 static uint8_t WiflyTCPAutoConnect =
FALSE;
107 static void clearwBuffer()
121 static uint8_t Wifly_SendSet(uint32_t delay,
char *exResp,
const char * restrict format,...)
126 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
128 va_start( arg, format);
130 vsprintf(wBuffer, format, arg);
139 Log_log( wiflyLogSev,
LV_ERR,
"Error expected response: %s",wBuffer);
154 static char * Wifly_SendGet(uint32_t delay,
const char * restrict format,...)
158 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
160 va_start( arg, format);
162 vsprintf(wBuffer, format, arg);
181 static uint8_t Wifly_CMD()
185 while ((WiFlyMode==
DATA_M) && (attempts<3))
197 Log_log( wiflyLogSev,
LV_ERR,
"Error max attempts sending CMD command");
209 static uint8_t Wifly_exitCMD()
234 wiflyPortNum=PortNum;
235 wiflyBaudRate=baudrate;
237 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
245 Log_log( wiflyLogSev,
LV_ERR,
"Error during Wifly UART initialize");
249 uint8_t
Wifly_logStart( uint32_t PortNum, uint32_t baudrate, uint32_t logSeverity )
257 wiflyLogSev= logSeverity;
259 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
269 Log_log( wiflyLogSev,
LV_ERR,
"Error during Log UART initialize");
279 wiflyBaudRate=baudrate;
294 Log_log( wiflyLogSev,
LV_ERR,
"Error: Cannot change baud rate");
306 LPC_PINCON->PINSEL1 &= ( ~( 3 << 12 ) );
317 if (Wifly_CMD()==
TRUE)
330 WiflyWLANConnected=
FALSE;
371 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
375 if(WiflyWLANConnected==
FALSE)
379 WiflyWLANConnected=
TRUE;
387 WiflyWLANConnected=
FALSE;
401 Log_log( wiflyLogSev,
LV_ERR,
"Error WLAN configuration connection");
416 if (Wifly_CMD()==
TRUE)
430 if(Wifly_CMD()==
TRUE)
451 else if (AuthMode==
WEP)
467 if (Wifly_CMD()==
TRUE)
481 if (Wifly_CMD()==
TRUE)
485 Log_log( wiflyLogSev,
LV_INFO,
"Open connection:IP= %s, PORT= %d",dnsAddress,port);
496 if (Wifly_CMD()==
TRUE)
510 if(Wifly_CMD()==
TRUE)
520 if(Wifly_CMD()==
TRUE)
530 if(Wifly_CMD()==
TRUE)
540 if(Wifly_CMD()==
TRUE)
550 if(Wifly_CMD()==
TRUE)
560 if(Wifly_CMD()==
TRUE)
570 if(Wifly_CMD()==
TRUE)
580 if(Wifly_CMD()==
TRUE)
590 if(Wifly_CMD()==
TRUE)
600 if(Wifly_CMD()==
TRUE)
610 if(Wifly_CMD()==
TRUE)
620 if(Wifly_CMD()==
TRUE)
630 if(Wifly_CMD()==
TRUE)
640 if(Wifly_CMD()==
TRUE)
650 if(Wifly_CMD()==
TRUE)
662 if(Wifly_CMD()==
TRUE)
674 if(Wifly_CMD()==
TRUE)
684 if(Wifly_CMD()==
TRUE)
694 if(Wifly_CMD()==
TRUE)
704 if(Wifly_CMD()==
TRUE)
714 if(Wifly_CMD()==
TRUE)
724 if(Wifly_CMD()==
TRUE)
734 if(Wifly_CMD()==
TRUE)
744 if(Wifly_CMD()==
TRUE)
756 if(Wifly_CMD()==
TRUE)
759 string = strtok(
string,
"\r\n");
771 if(Wifly_CMD()==
TRUE)
775 string = strstr(wBuffer,
"Chan=") + strlen(
"Chan=");
776 rtn = strtol(
string , &
string, 10);
788 if(Wifly_CMD()==
TRUE)
792 string = strstr(wBuffer,
"TxPower=") + strlen(
"TxPower=");
793 tx = strtol(
string , &
string, 10);
804 if(Wifly_CMD()==
TRUE)
807 string = strstr(wBuffer,
"RSSI=(") + strlen(
"RSSI=(");
808 rssi = strtol(
string , &
string, 10);
819 if(Wifly_CMD()==
TRUE)
822 string = strstr(wBuffer,
"Time=") + strlen(
"Time=");
823 time = strtol(
string , &
string, 10);
833 if(Wifly_CMD()==
TRUE)
836 string = strstr(wBuffer,
"Mac Addr=") + strlen(
"Mac Addr=");
837 string = strtok(
string,
"\r\n");
849 if(Wifly_CMD()==
TRUE)
852 string = strstr(wBuffer,
"SSID=") + strlen(
"SSID=");
853 string = strtok(
string,
"\r\n");
865 if(Wifly_CMD()==
TRUE)
868 string = strstr(wBuffer,
"Ver: ") + strlen(
"Ver: ");
869 ver = strtod(
string , &
string);
881 if(Wifly_CMD()==
FALSE)
884 string = strstr(wBuffer,
"8") + strlen(
"8");
885 rtn = strtol(
string , &
string, 16);
895 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
902 buff=strcpy(HTTPRxBuff,wBuffer);
904 buff = strtok(buff,
"*");
912 uint8_t
Wifly_HTTPSend(
char *dnsAddress,
char *getCommand, uint32_t port, uint8_t proto)
916 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
955 char *
Wifly_UDPReceive(
char *address, uint32_t localPort, uint32_t remotePort,
const char * restrict command,...)
960 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
964 if(Wifly_exitCMD()==
TRUE)
967 va_start( arg, command);
969 buff=strcpy(UdpRxBuff,Wifly_SendGet(
UDP_DELAY, command, arg));
978 uint8_t
Wifly_UDPSend(
char *address, uint32_t localPort, uint32_t remotePort,
char *exResp ,
const char * restrict command,...)
983 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
987 if(Wifly_exitCMD()==
TRUE)
990 va_start( arg, command);
1005 if (Wifly_CMD()==
TRUE)
1031 va_start( arg, command);
1034 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
1041 buff=strcpy(TcpRxBuff,Wifly_SendGet(
TCP_DELAY,command, arg));
1053 uint8_t
Wifly_TCPSend(
char *address, uint32_t remotePort,
char *exResp ,
const char * restrict command,...)
1057 va_start( arg, command);
1059 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
1067 Wifly_SendSet(
TCP_DELAY, exResp, command, arg);
1081 void Wifly_TCPTimeOpen(uint32_t time,
char *address, uint32_t remotePort,
char *exResp ,
const char * restrict command,...)
1085 uint32_t timeSec=time*1000;
1089 while(WiflyTCPAutoConnect==
TRUE)
1091 va_start( arg, command);
1092 vsprintf(
string, command, arg);
1106 WiflyTCPAutoConnect=
FALSE;
1112 if (Wifly_CMD()==
TRUE)
1136 if(Wifly_CMD()==
TRUE)
1151 if (Wifly_CMD()==
TRUE)
1153 xSemaphoreTakeRecursive(
xMutexWifly, portMAX_DELAY );
1182 Log_log( wiflyLogSev,
LV_ERR,
"Soft AP not compatible with this version:ver= %f",ver);
uint8_t Wifly_setWlanJoin(uint32_t value)
uint32_t Log_start(uint32_t PortNum, uint32_t baudrate)
#define MODE_TCP
TCP Protocol configured.
uint8_t Wifly_logStart(uint32_t PortNum, uint32_t baudrate, uint32_t logSeverity)
uint8_t Wifly_setIpnetmask(char *address)
uint8_t Wifly_ChangeBaudRate(uint32_t baudrate)
uint8_t Wifly_HTTPConfig(char *dnsAddress, char *getCommand, uint32_t port, uint8_t proto)
uint8_t Wifly_APMode(char *ssid, uint8_t channel)
void PrintF_ClBuffUart(uint8_t portNum)
char * Wifly_HTTPReceive(char *dnsAddress, char *getCommand, uint32_t port, uint8_t proto)
uint8_t Wifly_start(uint32_t PortNum, uint32_t baudrate)
uint8_t Wifly_setWlanPhrase(char *password)
uint8_t Wifly_setIpNET(char *address)
uint8_t Wifly_WLANConnectPing(uint32_t AuthMode, char *ssid, char *passw, char *pingIP)
uint8_t Wifly_ping(char *ip)
void Log_log(uint8_t severity, uint8_t logLevel, const char *restrict format,...)
uint8_t Wifly_open(char *dnsAddress, uint32_t port)
uint8_t Wifly_setWlanSSID(char *value)
void PrintF_scan(uint8_t port, char *string, uint32_t timeout)
uint8_t Wifly_setIpProtocol(uint32_t value)
#define SET_IP_LOCAL_PORT
#define DATA_M
Wifly data mode */.
char * Wifly_TCPReceive(char *address, uint32_t remotePort, const char *restrict command,...)
uint8_t Wifly_setWlanTX(uint32_t tx)
#define MODE_HTTP
HTTP Protocol configured.
uint8_t Wifly_setWlanAuth(uint32_t value)
void Wifly_TCPTimeOpen(uint32_t time, char *address, uint32_t remotePort, char *exResp, const char *restrict command,...)
#define WLAN_DISCON
Wlan disconnected.
uint8_t Wifly_TCPSend(char *address, uint32_t remotePort, char *exResp, const char *restrict command,...)
uint8_t PrintF_ChkScan(uint8_t portNum, char *strScan, char *strExp, uint32_t timeout)
void Wifly_reset(uint8_t typeReset)
uint8_t Wifly_TCPConfig(char *address, uint32_t port)
uint8_t Wifly_setUartInstant(uint32_t value)
#define RESET_SOFTWARE
Software reset mode */.
uint32_t Wifly_showConnection()
uint8_t Wifly_setIpFlags(uint32_t mask)
uint8_t Wifly_setIpGateway(char *address)
uint8_t Wifly_getChannel()
uint8_t Wifly_factoryReset()
uint8_t Wifly_setOptionFormat(uint32_t value)
char * Wifly_UDPReceive(char *address, uint32_t localPort, uint32_t remotePort, const char *restrict command,...)
xSemaphoreHandle xMutexWifly
uint8_t Wifly_setWlanKey(char *value)
uint8_t Wifly_setIpRemote(uint32_t value)
#define MODE_UDP
UDP Protocol configured.
uint8_t Wifly_ConfigAPMode(char *ssid, uint8_t channel, char *ipAddress, char *subnetMask, char *gateway)
#define CMD_M
Wifly command mode */.
void PrintF_delayMs(uint32_t ms)
#define RESET_HARDWARE
Hardware reset mode */.
uint8_t Wifly_setDNSName(char *name)
uint8_t Wifly_setUartMode(uint32_t value)
uint8_t Wifly_UDPSend(char *address, uint32_t localPort, uint32_t remotePort, char *exResp, const char *restrict command,...)
void Wifly_TCPTimeOpenDisc()
void PrintF_print(uint32_t portNum, const char *restrict format,...)
#define WLAN_CON
Wlan connected.
uint8_t Wifly_setComRemote(char *value)
uint8_t Wifly_setIpTcpMode(uint32_t value)
#define WLAN_APCON
AP connected.
uint8_t Wifly_setIpAddress(char *address)
uint8_t Wifly_setUartBaud(uint32_t value)
uint8_t Wifly_WLANConfigConnect(uint32_t AuthMode, char *ssid, char *passw)
uint8_t Wifly_WLANConnect(uint32_t AuthMode, char *ssid, char *passw)
#define MODE_DISCON
Protocol not configured.
uint32_t PrintF_start(uint32_t portNum, uint32_t baudRate)
uint8_t Wifly_HTTPSend(char *dnsAddress, char *getCommand, uint32_t port, uint8_t proto)
uint8_t Wifly_setIpLocalPort(uint32_t value)
uint8_t Wifly_setIpDHCP(uint8_t mode)
uint8_t Wifly_setIpHost(char *address)
uint8_t Wifly_UDPConfig(char *address, uint32_t localPort, uint32_t remotePort)
uint8_t Wifly_setWlanChannel(uint8_t value)
#define MIXED
Mixed WPA1 and WPA2-SK.