This library can be used in mbed driver or mbed OS2. So If you want to use WizFi310 on mbed OS5, You have to use another WizFi310 library(wizfi310-driver). That is git repository for wizfi310-driver. - https://github.com/ARMmbed/wizfi310-driver

Dependents:   KT_IoTMakers_WizFi310_Example WizFi310_STATION_HelloWorld WizFi310_DNS_TCP_HelloWorld WizFi310_Ubidots ... more

This library can be used in mbed driver or mbed OS2. So If you want to use WizFi310 on mbed OS5, You have to use another WizFi310 library(wizfi310-driver).

That is git repository for wizfi310-driver. - https://github.com/ARMmbed/wizfi310-driver

Committer:
jehoon
Date:
Thu Nov 23 23:51:30 2017 +0000
Revision:
7:08771e4906bb
Parent:
1:16e57103a7dd
fix socket message parsing in isr

Who changed what in which revision?

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