WizFi310Interface
Fork of WizFi310Interface_Legacynew by
WizFi310/WizFi310_at.cpp@2:a4890cc8be69, 2017-09-18 (annotated)
- Committer:
- ajeet3004
- Date:
- Mon Sep 18 02:50:44 2017 +0000
- Revision:
- 2:a4890cc8be69
- Parent:
- 0:774ff1e8b26b
Changed the Library
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 | } |
ajeet3004 | 2:a4890cc8be69 | 102 | int WizFi310::cmdTEST() |
ajeet3004 | 2:a4890cc8be69 | 103 | { |
ajeet3004 | 2:a4890cc8be69 | 104 | return sendCommand("AT"); |
ajeet3004 | 2:a4890cc8be69 | 105 | } |
kaizen | 0:774ff1e8b26b | 106 | |
kaizen | 0:774ff1e8b26b | 107 | int WizFi310::cmdMECHO(bool flg) |
kaizen | 0:774ff1e8b26b | 108 | { |
kaizen | 0:774ff1e8b26b | 109 | int status; |
kaizen | 0:774ff1e8b26b | 110 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 111 | |
kaizen | 0:774ff1e8b26b | 112 | sprintf(cmd,"AT+MECHO=%d",flg); |
kaizen | 0:774ff1e8b26b | 113 | status = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 114 | |
kaizen | 0:774ff1e8b26b | 115 | return status; |
kaizen | 0:774ff1e8b26b | 116 | } |
kaizen | 0:774ff1e8b26b | 117 | |
kaizen | 0:774ff1e8b26b | 118 | int WizFi310::cmdUSET(int baud, char *flow) |
kaizen | 0:774ff1e8b26b | 119 | { |
kaizen | 0:774ff1e8b26b | 120 | int status; |
kaizen | 0:774ff1e8b26b | 121 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 122 | |
kaizen | 0:774ff1e8b26b | 123 | sprintf(cmd,"AT+USET=%d,N,8,1,%s",baud, flow); |
kaizen | 0:774ff1e8b26b | 124 | status = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 125 | |
kaizen | 0:774ff1e8b26b | 126 | if(status == 0) |
kaizen | 0:774ff1e8b26b | 127 | { |
kaizen | 0:774ff1e8b26b | 128 | wait(1); |
kaizen | 0:774ff1e8b26b | 129 | _state.buf->flush(); |
kaizen | 0:774ff1e8b26b | 130 | } |
kaizen | 0:774ff1e8b26b | 131 | |
kaizen | 0:774ff1e8b26b | 132 | return status; |
kaizen | 0:774ff1e8b26b | 133 | } |
kaizen | 0:774ff1e8b26b | 134 | |
kaizen | 0:774ff1e8b26b | 135 | int WizFi310::cmdMMAC(const char *mac) |
kaizen | 0:774ff1e8b26b | 136 | { |
kaizen | 0:774ff1e8b26b | 137 | int resp; |
kaizen | 0:774ff1e8b26b | 138 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 139 | |
kaizen | 0:774ff1e8b26b | 140 | if (mac) |
kaizen | 0:774ff1e8b26b | 141 | { |
kaizen | 0:774ff1e8b26b | 142 | sprintf(cmd, "AT+MMAC=%s",mac); |
kaizen | 0:774ff1e8b26b | 143 | resp = sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 144 | } |
kaizen | 0:774ff1e8b26b | 145 | else |
kaizen | 0:774ff1e8b26b | 146 | { |
kaizen | 0:774ff1e8b26b | 147 | sprintf(cmd, "AT+MMAC=?"); |
kaizen | 0:774ff1e8b26b | 148 | resp = sendCommand(cmd, RES_MACADDRESS); |
kaizen | 0:774ff1e8b26b | 149 | } |
kaizen | 0:774ff1e8b26b | 150 | |
kaizen | 0:774ff1e8b26b | 151 | return resp; |
kaizen | 0:774ff1e8b26b | 152 | } |
kaizen | 0:774ff1e8b26b | 153 | |
kaizen | 0:774ff1e8b26b | 154 | int WizFi310::cmdWSET(WiFiMode mode, const char *ssid, const char *bssid, int channel) |
kaizen | 0:774ff1e8b26b | 155 | { |
kaizen | 0:774ff1e8b26b | 156 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 157 | |
kaizen | 0:774ff1e8b26b | 158 | if(*bssid == NULL) |
kaizen | 0:774ff1e8b26b | 159 | { |
kaizen | 0:774ff1e8b26b | 160 | sprintf(cmd, "AT+WSET=%d,%s",mode, ssid); |
kaizen | 0:774ff1e8b26b | 161 | } |
kaizen | 0:774ff1e8b26b | 162 | else |
kaizen | 0:774ff1e8b26b | 163 | { |
kaizen | 0:774ff1e8b26b | 164 | sprintf(cmd, "AT+WSET=%d,%s,%s,%d",mode, ssid, bssid, channel); |
kaizen | 0:774ff1e8b26b | 165 | } |
kaizen | 0:774ff1e8b26b | 166 | |
kaizen | 0:774ff1e8b26b | 167 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 168 | } |
kaizen | 0:774ff1e8b26b | 169 | |
kaizen | 0:774ff1e8b26b | 170 | int WizFi310::cmdWANT(AntennaMode mode) |
kaizen | 0:774ff1e8b26b | 171 | { |
kaizen | 0:774ff1e8b26b | 172 | char cmd[CFG_CMD_SIZE]; |
ajeet3004 | 2:a4890cc8be69 | 173 | sprintf(cmd, "AT+WANT=%d",mode); |
kaizen | 0:774ff1e8b26b | 174 | |
kaizen | 0:774ff1e8b26b | 175 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 176 | } |
kaizen | 0:774ff1e8b26b | 177 | |
kaizen | 0:774ff1e8b26b | 178 | int WizFi310::cmdWNET(bool is_dhcp) |
kaizen | 0:774ff1e8b26b | 179 | { |
kaizen | 0:774ff1e8b26b | 180 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 181 | |
kaizen | 0:774ff1e8b26b | 182 | if(is_dhcp == true) |
kaizen | 0:774ff1e8b26b | 183 | { |
kaizen | 0:774ff1e8b26b | 184 | sprintf(cmd, "AT+WNET=1"); |
kaizen | 0:774ff1e8b26b | 185 | } |
kaizen | 0:774ff1e8b26b | 186 | else |
kaizen | 0:774ff1e8b26b | 187 | { |
kaizen | 0:774ff1e8b26b | 188 | sprintf(cmd, "AT+WNET=0,%s,%s,%s",_state.ip,_state.netmask,_state.gateway); |
kaizen | 0:774ff1e8b26b | 189 | } |
kaizen | 0:774ff1e8b26b | 190 | |
kaizen | 0:774ff1e8b26b | 191 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 192 | } |
kaizen | 0:774ff1e8b26b | 193 | |
kaizen | 0:774ff1e8b26b | 194 | int WizFi310::cmdWSEC(WiFiMode mode, const char *key, const char *sec) |
kaizen | 0:774ff1e8b26b | 195 | { |
kaizen | 0:774ff1e8b26b | 196 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 197 | |
kaizen | 0:774ff1e8b26b | 198 | if(*sec == NULL) |
kaizen | 0:774ff1e8b26b | 199 | { |
kaizen | 0:774ff1e8b26b | 200 | sprintf(cmd, "AT+WSEC=%d,,%s",mode, key); |
kaizen | 0:774ff1e8b26b | 201 | } |
kaizen | 0:774ff1e8b26b | 202 | else |
kaizen | 0:774ff1e8b26b | 203 | { |
kaizen | 0:774ff1e8b26b | 204 | sprintf(cmd, "AT+WSEC=%d,%s,%s",mode, sec, key); |
kaizen | 0:774ff1e8b26b | 205 | } |
kaizen | 0:774ff1e8b26b | 206 | |
kaizen | 0:774ff1e8b26b | 207 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 208 | } |
kaizen | 0:774ff1e8b26b | 209 | |
kaizen | 0:774ff1e8b26b | 210 | int WizFi310::cmdWJOIN() |
kaizen | 0:774ff1e8b26b | 211 | { |
kaizen | 0:774ff1e8b26b | 212 | //if( sendCommand("AT+WJOIN", RES_WJOIN, CFG_JOIN_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 213 | if( sendCommand("AT+WJOIN", RES_NULL, CFG_JOIN_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 214 | { |
kaizen | 0:774ff1e8b26b | 215 | WIZ_ERR("cmdWJOIN"); |
kaizen | 0:774ff1e8b26b | 216 | return -1; |
kaizen | 0:774ff1e8b26b | 217 | } |
kaizen | 0:774ff1e8b26b | 218 | |
kaizen | 0:774ff1e8b26b | 219 | if( cmdWSTATUS() ) |
kaizen | 0:774ff1e8b26b | 220 | return -1; |
kaizen | 0:774ff1e8b26b | 221 | |
kaizen | 0:774ff1e8b26b | 222 | WIZ_INFO("WizFi310 is successfully join to AP"); |
kaizen | 0:774ff1e8b26b | 223 | |
kaizen | 0:774ff1e8b26b | 224 | return 0; |
kaizen | 0:774ff1e8b26b | 225 | } |
kaizen | 0:774ff1e8b26b | 226 | |
kaizen | 0:774ff1e8b26b | 227 | int WizFi310::cmdWLEAVE() |
kaizen | 0:774ff1e8b26b | 228 | { |
kaizen | 0:774ff1e8b26b | 229 | return sendCommand("AT+WLEAVE"); |
kaizen | 0:774ff1e8b26b | 230 | } |
kaizen | 0:774ff1e8b26b | 231 | |
kaizen | 0:774ff1e8b26b | 232 | |
kaizen | 0:774ff1e8b26b | 233 | int WizFi310::cmdWSTATUS() |
kaizen | 0:774ff1e8b26b | 234 | { |
kaizen | 0:774ff1e8b26b | 235 | if( sendCommand("AT+WSTATUS", RES_WSTATUS, DEFAULT_WAIT_RESP_TIMEOUT) ) |
kaizen | 0:774ff1e8b26b | 236 | { |
kaizen | 0:774ff1e8b26b | 237 | WIZ_ERR("cmdWSTATUS"); |
kaizen | 0:774ff1e8b26b | 238 | return -1; |
kaizen | 0:774ff1e8b26b | 239 | } |
kaizen | 0:774ff1e8b26b | 240 | |
kaizen | 0:774ff1e8b26b | 241 | WIZ_INFO("IP : %s", _state.ip); |
kaizen | 0:774ff1e8b26b | 242 | WIZ_INFO("Gateway : %s", _state.gateway); |
kaizen | 0:774ff1e8b26b | 243 | |
kaizen | 0:774ff1e8b26b | 244 | return 0; |
kaizen | 0:774ff1e8b26b | 245 | } |
kaizen | 0:774ff1e8b26b | 246 | |
kaizen | 0:774ff1e8b26b | 247 | int WizFi310::cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode) |
kaizen | 0:774ff1e8b26b | 248 | { |
kaizen | 0:774ff1e8b26b | 249 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 250 | |
kaizen | 0:774ff1e8b26b | 251 | sprintf(cmd,"AT+SCON=%s,%s,,,%d,%s",openType, socketType, localPort, dataMode); |
kaizen | 0:774ff1e8b26b | 252 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 253 | } |
kaizen | 0:774ff1e8b26b | 254 | |
kaizen | 0:774ff1e8b26b | 255 | int WizFi310::cmdSCON ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort, const char *dataMode) |
kaizen | 0:774ff1e8b26b | 256 | { |
kaizen | 0:774ff1e8b26b | 257 | int resp; |
kaizen | 0:774ff1e8b26b | 258 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 259 | |
kaizen | 0:774ff1e8b26b | 260 | if(localPort == 0) |
kaizen | 0:774ff1e8b26b | 261 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%s,%s",openType, socketType, remoteIp, remotePort, "", dataMode); |
kaizen | 0:774ff1e8b26b | 262 | else |
kaizen | 0:774ff1e8b26b | 263 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%d,%s",openType, socketType, remoteIp, remotePort, localPort, dataMode); |
kaizen | 0:774ff1e8b26b | 264 | |
kaizen | 0:774ff1e8b26b | 265 | resp = sendCommand(cmd, RES_CONNECT, 30000 ); |
kaizen | 0:774ff1e8b26b | 266 | |
kaizen | 0:774ff1e8b26b | 267 | return resp; |
kaizen | 0:774ff1e8b26b | 268 | } |
kaizen | 0:774ff1e8b26b | 269 | |
kaizen | 0:774ff1e8b26b | 270 | int WizFi310::cmdSSEND ( const char *data, int cid, int sendSize, const char *remoteIp, int remotePort, int Timeout ) |
kaizen | 0:774ff1e8b26b | 271 | { |
kaizen | 0:774ff1e8b26b | 272 | int i, resp; |
kaizen | 0:774ff1e8b26b | 273 | Timer t; |
kaizen | 0:774ff1e8b26b | 274 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 275 | |
kaizen | 0:774ff1e8b26b | 276 | if (lockUart(Timeout)) return -1; |
kaizen | 0:774ff1e8b26b | 277 | |
kaizen | 0:774ff1e8b26b | 278 | clearFlags(); |
kaizen | 0:774ff1e8b26b | 279 | if(remoteIp == NULL) |
kaizen | 0:774ff1e8b26b | 280 | { |
kaizen | 0:774ff1e8b26b | 281 | sprintf(cmd,"AT+SSEND=%d,,,%d",cid, sendSize); |
kaizen | 0:774ff1e8b26b | 282 | } |
kaizen | 0:774ff1e8b26b | 283 | else |
kaizen | 0:774ff1e8b26b | 284 | { |
kaizen | 0:774ff1e8b26b | 285 | sprintf(cmd,"AT+SSEND=%d,%s,%d,%d",cid, remoteIp, remotePort, sendSize); |
kaizen | 0:774ff1e8b26b | 286 | } |
kaizen | 0:774ff1e8b26b | 287 | |
kaizen | 0:774ff1e8b26b | 288 | _con[cid].send_length = sendSize; |
kaizen | 0:774ff1e8b26b | 289 | |
kaizen | 0:774ff1e8b26b | 290 | resp = sendCommand(cmd, RES_SSEND, 2000, 1); |
kaizen | 0:774ff1e8b26b | 291 | |
kaizen | 0:774ff1e8b26b | 292 | unlockUart(); |
kaizen | 0:774ff1e8b26b | 293 | if(resp){ |
kaizen | 0:774ff1e8b26b | 294 | WIZ_DBG("Fail cmdSSEND") |
kaizen | 0:774ff1e8b26b | 295 | return -1; |
kaizen | 0:774ff1e8b26b | 296 | } |
kaizen | 0:774ff1e8b26b | 297 | |
kaizen | 0:774ff1e8b26b | 298 | for(i=0; i<sendSize; i++) |
kaizen | 0:774ff1e8b26b | 299 | { |
kaizen | 0:774ff1e8b26b | 300 | putUart(data[i]); |
kaizen | 0:774ff1e8b26b | 301 | } |
kaizen | 0:774ff1e8b26b | 302 | unlockUart(); |
kaizen | 0:774ff1e8b26b | 303 | |
kaizen | 0:774ff1e8b26b | 304 | if(Timeout) |
kaizen | 0:774ff1e8b26b | 305 | { |
kaizen | 0:774ff1e8b26b | 306 | t.start(); |
kaizen | 0:774ff1e8b26b | 307 | for(;;) |
kaizen | 0:774ff1e8b26b | 308 | { |
kaizen | 0:774ff1e8b26b | 309 | if (_state.ok) break; |
kaizen | 0:774ff1e8b26b | 310 | if (_state.failure || t.read_ms() > Timeout) |
kaizen | 0:774ff1e8b26b | 311 | { |
kaizen | 0:774ff1e8b26b | 312 | WIZ_WARN("failure or timeout\r\n"); |
kaizen | 0:774ff1e8b26b | 313 | return -1; |
kaizen | 0:774ff1e8b26b | 314 | } |
kaizen | 0:774ff1e8b26b | 315 | } |
kaizen | 0:774ff1e8b26b | 316 | t.stop(); |
kaizen | 0:774ff1e8b26b | 317 | } |
kaizen | 0:774ff1e8b26b | 318 | |
kaizen | 0:774ff1e8b26b | 319 | wait(0.05); |
kaizen | 0:774ff1e8b26b | 320 | WIZ_INFO("%s\r\n",data); |
kaizen | 0:774ff1e8b26b | 321 | |
kaizen | 0:774ff1e8b26b | 322 | return i; |
kaizen | 0:774ff1e8b26b | 323 | } |
kaizen | 0:774ff1e8b26b | 324 | |
kaizen | 0:774ff1e8b26b | 325 | |
kaizen | 0:774ff1e8b26b | 326 | int WizFi310::cmdCLOSE ( int cid ) |
kaizen | 0:774ff1e8b26b | 327 | { |
kaizen | 0:774ff1e8b26b | 328 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 329 | |
kaizen | 0:774ff1e8b26b | 330 | sprintf(cmd,"AT+SMGMT=%d",cid); |
kaizen | 0:774ff1e8b26b | 331 | return sendCommand(cmd); |
kaizen | 0:774ff1e8b26b | 332 | } |
kaizen | 0:774ff1e8b26b | 333 | |
kaizen | 0:774ff1e8b26b | 334 | |
kaizen | 0:774ff1e8b26b | 335 | int WizFi310::cmdFDNS (const char *host) |
kaizen | 0:774ff1e8b26b | 336 | { |
kaizen | 0:774ff1e8b26b | 337 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:774ff1e8b26b | 338 | int resp; |
kaizen | 0:774ff1e8b26b | 339 | |
kaizen | 0:774ff1e8b26b | 340 | sprintf(cmd,"AT+FDNS=%s,3000",host); |
kaizen | 0:774ff1e8b26b | 341 | resp = sendCommand(cmd, RES_FDNS); |
kaizen | 0:774ff1e8b26b | 342 | |
kaizen | 0:774ff1e8b26b | 343 | WIZ_DBG("%s",_state.resolv); |
kaizen | 0:774ff1e8b26b | 344 | return resp; |
kaizen | 0:774ff1e8b26b | 345 | } |
kaizen | 0:774ff1e8b26b | 346 | |
kaizen | 0:774ff1e8b26b | 347 | int WizFi310::cmdSMGMT ( int cid ) |
kaizen | 0:774ff1e8b26b | 348 | { |
kaizen | 0:774ff1e8b26b | 349 | int resp; |
kaizen | 0:774ff1e8b26b | 350 | |
kaizen | 0:774ff1e8b26b | 351 | resp = sendCommand("AT+SMGMT=?", RES_SMGMT); |
kaizen | 0:774ff1e8b26b | 352 | return resp; |
kaizen | 0:774ff1e8b26b | 353 | } |