Crawl再現プロジェクト

Files at this revision

API Documentation at this revision

Comitter:
Nyakkey from Desktop
Date:
Tue Feb 12 02:37:19 2019 +0900
Parent:
0:d730ea7f5784
Child:
2:af1c058fb7f0
Commit message:
Try :: Add mbed_app.json and try setting from mbed_app.json (Nyakkey from Desktop)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Feb 09 14:58:44 2019 +0000
+++ b/main.cpp	Tue Feb 12 02:37:19 2019 +0900
@@ -5,11 +5,12 @@
 Serial pc (PA_2, PA_15, 115200) ;
 //Serial pc (PA_2, PA_15, 9600) ;
 //Serial esp (PB_6, PB_7, 115200) ;
-ESP8266Interface wifi(PB_6, PB_7, false); //tx,rx,debug
+//ESP8266Interface wifi(PB_6, PB_7, false); //tx,rx,debug
 PwmOut mt[2][2] = {{PA_3, PA_6}, {PA_9, PA_8}} ;
+WiFiInterface *wifi ;
 
-const char ip_addr_dns[4] = {192,168,137,1} ;
-SocketAddress dns(ip_addr_dns) ;
+//const char ip_addr_dns[4] = {192,168,137,1} ;
+//SocketAddress dns(ip_addr_dns) ;
 Thread t_led(osPriorityLow) ;
 //Thread t_serial(osPriorityAboveNormal) ; //configure mutax lock
 
@@ -108,7 +109,7 @@
     }
 }
 
-void http_demo()
+void http_demo(NetworkInterface *net)
 {
     TCPSocket socket;
     nsapi_error_t response;
@@ -116,7 +117,7 @@
     pc.printf("Sending HTTP request to www.arm.com...\n");
 
     // Open a socket on the network interface, and create a TCP connection to www.arm.com
-    response = socket.open(&wifi);
+    response = socket.open(net);
     if(0 != response) {
         pc.printf("socket.open() failed: %d\n", response);
         return;
@@ -171,15 +172,22 @@
     t_led.start(thread_led) ;
     //t_serial.start(thread_serial) ;
     pc.printf("Helloworld\r\n") ;
+    pc.printf("WiFi example\r\n");
+
+    wifi = WiFiInterface::get_default_instance();
+    if (!wifi) {
+        pc.printf("ERROR: No WiFiInterface found.\r\n");
+        return -1;
+    }
     
     WiFiAccessPoint *ap ;
     pc.printf("Scan:\r\n");
-    int count = wifi.scan(NULL,0);
+    int count = wifi->scan(NULL,0);
     pc.printf("scan end, %d access point founded\r\n",count) ;
     
     pc.printf("Scan:\r\n");
     ap = new WiFiAccessPoint[count];
-    count = wifi.scan(ap, count);
+    count = wifi->scan(ap, count);
     for (int i = 0; i < count; i++) {
         pc.printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\r\n", ap[i].get_ssid(),
                sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
@@ -188,19 +196,23 @@
     pc.printf("%d networks available.\r\n", count);
     
     pc.printf("Connecting...") ;
-    //int val = wifi.connect("Buffalo-G-C1B0", "hp43hgw57hhxe", NSAPI_SECURITY_WPA2);
-    int val = wifi.connect("KOUSUKE-PC_6698", "67eT0013", NSAPI_SECURITY_WPA2) ;
+    int val = wifi->connect("Buffalo-G-C1B0", "hp43hgw57hhxe", NSAPI_SECURITY_WPA2);
+    //int val = wifi->connect("KOUSUKE-PC_6698", "67eT0013", NSAPI_SECURITY_WPA2) ;
+    if (val != 0) {
+        pc.printf("ERROR: No WiFiInterface found.\r\n");
+        return -1;
+    }
     pc.printf("Connection Result::%d\r\n", val) ;
-    pc.printf("MAC: %s\r\n", wifi.get_mac_address());
-    pc.printf("IP: %s\r\n", wifi.get_ip_address());
-    pc.printf("Netmask: %s\r\n", wifi.get_netmask());
-    pc.printf("Gateway: %s\r\n", wifi.get_gateway());
-    pc.printf("RSSI: %d\r\n\n", wifi.get_rssi());
+    pc.printf("MAC: %s\r\n", wifi->get_mac_address());
+    pc.printf("IP: %s\r\n", wifi->get_ip_address());
+    pc.printf("Netmask: %s\r\n", wifi->get_netmask());
+    pc.printf("Gateway: %s\r\n", wifi->get_gateway());
+    pc.printf("RSSI: %d\r\n\n", wifi->get_rssi());
     
-    wifi.add_dns_server(dns) ;
-    http_demo() ;
+    //wifi.add_dns_server(dns) ;
+    http_demo(wifi) ;
     
     pc.printf("Finished\r\n");
     
     wait(osWaitForever) ;
-}
\ No newline at end of file
+}