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
main.cpp@58:e62c5f2e41bd, 2018-04-07 (annotated)
- Committer:
- cdupaty
- Date:
- Sat Apr 07 14:57:24 2018 +0000
- Revision:
- 58:e62c5f2e41bd
- Parent:
- 44:63be19b7a3db
GOPRO camera adaptation; Simple test to take a photo on GOPRO HERO3+
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:857719181846 | 1 | /* WiFi Example |
mbed_official | 0:857719181846 | 2 | * Copyright (c) 2016 ARM Limited |
mbed_official | 0:857719181846 | 3 | * |
mbed_official | 0:857719181846 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 0:857719181846 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 0:857719181846 | 6 | * You may obtain a copy of the License at |
mbed_official | 0:857719181846 | 7 | * |
mbed_official | 0:857719181846 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 0:857719181846 | 9 | * |
mbed_official | 0:857719181846 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 0:857719181846 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 0:857719181846 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 0:857719181846 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 0:857719181846 | 14 | * limitations under the License. |
mbed_official | 0:857719181846 | 15 | */ |
cdupaty | 58:e62c5f2e41bd | 16 | |
cdupaty | 58:e62c5f2e41bd | 17 | /* adaptation pour demo commande camera GOPRO |
cdupaty | 58:e62c5f2e41bd | 18 | * C.Dupaty 04-2018 |
cdupaty | 58:e62c5f2e41bd | 19 | */ |
mbed_official | 0:857719181846 | 20 | |
mbed_official | 0:857719181846 | 21 | #include "mbed.h" |
mbed_official | 0:857719181846 | 22 | #include "TCPSocket.h" |
mbed_official | 0:857719181846 | 23 | |
mbed_official | 32:bca3f5f442b3 | 24 | #define WIFI_ESP8266 1 |
mbed_official | 44:63be19b7a3db | 25 | #define WIFI_IDW0XX1 2 |
mbed_official | 32:bca3f5f442b3 | 26 | |
mbed_official | 0:857719181846 | 27 | #if TARGET_UBLOX_EVK_ODIN_W2 |
mbed_official | 1:aea78e21a7da | 28 | #include "OdinWiFiInterface.h" |
mbed_official | 1:aea78e21a7da | 29 | OdinWiFiInterface wifi; |
mbed_official | 10:5b5beb106156 | 30 | |
mbed_official | 21:b2f2f6a840b4 | 31 | #elif TARGET_REALTEK_RTL8195AM |
mbed_official | 21:b2f2f6a840b4 | 32 | #include "RTWInterface.h" |
mbed_official | 21:b2f2f6a840b4 | 33 | RTWInterface wifi; |
mbed_official | 21:b2f2f6a840b4 | 34 | |
mbed_official | 33:12f0df4d51d7 | 35 | #else // External WiFi modules |
mbed_official | 21:b2f2f6a840b4 | 36 | |
mbed_official | 32:bca3f5f442b3 | 37 | #if MBED_CONF_APP_WIFI_SHIELD == WIFI_ESP8266 |
mbed_official | 1:aea78e21a7da | 38 | #include "ESP8266Interface.h" |
mbed_official | 10:5b5beb106156 | 39 | ESP8266Interface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX); |
mbed_official | 44:63be19b7a3db | 40 | #elif MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1 |
mbed_official | 32:bca3f5f442b3 | 41 | #include "SpwfSAInterface.h" |
mbed_official | 32:bca3f5f442b3 | 42 | SpwfSAInterface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX); |
mbed_official | 44:63be19b7a3db | 43 | #endif // MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1 |
mbed_official | 10:5b5beb106156 | 44 | |
mbed_official | 33:12f0df4d51d7 | 45 | #endif |
mbed_official | 0:857719181846 | 46 | |
cdupaty | 58:e62c5f2e41bd | 47 | Serial pc(USBTX,USBRX); |
cdupaty | 58:e62c5f2e41bd | 48 | |
cdupaty | 58:e62c5f2e41bd | 49 | char photo[]="GET /bacpac/SH?t=goprofourcade&p=%01 HTTP/1.0\r\n\r\n"; // requete de prise de vue |
cdupaty | 58:e62c5f2e41bd | 50 | |
cdupaty | 58:e62c5f2e41bd | 51 | |
mbed_official | 0:857719181846 | 52 | const char *sec2str(nsapi_security_t sec) |
mbed_official | 0:857719181846 | 53 | { |
mbed_official | 0:857719181846 | 54 | switch (sec) { |
mbed_official | 0:857719181846 | 55 | case NSAPI_SECURITY_NONE: |
mbed_official | 0:857719181846 | 56 | return "None"; |
mbed_official | 0:857719181846 | 57 | case NSAPI_SECURITY_WEP: |
mbed_official | 0:857719181846 | 58 | return "WEP"; |
mbed_official | 0:857719181846 | 59 | case NSAPI_SECURITY_WPA: |
mbed_official | 0:857719181846 | 60 | return "WPA"; |
mbed_official | 0:857719181846 | 61 | case NSAPI_SECURITY_WPA2: |
mbed_official | 0:857719181846 | 62 | return "WPA2"; |
mbed_official | 0:857719181846 | 63 | case NSAPI_SECURITY_WPA_WPA2: |
mbed_official | 0:857719181846 | 64 | return "WPA/WPA2"; |
mbed_official | 0:857719181846 | 65 | case NSAPI_SECURITY_UNKNOWN: |
mbed_official | 0:857719181846 | 66 | default: |
mbed_official | 0:857719181846 | 67 | return "Unknown"; |
mbed_official | 0:857719181846 | 68 | } |
mbed_official | 0:857719181846 | 69 | } |
mbed_official | 0:857719181846 | 70 | |
mbed_official | 37:3a31525e2971 | 71 | int scan_demo(WiFiInterface *wifi) |
mbed_official | 0:857719181846 | 72 | { |
mbed_official | 0:857719181846 | 73 | WiFiAccessPoint *ap; |
mbed_official | 0:857719181846 | 74 | |
cdupaty | 58:e62c5f2e41bd | 75 | pc.printf("Scan:\n"); |
mbed_official | 0:857719181846 | 76 | |
mbed_official | 0:857719181846 | 77 | int count = wifi->scan(NULL,0); |
mbed_official | 0:857719181846 | 78 | |
mbed_official | 0:857719181846 | 79 | /* Limit number of network arbitrary to 15 */ |
mbed_official | 0:857719181846 | 80 | count = count < 15 ? count : 15; |
mbed_official | 0:857719181846 | 81 | |
mbed_official | 0:857719181846 | 82 | ap = new WiFiAccessPoint[count]; |
mbed_official | 0:857719181846 | 83 | count = wifi->scan(ap, count); |
mbed_official | 0:857719181846 | 84 | for (int i = 0; i < count; i++) |
mbed_official | 0:857719181846 | 85 | { |
cdupaty | 58:e62c5f2e41bd | 86 | pc.printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(), |
mbed_official | 0:857719181846 | 87 | sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], |
mbed_official | 0:857719181846 | 88 | ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel()); |
mbed_official | 0:857719181846 | 89 | } |
cdupaty | 58:e62c5f2e41bd | 90 | pc.printf("%d networks available.\n", count); |
mbed_official | 0:857719181846 | 91 | |
mbed_official | 0:857719181846 | 92 | delete[] ap; |
mbed_official | 37:3a31525e2971 | 93 | return count; |
mbed_official | 0:857719181846 | 94 | } |
mbed_official | 0:857719181846 | 95 | |
cdupaty | 58:e62c5f2e41bd | 96 | void envoie_commande(NetworkInterface *net, char *sbuffer) |
mbed_official | 0:857719181846 | 97 | { |
cdupaty | 58:e62c5f2e41bd | 98 | pc.printf("\x1B[33m"); //texte jaune |
mbed_official | 0:857719181846 | 99 | TCPSocket socket; |
mbed_official | 24:323569a565ec | 100 | nsapi_error_t response; |
mbed_official | 0:857719181846 | 101 | |
cdupaty | 58:e62c5f2e41bd | 102 | pc.printf("Sending HTTP request to gopro...\n"); |
mbed_official | 0:857719181846 | 103 | |
mbed_official | 0:857719181846 | 104 | // Open a socket on the network interface, and create a TCP connection to www.arm.com |
mbed_official | 0:857719181846 | 105 | socket.open(net); |
cdupaty | 58:e62c5f2e41bd | 106 | response = socket.connect("10.5.5.9", 80); |
mbed_official | 24:323569a565ec | 107 | if(0 != response) { |
cdupaty | 58:e62c5f2e41bd | 108 | pc.printf("Error connecting: %d\n", response); |
mbed_official | 24:323569a565ec | 109 | socket.close(); |
cdupaty | 58:e62c5f2e41bd | 110 | pc.printf("\x1B[37m"); //texte blanc |
mbed_official | 24:323569a565ec | 111 | return; |
mbed_official | 24:323569a565ec | 112 | } |
cdupaty | 58:e62c5f2e41bd | 113 | else pc.printf("Connexion etablie\r\n"); |
mbed_official | 0:857719181846 | 114 | |
mbed_official | 0:857719181846 | 115 | // Send a simple http request |
cdupaty | 58:e62c5f2e41bd | 116 | // char sbuffer[] = "GET /bacpac/SH?t=goprofourcade&p=%01 HTTP/1.0\r\n\r\n"; |
cdupaty | 58:e62c5f2e41bd | 117 | // char sbuffer[] = "GET / HTTP/1.1\r\nhost: 10.5.5.9\r\n\r\n"; |
mbed_official | 33:12f0df4d51d7 | 118 | nsapi_size_t size = strlen(sbuffer); |
mbed_official | 24:323569a565ec | 119 | response = 0; |
mbed_official | 24:323569a565ec | 120 | while(size) |
mbed_official | 24:323569a565ec | 121 | { |
mbed_official | 24:323569a565ec | 122 | response = socket.send(sbuffer+response, size); |
mbed_official | 24:323569a565ec | 123 | if (response < 0) { |
cdupaty | 58:e62c5f2e41bd | 124 | pc.printf("Error sending data: %d\n", response); |
mbed_official | 24:323569a565ec | 125 | socket.close(); |
cdupaty | 58:e62c5f2e41bd | 126 | pc.printf("\x1B[37m"); //texte blanc |
mbed_official | 24:323569a565ec | 127 | return; |
mbed_official | 24:323569a565ec | 128 | } else { |
mbed_official | 24:323569a565ec | 129 | size -= response; |
mbed_official | 24:323569a565ec | 130 | // Check if entire message was sent or not |
cdupaty | 58:e62c5f2e41bd | 131 | pc.printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); |
mbed_official | 24:323569a565ec | 132 | } |
mbed_official | 24:323569a565ec | 133 | } |
mbed_official | 0:857719181846 | 134 | |
mbed_official | 0:857719181846 | 135 | // Recieve a simple http response and print out the response line |
mbed_official | 0:857719181846 | 136 | char rbuffer[64]; |
mbed_official | 24:323569a565ec | 137 | response = socket.recv(rbuffer, sizeof rbuffer); |
mbed_official | 24:323569a565ec | 138 | if (response < 0) { |
cdupaty | 58:e62c5f2e41bd | 139 | pc.printf("Error receiving data: %d\n", response); |
mbed_official | 24:323569a565ec | 140 | } else { |
cdupaty | 58:e62c5f2e41bd | 141 | pc.printf("recv %d [%.*s]\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); |
cdupaty | 58:e62c5f2e41bd | 142 | pc.printf("%s\r\n",rbuffer); |
mbed_official | 24:323569a565ec | 143 | } |
mbed_official | 0:857719181846 | 144 | |
mbed_official | 0:857719181846 | 145 | // Close the socket to return its memory and bring down the network interface |
mbed_official | 0:857719181846 | 146 | socket.close(); |
cdupaty | 58:e62c5f2e41bd | 147 | pc.printf("\x1B[37m"); //texte blanc |
mbed_official | 0:857719181846 | 148 | } |
mbed_official | 0:857719181846 | 149 | |
mbed_official | 0:857719181846 | 150 | int main() |
mbed_official | 0:857719181846 | 151 | { |
cdupaty | 58:e62c5f2e41bd | 152 | // int count = 0; |
cdupaty | 58:e62c5f2e41bd | 153 | pc.printf("\x1B[2J"); //efface ecran |
cdupaty | 58:e62c5f2e41bd | 154 | pc.printf("\x1B[0;0H"); // curseur en 0,0 |
cdupaty | 58:e62c5f2e41bd | 155 | pc.printf("\x1B[37m"); //texte blanc |
cdupaty | 58:e62c5f2e41bd | 156 | pc.printf("-----------------------------------------------------------\r\n"); |
cdupaty | 58:e62c5f2e41bd | 157 | pc.printf("Exemple de controle de camera GOPRO par WIFI\r\n"); |
cdupaty | 58:e62c5f2e41bd | 158 | pc.printf("La camera GOPRO doit etre en marche, WIFI actif, mode photo\r\n"); |
cdupaty | 58:e62c5f2e41bd | 159 | pc.printf("-----------------------------------------------------------\r\n"); |
cdupaty | 58:e62c5f2e41bd | 160 | /* // Exploration |
mbed_official | 37:3a31525e2971 | 161 | count = scan_demo(&wifi); |
mbed_official | 37:3a31525e2971 | 162 | if (count == 0) { |
cdupaty | 58:e62c5f2e41bd | 163 | pc.printf("No WIFI APNs found - can't continue further.\n"); |
cdupaty | 58:e62c5f2e41bd | 164 | return -1; |
cdupaty | 58:e62c5f2e41bd | 165 | } |
cdupaty | 58:e62c5f2e41bd | 166 | */ |
cdupaty | 58:e62c5f2e41bd | 167 | pc.printf("\nTentative de connection sur la borne WIFI %s...\n", MBED_CONF_APP_WIFI_SSID); |
cdupaty | 58:e62c5f2e41bd | 168 | int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); |
cdupaty | 58:e62c5f2e41bd | 169 | if (ret != 0) { |
cdupaty | 58:e62c5f2e41bd | 170 | pc.printf("\nConnection error\n"); |
mbed_official | 37:3a31525e2971 | 171 | return -1; |
mbed_official | 37:3a31525e2971 | 172 | } |
mbed_official | 0:857719181846 | 173 | |
cdupaty | 58:e62c5f2e41bd | 174 | pc.printf("Connexion reussie\n\n"); |
cdupaty | 58:e62c5f2e41bd | 175 | pc.printf("MAC: %s\n", wifi.get_mac_address()); |
cdupaty | 58:e62c5f2e41bd | 176 | pc.printf("IP: %s\n", wifi.get_ip_address()); |
cdupaty | 58:e62c5f2e41bd | 177 | pc.printf("Netmask: %s\n", wifi.get_netmask()); |
cdupaty | 58:e62c5f2e41bd | 178 | pc.printf("Gateway: %s\n", wifi.get_gateway()); |
cdupaty | 58:e62c5f2e41bd | 179 | pc.printf("RSSI: %d\n\n", wifi.get_rssi()); |
mbed_official | 0:857719181846 | 180 | |
cdupaty | 58:e62c5f2e41bd | 181 | char * commande = photo; // un exemple pour prendre une photo |
cdupaty | 58:e62c5f2e41bd | 182 | // la camera doit activee être en mode photo |
cdupaty | 58:e62c5f2e41bd | 183 | char c='a'; |
cdupaty | 58:e62c5f2e41bd | 184 | while(c!='q') |
cdupaty | 58:e62c5f2e41bd | 185 | { |
cdupaty | 58:e62c5f2e41bd | 186 | while(pc.readable())c=pc.getc(); |
cdupaty | 58:e62c5f2e41bd | 187 | pc.printf("\r\nTaper q pour quitter\n\r"); |
cdupaty | 58:e62c5f2e41bd | 188 | pc.printf("ou n'importe quelle touche pour prendre une photo \n\r"); |
cdupaty | 58:e62c5f2e41bd | 189 | while(!pc.readable()); |
cdupaty | 58:e62c5f2e41bd | 190 | envoie_commande(&wifi,commande); |
cdupaty | 58:e62c5f2e41bd | 191 | } |
mbed_official | 0:857719181846 | 192 | wifi.disconnect(); |
cdupaty | 58:e62c5f2e41bd | 193 | |
cdupaty | 58:e62c5f2e41bd | 194 | pc.printf("Wifi deconnecte - fin du programme\n\r"); |
cdupaty | 58:e62c5f2e41bd | 195 | while(1); |
mbed_official | 0:857719181846 | 196 | } |