@@ -38,6 +38,32 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
38
38
return ret == NSAPI_ERROR_OK ? WL_CONNECTED : WL_CONNECT_FAILED;
39
39
}
40
40
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
+
41
67
char * arduino::WiFiClass::SSID () {
42
68
return _ssid;
43
69
}
@@ -136,13 +162,22 @@ uint8_t* arduino::WiFiClass::macAddress(uint8_t* mac) {
136
162
arduino::IPAddress arduino::WiFiClass::localIP () {
137
163
arduino::IPAddress addr;
138
164
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
141
172
return addr;
142
173
}
143
174
144
175
NetworkInterface *arduino::WiFiClass::getNetwork () {
145
- return wifi_if;
176
+ if (softap != NULL ) {
177
+ return softap;
178
+ } else {
179
+ return wifi_if;
180
+ }
146
181
}
147
182
148
183
#if defined(ARDUINO_ENVIE_M7) || defined(ARDUINO_ENVIE_M4)
0 commit comments