Adaptation of the esp8266-driver demo program to control a GOPRO HERO3+ camera. This demo can only take a photo

Fork of mbed-os-example-mbed5-wifi by mbed-os-examples

Revision:
58:e62c5f2e41bd
Parent:
44:63be19b7a3db
--- a/main.cpp	Tue Mar 27 12:45:02 2018 +0100
+++ b/main.cpp	Sat Apr 07 14:57:24 2018 +0000
@@ -13,6 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+ 
+/* adaptation pour demo commande camera GOPRO
+ * C.Dupaty 04-2018   
+ */
 
 #include "mbed.h"
 #include "TCPSocket.h"
@@ -40,6 +44,11 @@
 
 #endif
 
+Serial pc(USBTX,USBRX);
+
+char photo[]="GET /bacpac/SH?t=goprofourcade&p=%01 HTTP/1.0\r\n\r\n"; // requete de prise de vue
+
+
 const char *sec2str(nsapi_security_t sec)
 {
     switch (sec) {
@@ -63,7 +72,7 @@
 {
     WiFiAccessPoint *ap;
 
-    printf("Scan:\n");
+    pc.printf("Scan:\n");
 
     int count = wifi->scan(NULL,0);
 
@@ -74,47 +83,52 @@
     count = wifi->scan(ap, count);
     for (int i = 0; i < count; i++)
     {
-        printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
+        pc.printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\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],
                ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
     }
-    printf("%d networks available.\n", count);
+    pc.printf("%d networks available.\n", count);
 
     delete[] ap;
     return count;
 }
 
-void http_demo(NetworkInterface *net)
+void envoie_commande(NetworkInterface *net, char *sbuffer)
 {
+    pc.printf("\x1B[33m");  //texte jaune
     TCPSocket socket;
     nsapi_error_t response;
 
-    printf("Sending HTTP request to www.arm.com...\n");
+    pc.printf("Sending HTTP request to gopro...\n");
 
     // Open a socket on the network interface, and create a TCP connection to www.arm.com
     socket.open(net);
-    response = socket.connect("www.arm.com", 80);
+    response = socket.connect("10.5.5.9", 80);
     if(0 != response) {
-        printf("Error connecting: %d\n", response);
+        pc.printf("Error connecting: %d\n", response);
         socket.close();
+        pc.printf("\x1B[37m");  //texte blanc
         return;
     }
+    else pc.printf("Connexion etablie\r\n");
 
     // Send a simple http request
-    char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
+    //  char sbuffer[] = "GET /bacpac/SH?t=goprofourcade&p=%01 HTTP/1.0\r\n\r\n";
+   // char sbuffer[] = "GET / HTTP/1.1\r\nhost: 10.5.5.9\r\n\r\n";
     nsapi_size_t size = strlen(sbuffer);
     response = 0;
     while(size)
     {
         response = socket.send(sbuffer+response, size);
         if (response < 0) {
-            printf("Error sending data: %d\n", response);
+            pc.printf("Error sending data: %d\n", response);
             socket.close();
+            pc.printf("\x1B[37m");  //texte blanc
             return;
         } else {
             size -= response;
             // Check if entire message was sent or not
-            printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
+            pc.printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
         }
     }
 
@@ -122,44 +136,61 @@
     char rbuffer[64];
     response = socket.recv(rbuffer, sizeof rbuffer);
     if (response < 0) {
-        printf("Error receiving data: %d\n", response);
+        pc.printf("Error receiving data: %d\n", response);
     } else {
-        printf("recv %d [%.*s]\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+        pc.printf("recv %d [%.*s]\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+        pc.printf("%s\r\n",rbuffer);
     }
 
     // Close the socket to return its memory and bring down the network interface
     socket.close();
+    pc.printf("\x1B[37m");  //texte blanc
 }
 
 int main()
 {
-    int count = 0;
-
-    printf("WiFi example\n\n");
-
+ //   int count = 0;
+    pc.printf("\x1B[2J");  //efface ecran
+    pc.printf("\x1B[0;0H");   // curseur en 0,0
+    pc.printf("\x1B[37m");  //texte blanc
+    pc.printf("-----------------------------------------------------------\r\n");
+    pc.printf("Exemple de controle de camera GOPRO par WIFI\r\n");
+    pc.printf("La camera GOPRO doit etre en marche, WIFI actif, mode photo\r\n");
+    pc.printf("-----------------------------------------------------------\r\n");
+/*  // Exploration 
     count = scan_demo(&wifi);
     if (count == 0) {
-        printf("No WIFI APNs found - can't continue further.\n");
+        pc.printf("No WIFI APNs found - can't continue further.\n");
+        return -1;
+    }
+*/
+    pc.printf("\nTentative de connection sur la borne WIFI %s...\n", MBED_CONF_APP_WIFI_SSID);
+    int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
+    if (ret != 0) {
+        pc.printf("\nConnection error\n");
         return -1;
     }
 
-    printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID);
-    int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
-    if (ret != 0) {
-        printf("\nConnection error\n");
-        return -1;
-    }
+    pc.printf("Connexion reussie\n\n");
+    pc.printf("MAC: %s\n", wifi.get_mac_address());
+    pc.printf("IP: %s\n", wifi.get_ip_address());
+    pc.printf("Netmask: %s\n", wifi.get_netmask());
+    pc.printf("Gateway: %s\n", wifi.get_gateway());
+    pc.printf("RSSI: %d\n\n", wifi.get_rssi());
 
-    printf("Success\n\n");
-    printf("MAC: %s\n", wifi.get_mac_address());
-    printf("IP: %s\n", wifi.get_ip_address());
-    printf("Netmask: %s\n", wifi.get_netmask());
-    printf("Gateway: %s\n", wifi.get_gateway());
-    printf("RSSI: %d\n\n", wifi.get_rssi());
-
-    http_demo(&wifi);
-
+    char * commande = photo;  // un exemple pour prendre une photo
+                              // la camera doit activee être en mode photo
+    char c='a';
+    while(c!='q')
+    {
+        while(pc.readable())c=pc.getc();
+        pc.printf("\r\nTaper q pour quitter\n\r");
+        pc.printf("ou n'importe quelle touche pour prendre une photo \n\r");
+        while(!pc.readable());
+        envoie_commande(&wifi,commande);
+    }
     wifi.disconnect();
-
-    printf("\nDone\n");
+   
+    pc.printf("Wifi deconnecte - fin du programme\n\r");
+    while(1);
 }