@@ -38,6 +38,32 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
3838 return ret == NSAPI_ERROR_OK ? WL_CONNECTED : WL_CONNECT_FAILED;
3939}
4040
41+ int arduino::WiFiClass::beginAP (const char * ssid, const char *passphrase, uint8_t channel) {
42+
43+ #if defined(ARDUINO_ENVIE_M7) || defined(ARDUINO_ENVIE_M4)
44+ softap = WhdSoftAPInterface::get_default_instance ();
45+ #endif
46+
47+ if (softap == NULL ) {
48+ return WL_CONNECT_FAILED;
49+ }
50+
51+ // Set ap ssid, password and channel
52+ SocketAddress ip (" 192.168.3.1" );
53+ SocketAddress gw (" 192.168.3.1" );
54+ SocketAddress netmask (" 255.255.255.0" );
55+ ((WhdSoftAPInterface*)softap)->set_network (ip, gw, netmask);
56+ nsapi_error_t ret = ((WhdSoftAPInterface*)softap)->start (ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */ , NULL , true /* cohexistance */ );
57+
58+ return ret == NSAPI_ERROR_OK ? WL_AP_LISTENING : WL_CONNECT_FAILED;
59+ }
60+
61+ void arduino::WiFiClass::end () {
62+ if (softap != NULL ) {
63+ ((WhdSoftAPInterface*)softap)->stop ();
64+ }
65+ }
66+
4167char * arduino::WiFiClass::SSID () {
4268 return _ssid;
4369}
@@ -136,13 +162,22 @@ uint8_t* arduino::WiFiClass::macAddress(uint8_t* mac) {
136162arduino::IPAddress arduino::WiFiClass::localIP () {
137163 arduino::IPAddress addr;
138164
139- const char *ip = wifi_if->get_ip_address ();
140- addr.fromString (ip); // @todo: the IP we get from Mbed is correct, but is parsed incorrectly by Arduino
165+ SocketAddress ip;
166+ if (softap != NULL ) {
167+ softap->get_ip_address (&ip);
168+ } else {
169+ wifi_if->get_ip_address (&ip);
170+ }
171+ addr.fromString (ip.get_ip_address ()); // @todo: the IP we get from Mbed is correct, but is parsed incorrectly by Arduino
141172 return addr;
142173}
143174
144175NetworkInterface *arduino::WiFiClass::getNetwork () {
145- return wifi_if;
176+ if (softap != NULL ) {
177+ return softap;
178+ } else {
179+ return wifi_if;
180+ }
146181}
147182
148183#if defined(ARDUINO_ENVIE_M7) || defined(ARDUINO_ENVIE_M4)
0 commit comments