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:
5:72212beb817c
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 #include "mbed.h"
jehoon 0:df571f8f8c03 24 #include "WizFi310.h"
jehoon 0:df571f8f8c03 25
jehoon 0:df571f8f8c03 26 WizFi310 * WizFi310::_inst;
jehoon 0:df571f8f8c03 27
jehoon 0:df571f8f8c03 28
jehoon 0:df571f8f8c03 29 WizFi310::WizFi310(PinName tx,PinName rx,PinName cts, PinName rts,PinName reset, PinName alarm, int baud):
jehoon 0:df571f8f8c03 30 _wizfi(tx,rx), _reset(reset)
jehoon 0:df571f8f8c03 31 {
jehoon 0:df571f8f8c03 32 _inst = this;
jehoon 0:df571f8f8c03 33 memset(&_state, 0, sizeof(_state));
jehoon 0:df571f8f8c03 34 memset(&_con, 0, sizeof(_con));
jehoon 0:df571f8f8c03 35 _state.initialized = false;
jehoon 0:df571f8f8c03 36 _state.status = STAT_READY;
jehoon 0:df571f8f8c03 37 _state.cid = -1;
jehoon 0:df571f8f8c03 38 _state.buf = new CircBuffer<char>(CFG_DATA_SIZE);
jehoon 0:df571f8f8c03 39
jehoon 0:df571f8f8c03 40 initUart(cts, rts, alarm, baud);
jehoon 0:df571f8f8c03 41 _reset.output();
jehoon 0:df571f8f8c03 42
jehoon 0:df571f8f8c03 43 setRts(true); // release
jehoon 5:72212beb817c 44
jehoon 0:df571f8f8c03 45 /*
jehoon 0:df571f8f8c03 46 wait_ms(500);
jehoon 0:df571f8f8c03 47 cmdAT();
jehoon 0:df571f8f8c03 48 cmdMECHO(false);
jehoon 0:df571f8f8c03 49 if(cts != NC && rts != NC)
jehoon 0:df571f8f8c03 50 cmdUSET(baud,"HW");
jehoon 0:df571f8f8c03 51 else
jehoon 0:df571f8f8c03 52 cmdUSET(baud,"N");
jehoon 0:df571f8f8c03 53
jehoon 0:df571f8f8c03 54 // WizFi310 will restart by cmdUSET command.
jehoon 0:df571f8f8c03 55 wait_ms(1000);
jehoon 0:df571f8f8c03 56 cmdAT();
jehoon 0:df571f8f8c03 57 */
jehoon 0:df571f8f8c03 58 }
jehoon 0:df571f8f8c03 59
jehoon 0:df571f8f8c03 60 int WizFi310::join(WiFiMode mode)
jehoon 0:df571f8f8c03 61 {
jehoon 0:df571f8f8c03 62 char sec[10];
jehoon 0:df571f8f8c03 63
jehoon 0:df571f8f8c03 64 if( cmdMMAC() ) return -1;
jehoon 0:df571f8f8c03 65
jehoon 0:df571f8f8c03 66 if(mode == WM_AP)
jehoon 0:df571f8f8c03 67 _state.wm = WM_AP;
jehoon 0:df571f8f8c03 68 else
jehoon 0:df571f8f8c03 69 _state.wm = WM_STATION;
jehoon 0:df571f8f8c03 70
jehoon 0:df571f8f8c03 71 if ( cmdWNET(_state.dhcp) ) return -1;
jehoon 0:df571f8f8c03 72 if ( cmdWSET(_state.wm, _state.ssid) ) return -1;
jehoon 0:df571f8f8c03 73
jehoon 0:df571f8f8c03 74
jehoon 0:df571f8f8c03 75 switch (_state.sec)
jehoon 0:df571f8f8c03 76 {
jehoon 0:df571f8f8c03 77 case NSAPI_SECURITY_NONE:
jehoon 0:df571f8f8c03 78 strcpy(sec,"OPEN");
jehoon 0:df571f8f8c03 79 break;
jehoon 0:df571f8f8c03 80 case NSAPI_SECURITY_WEP:
jehoon 0:df571f8f8c03 81 strcpy(sec,"WEP");
jehoon 0:df571f8f8c03 82 break;
jehoon 0:df571f8f8c03 83 case NSAPI_SECURITY_WPA:
jehoon 0:df571f8f8c03 84 strcpy(sec,"WPA");
jehoon 0:df571f8f8c03 85 break;
jehoon 0:df571f8f8c03 86 case NSAPI_SECURITY_WPA2:
jehoon 0:df571f8f8c03 87 strcpy(sec,"WPA2");
jehoon 0:df571f8f8c03 88 break;
jehoon 0:df571f8f8c03 89 default:
jehoon 0:df571f8f8c03 90 strcpy(sec,"");
jehoon 0:df571f8f8c03 91 break;
jehoon 0:df571f8f8c03 92 }
jehoon 0:df571f8f8c03 93
jehoon 0:df571f8f8c03 94 if ( cmdWSEC(_state.wm, _state.pass, sec) ) return -1;
jehoon 0:df571f8f8c03 95 if ( cmdWJOIN() ) return -1;;
jehoon 0:df571f8f8c03 96 _state.associated = true;
jehoon 0:df571f8f8c03 97
jehoon 0:df571f8f8c03 98 return 0;
jehoon 0:df571f8f8c03 99 }
jehoon 0:df571f8f8c03 100
jehoon 0:df571f8f8c03 101 bool WizFi310::isAssociated()
jehoon 0:df571f8f8c03 102 {
jehoon 0:df571f8f8c03 103 return _state.associated;
jehoon 0:df571f8f8c03 104 }
jehoon 0:df571f8f8c03 105
jehoon 0:df571f8f8c03 106 int WizFi310::setMacAddress (const char *mac)
jehoon 0:df571f8f8c03 107 {
jehoon 0:df571f8f8c03 108 if (cmdMMAC(mac)) return -1;
jehoon 0:df571f8f8c03 109 strncpy(_state.mac, mac, sizeof(_state.mac));
jehoon 0:df571f8f8c03 110 return 0;
jehoon 0:df571f8f8c03 111 }
jehoon 0:df571f8f8c03 112
jehoon 0:df571f8f8c03 113 int WizFi310::getMacAddress (char *mac)
jehoon 0:df571f8f8c03 114 {
jehoon 0:df571f8f8c03 115 if (cmdMMAC()) return -1;
jehoon 0:df571f8f8c03 116 strcpy(mac, _state.mac);
jehoon 0:df571f8f8c03 117 return 0;
jehoon 0:df571f8f8c03 118 }
jehoon 0:df571f8f8c03 119
jehoon 0:df571f8f8c03 120 int WizFi310::setAddress (const char *name)
jehoon 0:df571f8f8c03 121 {
jehoon 0:df571f8f8c03 122 _state.dhcp = true;
jehoon 0:df571f8f8c03 123 strncpy(_state.name, name, sizeof(_state.name));
jehoon 0:df571f8f8c03 124 return 0;
jehoon 0:df571f8f8c03 125 }
jehoon 0:df571f8f8c03 126
jehoon 0:df571f8f8c03 127 int WizFi310::setAddress (const char *ip, const char *netmask, const char *gateway, const char *dns, const char *name)
jehoon 0:df571f8f8c03 128 {
jehoon 0:df571f8f8c03 129 _state.dhcp = false;
jehoon 0:df571f8f8c03 130 strncpy(_state.ip, ip, sizeof(_state.ip));
jehoon 0:df571f8f8c03 131 strncpy(_state.netmask, netmask, sizeof(_state.netmask));
jehoon 0:df571f8f8c03 132 strncpy(_state.gateway, gateway, sizeof(_state.gateway));
jehoon 0:df571f8f8c03 133 strncpy(_state.nameserver, dns, sizeof(_state.nameserver));
jehoon 0:df571f8f8c03 134 strncpy(_state.name, name, sizeof(_state.name));
jehoon 0:df571f8f8c03 135 return 0;
jehoon 0:df571f8f8c03 136 }
jehoon 0:df571f8f8c03 137
jehoon 0:df571f8f8c03 138 int WizFi310::getAddress (char *ip, char *netmask, char *gateway)
jehoon 0:df571f8f8c03 139 {
jehoon 0:df571f8f8c03 140 strcpy(ip, _state.ip);
jehoon 0:df571f8f8c03 141 strcpy(netmask, _state.netmask);
jehoon 0:df571f8f8c03 142 strcpy(gateway, _state.gateway);
jehoon 0:df571f8f8c03 143 return 0;
jehoon 0:df571f8f8c03 144 }
jehoon 0:df571f8f8c03 145
jehoon 0:df571f8f8c03 146 int WizFi310::setSsid (const char *ssid)
jehoon 0:df571f8f8c03 147 {
jehoon 0:df571f8f8c03 148 strncpy(_state.ssid, ssid, sizeof(_state.ssid));
jehoon 0:df571f8f8c03 149 return 0;
jehoon 0:df571f8f8c03 150 }
jehoon 0:df571f8f8c03 151
jehoon 0:df571f8f8c03 152 //daniel
jehoon 0:df571f8f8c03 153 //int WizFi310::setSec ( Security sec, const char *phrase )
jehoon 0:df571f8f8c03 154 int WizFi310::setSec ( nsapi_security_t sec, const char *phrase )
jehoon 0:df571f8f8c03 155 {
jehoon 0:df571f8f8c03 156 _state.sec = sec;
jehoon 0:df571f8f8c03 157 strncpy(_state.pass, phrase, strlen(phrase));
jehoon 0:df571f8f8c03 158 return 0;
jehoon 0:df571f8f8c03 159 }
jehoon 0:df571f8f8c03 160
jehoon 0:df571f8f8c03 161 const char *WizFi310::getIPAddress(void)
jehoon 0:df571f8f8c03 162 {
jehoon 0:df571f8f8c03 163 return _state.ip;
jehoon 0:df571f8f8c03 164 }
jehoon 0:df571f8f8c03 165
jehoon 0:df571f8f8c03 166 const char *WizFi310::getMACAddress(void)
jehoon 0:df571f8f8c03 167 {
jehoon 0:df571f8f8c03 168 return _state.mac;
jehoon 0:df571f8f8c03 169 }
jehoon 0:df571f8f8c03 170