update
Fork of WizFi310Interface_Legacynew by
WizFi310/WizFi310_at.cpp@0:774ff1e8b26b, 2017-04-19 (annotated)
- Committer:
- kaizen
- Date:
- Wed Apr 19 00:46:44 2017 +0000
- Revision:
- 0:774ff1e8b26b
- Child:
- 2:a4890cc8be69
First release WizFi310Interface for mbed OS2 ( Legacy version )
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaizen | 0:774ff1e8b26b | 1 | /* |
kaizen | 0:774ff1e8b26b | 2 | * Copyright (C) 2013 gsfan, MIT License |
kaizen | 0:774ff1e8b26b | 3 | * |
kaizen | 0:774ff1e8b26b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kaizen | 0:774ff1e8b26b | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kaizen | 0:774ff1e8b26b | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kaizen | 0:774ff1e8b26b | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kaizen | 0:774ff1e8b26b | 8 | * furnished to do so, subject to the following conditions: |
kaizen | 0:774ff1e8b26b | 9 | * |
kaizen | 0:774ff1e8b26b | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kaizen | 0:774ff1e8b26b | 11 | * substantial portions of the Software. |
kaizen | 0:774ff1e8b26b | 12 | * |
kaizen | 0:774ff1e8b26b | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kaizen | 0:774ff1e8b26b | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kaizen | 0:774ff1e8b26b | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kaizen | 0:774ff1e8b26b | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kaizen | 0:774ff1e8b26b | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kaizen | 0:774ff1e8b26b | 18 | */ |
kaizen | 0:774ff1e8b26b | 19 | /* Copyright (C) 2014 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 20 | * port to the Wiznet Module WizFi250 |
kaizen | 0:774ff1e8b26b | 21 | */ |
kaizen | 0:774ff1e8b26b | 22 | /* Copyright (C) 2017 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 23 | * port to the Wiznet Module WizFi310 |
kaizen | 0:774ff1e8b26b | 24 | */ |
kaizen | 0:774ff1e8b26b | 25 | |
kaizen | 0:774ff1e8b26b | 26 | #include "WizFi310.h" |
kaizen | 0:774ff1e8b26b | 27 | |
kaizen | 0:774ff1e8b26b | 28 | |
kaizen | 0:774ff1e8b26b | 29 | |
kaizen | 0:774ff1e8b26b | 30 | void WizFi310::clearFlags() |
kaizen | 0:774ff1e8b26b | 31 | { |
kaizen | 0:774ff1e8b26b | 32 | _state.ok = false; |
kaizen | 0:774ff1e8b26b | 33 | _state.failure = false; |
kaizen | 0:774ff1e8b26b | 34 | _state.res = RES_NULL; |
kaizen | 0:774ff1e8b26b | 35 | _state.n = 0; |
kaizen | 0:774ff1e8b26b | 36 | } |
kaizen | 0:774ff1e8b26b | 37 | |
kaizen | 0:774ff1e8b26b | 38 | |
kaizen | 0:774ff1e8b26b | 39 | int WizFi310::sendCommand(const char * cmd, Response res, int timeout, int opt) |
kaizen | 0:774ff1e8b26b | 40 | { |
kaizen | 0:774ff1e8b26b | 41 | unsigned int i; |
kaizen | 0:774ff1e8b26b | 42 | Timer t; |
kaizen | 0:774ff1e8b26b | 43 | |
kaizen | 0:774ff1e8b26b | 44 | if (lockUart(timeout)) return -1; |
kaizen | 0:774ff1e8b26b | 45 | |
kaizen | 0:774ff1e8b26b | 46 | clearFlags(); |
kaizen | 0:774ff1e8b26b | 47 | _state.res = res; |
kaizen | 0:774ff1e8b26b | 48 | |
kaizen | 0:774ff1e8b26b | 49 | WIZ_INFO("%s", cmd) |
kaizen | 0:774ff1e8b26b | 50 | |
kaizen | 0:774ff1e8b26b | 51 | for (i=0; i< strlen(cmd); i++) |
kaizen | 0:774ff1e8b26b | 52 | { |
kaizen | 0:774ff1e8b26b | 53 | putUart(cmd[i]); |
kaizen | 0:774ff1e8b26b | 54 | } |
kaizen | 0:774ff1e8b26b | 55 | |
kaizen | 0:774ff1e8b26b | 56 | if(opt == 1) |
kaizen | 0:774ff1e8b26b | 57 | { |
kaizen | 0:774ff1e8b26b | 58 | putUart('\r'); |
kaizen | 0:774ff1e8b26b | 59 | } |
kaizen | 0:774ff1e8b26b | 60 | else if(opt == 2) |
kaizen | 0:774ff1e8b26b | 61 | { |
kaizen | 0:774ff1e8b26b | 62 | putUart('\r'); |
kaizen | 0:774ff1e8b26b | 63 | putUart('\n'); |
kaizen | 0:774ff1e8b26b | 64 | } |
kaizen | 0:774ff1e8b26b | 65 | unlockUart(); |
kaizen | 0:774ff1e8b26b | 66 | |
kaizen | 0:774ff1e8b26b | 67 | if(timeout) |
kaizen | 0:774ff1e8b26b | 68 | { |
kaizen | 0:774ff1e8b26b | 69 | t.start(); |
kaizen | 0:774ff1e8b26b | 70 | for(;;) |
kaizen | 0:774ff1e8b26b | 71 | { |
kaizen | 0:774ff1e8b26b | 72 | if (_state.ok && _state.res == RES_NULL){ |
kaizen | 0:774ff1e8b26b | 73 | break; |
kaizen | 0:774ff1e8b26b | 74 | } |
kaizen | 0:774ff1e8b26b | 75 | |
kaizen | 0:774ff1e8b26b | 76 | if (_state.failure || t.read_ms() > timeout) |
kaizen | 0:774ff1e8b26b | 77 | { |
kaizen | 0:774ff1e8b26b | 78 | WIZ_WARN("failure of timeout[%d]ms\r\n",t.read_ms()); |
kaizen | 0:774ff1e8b26b | 79 | _state.res = RES_NULL; |
kaizen | 0:774ff1e8b26b | 80 | t.stop(); |
kaizen | 0:774ff1e8b26b | 81 | return -1; |
kaizen | 0:774ff1e8b26b | 82 | } |
kaizen | 0:774ff1e8b26b | 83 | } |
kaizen | 0:774ff1e8b26b | 84 | |
kaizen | 0:774ff1e8b26b | 85 | t.stop(); |
kaizen | 0:774ff1e8b26b | 86 | } |
kaizen | 0:774ff1e8b26b | 87 | |
kaizen | 0:774ff1e8b26b | 88 | WIZ_INFO("[OK]\r\n"); |
kaizen | 0:774ff1e8b26b | 89 | _state.res = RES_NULL; |
kaizen | 0:774ff1e8b26b | 90 | |
kaizen | 0:774ff1e8b26b | 91 | return 0; |
kaizen | 0:774ff1e8b26b | 92 | } |
kaizen | 0:774ff1e8b26b | 93 | |
kaizen | 0:774ff1e8b26b | 94 | int WizFi310::cmdAT() |
kaizen | 0:774ff1e8b26b | 95 | { |
kaizen | 0:774ff1e8b26b | 96 | int resp; |
kaizen | 0:774ff1e8b26b | 97 | |
kaizen | 0:774ff1e8b26b | 98 | resp = sendCommand("AT"); |
kaizen | 0:774ff1e8b26b | 99 | |
kaizen | 0:774ff1e8b26b | 100 | return resp; |
kaizen | 0:774ff1e8b26b | 101 | } |
kaizen | 0:774ff1e8b26b | 102 | |
kaizen | 0:774ff1e8b26b | 103 | int WizFi310::cmdMECHO(bool flg) |
kaizen | 0:774ff1e8b26b | 104 | { |
kaizen | 0:774ff1e8b26b | 105 | int status; |
kaizen | 0:774ff1e8b26b | 106 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 107 | |
kaizen | 0:774ff1e8b26b | 108 | sprintf(cmd,"AT+MECHO=%d",flg); |
kaizen | 0:774ff1e8b26b | 109 | status = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 110 | |
kaizen | 0:774ff1e8b26b | 111 | return status; |
kaizen | 0:774ff1e8b26b | 112 | } |
kaizen | 0:774ff1e8b26b | 113 | |
kaizen | 0:774ff1e8b26b | 114 | int WizFi310::cmdUSET(int baud, char *flow) |
kaizen | 0:774ff1e8b26b | 115 | { |
kaizen | 0:774ff1e8b26b | 116 | int status; |
kaizen | 0:774ff1e8b26b | 117 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 118 | |
kaizen | 0:774ff1e8b26b | 119 | sprintf(cmd,"AT+USET=%d,N,8,1,%s",baud, flow); |
kaizen | 0:774ff1e8b26b | 120 | status = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 121 | |
kaizen | 0:774ff1e8b26b | 122 | if(status == 0) |
kaizen | 0:774ff1e8b26b | 123 | { |
kaizen | 0:774ff1e8b26b | 124 | wait(1); |
kaizen | 0:774ff1e8b26b | 125 | _state.buf->flush(); |
kaizen | 0:774ff1e8b26b | 126 | } |
kaizen | 0:774ff1e8b26b | 127 | |
kaizen | 0:774ff1e8b26b | 128 | return status; |
kaizen | 0:774ff1e8b26b | 129 | } |
kaizen | 0:774ff1e8b26b | 130 | |
kaizen | 0:774ff1e8b26b | 131 | int WizFi310::cmdMMAC(const char *mac) |
kaizen | 0:774ff1e8b26b | 132 | { |
kaizen | 0:774ff1e8b26b | 133 | int resp; |
kaizen | 0:774ff1e8b26b | 134 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 135 | |
kaizen | 0:774ff1e8b26b | 136 | if (mac) |
kaizen | 0:774ff1e8b26b | 137 | { |
kaizen | 0:774ff1e8b26b | 138 | sprintf(cmd, "AT+MMAC=%s",mac); |
kaizen | 0:774ff1e8b26b | 139 | resp = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 140 | } |
kaizen | 0:774ff1e8b26b | 141 | else |
kaizen | 0:774ff1e8b26b | 142 | { |
kaizen | 0:774ff1e8b26b | 143 | sprintf(cmd, "AT+MMAC=?"); |
kaizen | 0:774ff1e8b26b | 144 | resp = sendCommand(cmd, RES_MACADDRESS); |
kaizen | 0:774ff1e8b26b | 145 | } |
kaizen | 0:774ff1e8b26b | 146 | |
kaizen | 0:774ff1e8b26b | 147 | return resp; |
kaizen | 0:774ff1e8b26b | 148 | } |
kaizen | 0:774ff1e8b26b | 149 | |
kaizen | 0:774ff1e8b26b | 150 | int WizFi310::cmdWSET(WiFiMode mode, const char *ssid, const char *bssid, int channel) |
kaizen | 0:774ff1e8b26b | 151 | { |
kaizen | 0:774ff1e8b26b | 152 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 153 | |
kaizen | 0:774ff1e8b26b | 154 | if(*bssid == NULL) |
kaizen | 0:774ff1e8b26b | 155 | { |
kaizen | 0:774ff1e8b26b | 156 | sprintf(cmd, "AT+WSET=%d,%s",mode, ssid); |
kaizen | 0:774ff1e8b26b | 157 | } |
kaizen | 0:774ff1e8b26b | 158 | else |
kaizen | 0:774ff1e8b26b | 159 | { |
kaizen | 0:774ff1e8b26b | 160 | sprintf(cmd, "AT+WSET=%d,%s,%s,%d",mode, ssid, bssid, channel); |
kaizen | 0:774ff1e8b26b | 161 | } |
kaizen | 0:774ff1e8b26b | 162 | |
kaizen | 0:774ff1e8b26b | 163 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 164 | } |
kaizen | 0:774ff1e8b26b | 165 | |
kaizen | 0:774ff1e8b26b | 166 | int WizFi310::cmdWANT(AntennaMode mode) |
kaizen | 0:774ff1e8b26b | 167 | { |
kaizen | 0:774ff1e8b26b | 168 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 169 | sprintf(cmd, "AT+WANT=%d",mode); |
kaizen | 0:774ff1e8b26b | 170 | |
kaizen | 0:774ff1e8b26b | 171 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 172 | } |
kaizen | 0:774ff1e8b26b | 173 | |
kaizen | 0:774ff1e8b26b | 174 | int WizFi310::cmdWNET(bool is_dhcp) |
kaizen | 0:774ff1e8b26b | 175 | { |
kaizen | 0:774ff1e8b26b | 176 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 177 | |
kaizen | 0:774ff1e8b26b | 178 | if(is_dhcp == true) |
kaizen | 0:774ff1e8b26b | 179 | { |
kaizen | 0:774ff1e8b26b | 180 | sprintf(cmd, "AT+WNET=1"); |
kaizen | 0:774ff1e8b26b | 181 | } |
kaizen | 0:774ff1e8b26b | 182 | else |
kaizen | 0:774ff1e8b26b | 183 | { |
kaizen | 0:774ff1e8b26b | 184 | sprintf(cmd, "AT+WNET=0,%s,%s,%s",_state.ip,_state.netmask,_state.gateway); |
kaizen | 0:774ff1e8b26b | 185 | } |
kaizen | 0:774ff1e8b26b | 186 | |
kaizen | 0:774ff1e8b26b | 187 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 188 | } |
kaizen | 0:774ff1e8b26b | 189 | |
kaizen | 0:774ff1e8b26b | 190 | int WizFi310::cmdWSEC(WiFiMode mode, const char *key, const char *sec) |
kaizen | 0:774ff1e8b26b | 191 | { |
kaizen | 0:774ff1e8b26b | 192 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 193 | |
kaizen | 0:774ff1e8b26b | 194 | if(*sec == NULL) |
kaizen | 0:774ff1e8b26b | 195 | { |
kaizen | 0:774ff1e8b26b | 196 | sprintf(cmd, "AT+WSEC=%d,,%s",mode, key); |
kaizen | 0:774ff1e8b26b | 197 | } |
kaizen | 0:774ff1e8b26b | 198 | else |
kaizen | 0:774ff1e8b26b | 199 | { |
kaizen | 0:774ff1e8b26b | 200 | sprintf(cmd, "AT+WSEC=%d,%s,%s",mode, sec, key); |
kaizen | 0:774ff1e8b26b | 201 | } |
kaizen | 0:774ff1e8b26b | 202 | |
kaizen | 0:774ff1e8b26b | 203 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 204 | } |
kaizen | 0:774ff1e8b26b | 205 | |
kaizen | 0:774ff1e8b26b | 206 | int WizFi310::cmdWJOIN() |
kaizen | 0:774ff1e8b26b | 207 | { |
kaizen | 0:774ff1e8b26b | 208 | //if( sendCommand("AT+WJOIN", RES_WJOIN, CFG_JOIN_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 209 | if( sendCommand("AT+WJOIN", RES_NULL, CFG_JOIN_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 210 | { |
kaizen | 0:774ff1e8b26b | 211 | WIZ_ERR("cmdWJOIN"); |
kaizen | 0:774ff1e8b26b | 212 | return -1; |
kaizen | 0:774ff1e8b26b | 213 | } |
kaizen | 0:774ff1e8b26b | 214 | |
kaizen | 0:774ff1e8b26b | 215 | if( cmdWSTATUS() ) |
kaizen | 0:774ff1e8b26b | 216 | return -1; |
kaizen | 0:774ff1e8b26b | 217 | |
kaizen | 0:774ff1e8b26b | 218 | WIZ_INFO("WizFi310 is successfully join to AP"); |
kaizen | 0:774ff1e8b26b | 219 | |
kaizen | 0:774ff1e8b26b | 220 | return 0; |
kaizen | 0:774ff1e8b26b | 221 | } |
kaizen | 0:774ff1e8b26b | 222 | |
kaizen | 0:774ff1e8b26b | 223 | int WizFi310::cmdWLEAVE() |
kaizen | 0:774ff1e8b26b | 224 | { |
kaizen | 0:774ff1e8b26b | 225 | return sendCommand("AT+WLEAVE"); |
kaizen | 0:774ff1e8b26b | 226 | } |
kaizen | 0:774ff1e8b26b | 227 | |
kaizen | 0:774ff1e8b26b | 228 | |
kaizen | 0:774ff1e8b26b | 229 | int WizFi310::cmdWSTATUS() |
kaizen | 0:774ff1e8b26b | 230 | { |
kaizen | 0:774ff1e8b26b | 231 | if( sendCommand("AT+WSTATUS", RES_WSTATUS, DEFAULT_WAIT_RESP_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 232 | { |
kaizen | 0:774ff1e8b26b | 233 | WIZ_ERR("cmdWSTATUS"); |
kaizen | 0:774ff1e8b26b | 234 | return -1; |
kaizen | 0:774ff1e8b26b | 235 | } |
kaizen | 0:774ff1e8b26b | 236 | |
kaizen | 0:774ff1e8b26b | 237 | WIZ_INFO("IP : %s", _state.ip); |
kaizen | 0:774ff1e8b26b | 238 | WIZ_INFO("Gateway : %s", _state.gateway); |
kaizen | 0:774ff1e8b26b | 239 | |
kaizen | 0:774ff1e8b26b | 240 | return 0; |
kaizen | 0:774ff1e8b26b | 241 | } |
kaizen | 0:774ff1e8b26b | 242 | |
kaizen | 0:774ff1e8b26b | 243 | int WizFi310::cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode) |
kaizen | 0:774ff1e8b26b | 244 | { |
kaizen | 0:774ff1e8b26b | 245 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 246 | |
kaizen | 0:774ff1e8b26b | 247 | sprintf(cmd,"AT+SCON=%s,%s,,,%d,%s",openType, socketType, localPort, dataMode); |
kaizen | 0:774ff1e8b26b | 248 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 249 | } |
kaizen | 0:774ff1e8b26b | 250 | |
kaizen | 0:774ff1e8b26b | 251 | int WizFi310::cmdSCON ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort, const char *dataMode) |
kaizen | 0:774ff1e8b26b | 252 | { |
kaizen | 0:774ff1e8b26b | 253 | int resp; |
kaizen | 0:774ff1e8b26b | 254 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 255 | |
kaizen | 0:774ff1e8b26b | 256 | if(localPort == 0) |
kaizen | 0:774ff1e8b26b | 257 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%s,%s",openType, socketType, remoteIp, remotePort, "", dataMode); |
kaizen | 0:774ff1e8b26b | 258 | else |
kaizen | 0:774ff1e8b26b | 259 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%d,%s",openType, socketType, remoteIp, remotePort, localPort, dataMode); |
kaizen | 0:774ff1e8b26b | 260 | |
kaizen | 0:774ff1e8b26b | 261 | resp = sendCommand(cmd, RES_CONNECT, 30000 ); |
kaizen | 0:774ff1e8b26b | 262 | |
kaizen | 0:774ff1e8b26b | 263 | return resp; |
kaizen | 0:774ff1e8b26b | 264 | } |
kaizen | 0:774ff1e8b26b | 265 | |
kaizen | 0:774ff1e8b26b | 266 | int WizFi310::cmdSSEND ( const char *data, int cid, int sendSize, const char *remoteIp, int remotePort, int Timeout ) |
kaizen | 0:774ff1e8b26b | 267 | { |
kaizen | 0:774ff1e8b26b | 268 | int i, resp; |
kaizen | 0:774ff1e8b26b | 269 | Timer t; |
kaizen | 0:774ff1e8b26b | 270 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 271 | |
kaizen | 0:774ff1e8b26b | 272 | if (lockUart(Timeout)) return -1; |
kaizen | 0:774ff1e8b26b | 273 | |
kaizen | 0:774ff1e8b26b | 274 | clearFlags(); |
kaizen | 0:774ff1e8b26b | 275 | if(remoteIp == NULL) |
kaizen | 0:774ff1e8b26b | 276 | { |
kaizen | 0:774ff1e8b26b | 277 | sprintf(cmd,"AT+SSEND=%d,,,%d",cid, sendSize); |
kaizen | 0:774ff1e8b26b | 278 | } |
kaizen | 0:774ff1e8b26b | 279 | else |
kaizen | 0:774ff1e8b26b | 280 | { |
kaizen | 0:774ff1e8b26b | 281 | sprintf(cmd,"AT+SSEND=%d,%s,%d,%d",cid, remoteIp, remotePort, sendSize); |
kaizen | 0:774ff1e8b26b | 282 | } |
kaizen | 0:774ff1e8b26b | 283 | |
kaizen | 0:774ff1e8b26b | 284 | _con[cid].send_length = sendSize; |
kaizen | 0:774ff1e8b26b | 285 | |
kaizen | 0:774ff1e8b26b | 286 | resp = sendCommand(cmd, RES_SSEND, 2000, 1); |
kaizen | 0:774ff1e8b26b | 287 | |
kaizen | 0:774ff1e8b26b | 288 | unlockUart(); |
kaizen | 0:774ff1e8b26b | 289 | if(resp){ |
kaizen | 0:774ff1e8b26b | 290 | WIZ_DBG("Fail cmdSSEND") |
kaizen | 0:774ff1e8b26b | 291 | return -1; |
kaizen | 0:774ff1e8b26b | 292 | } |
kaizen | 0:774ff1e8b26b | 293 | |
kaizen | 0:774ff1e8b26b | 294 | for(i=0; i<sendSize; i++) |
kaizen | 0:774ff1e8b26b | 295 | { |
kaizen | 0:774ff1e8b26b | 296 | putUart(data[i]); |
kaizen | 0:774ff1e8b26b | 297 | } |
kaizen | 0:774ff1e8b26b | 298 | unlockUart(); |
kaizen | 0:774ff1e8b26b | 299 | |
kaizen | 0:774ff1e8b26b | 300 | if(Timeout) |
kaizen | 0:774ff1e8b26b | 301 | { |
kaizen | 0:774ff1e8b26b | 302 | t.start(); |
kaizen | 0:774ff1e8b26b | 303 | for(;;) |
kaizen | 0:774ff1e8b26b | 304 | { |
kaizen | 0:774ff1e8b26b | 305 | if (_state.ok) break; |
kaizen | 0:774ff1e8b26b | 306 | if (_state.failure || t.read_ms() > Timeout) |
kaizen | 0:774ff1e8b26b | 307 | { |
kaizen | 0:774ff1e8b26b | 308 | WIZ_WARN("failure or timeout\r\n"); |
kaizen | 0:774ff1e8b26b | 309 | return -1; |
kaizen | 0:774ff1e8b26b | 310 | } |
kaizen | 0:774ff1e8b26b | 311 | } |
kaizen | 0:774ff1e8b26b | 312 | t.stop(); |
kaizen | 0:774ff1e8b26b | 313 | } |
kaizen | 0:774ff1e8b26b | 314 | |
kaizen | 0:774ff1e8b26b | 315 | wait(0.05); |
kaizen | 0:774ff1e8b26b | 316 | WIZ_INFO("%s\r\n",data); |
kaizen | 0:774ff1e8b26b | 317 | |
kaizen | 0:774ff1e8b26b | 318 | return i; |
kaizen | 0:774ff1e8b26b | 319 | } |
kaizen | 0:774ff1e8b26b | 320 | |
kaizen | 0:774ff1e8b26b | 321 | |
kaizen | 0:774ff1e8b26b | 322 | int WizFi310::cmdCLOSE ( int cid ) |
kaizen | 0:774ff1e8b26b | 323 | { |
kaizen | 0:774ff1e8b26b | 324 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 325 | |
kaizen | 0:774ff1e8b26b | 326 | sprintf(cmd,"AT+SMGMT=%d",cid); |
kaizen | 0:774ff1e8b26b | 327 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 328 | } |
kaizen | 0:774ff1e8b26b | 329 | |
kaizen | 0:774ff1e8b26b | 330 | |
kaizen | 0:774ff1e8b26b | 331 | int WizFi310::cmdFDNS (const char *host) |
kaizen | 0:774ff1e8b26b | 332 | { |
kaizen | 0:774ff1e8b26b | 333 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 334 | int resp; |
kaizen | 0:774ff1e8b26b | 335 | |
kaizen | 0:774ff1e8b26b | 336 | sprintf(cmd,"AT+FDNS=%s,3000",host); |
kaizen | 0:774ff1e8b26b | 337 | resp = sendCommand(cmd, RES_FDNS); |
kaizen | 0:774ff1e8b26b | 338 | |
kaizen | 0:774ff1e8b26b | 339 | WIZ_DBG("%s",_state.resolv); |
kaizen | 0:774ff1e8b26b | 340 | return resp; |
kaizen | 0:774ff1e8b26b | 341 | } |
kaizen | 0:774ff1e8b26b | 342 | |
kaizen | 0:774ff1e8b26b | 343 | int WizFi310::cmdSMGMT ( int cid ) |
kaizen | 0:774ff1e8b26b | 344 | { |
kaizen | 0:774ff1e8b26b | 345 | int resp; |
kaizen | 0:774ff1e8b26b | 346 | |
kaizen | 0:774ff1e8b26b | 347 | resp = sendCommand("AT+SMGMT=?", RES_SMGMT); |
kaizen | 0:774ff1e8b26b | 348 | return resp; |
kaizen | 0:774ff1e8b26b | 349 | } |