Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of WiFi_Camera by
Diff: main.cpp
- Revision:
- 6:ac677b091f76
- Parent:
- 5:dd5bc7b037c7
- Child:
- 7:aa6d95034cf2
diff -r dd5bc7b037c7 -r ac677b091f76 main.cpp
--- a/main.cpp Thu Nov 03 16:26:35 2016 +0000
+++ b/main.cpp Fri Nov 04 14:44:25 2016 +0000
@@ -1,25 +1,58 @@
#include "mbed.h"
+#include "rtos.h"
+
+#define GPS_ENABLE 1
+#define WIFI_ENABLE 1
+#define ETHER_ENABLE 0
+
+#if WIFI_ENABLE
#include "ESP8266.h"
+#endif // WIFI_ENABLE
+
+#if ETHER_ENABLE
+#include "EthernetInterface.h"
+#endif // ETHER_ENABLE
+
+#if GPS_ENABLE
#include "gps.h"
-
-#define GPS_ENABLE 1
+#endif // GPS_ENABLE
-Serial mc(P2_14, P2_15); //tx rx
+/****************************************************************************/
+/* Ether関連の定義 */
+/****************************************************************************/
+#if ETHER_ENABLE
+EthernetInterface eth;
+#define HOST_NAME "104.199.222.173" // HOST Address
+#define HOST_URL "/r-king/space/webapi.php?" // HOST URL
+#define HOST_PORT (80) // HOST Port
+#endif // ETHER_ENABLE
/****************************************************************************/
/* Wi-Fi関連の定義 */
/****************************************************************************/
+#if WIFI_ENABLE
SerialBuffered serial_buffered(P8_14, P8_15);
ESP8266 wifi;
-#define WLAN_SSID "4CE67630E22B" // AP Name
-#define WLAN_PASS "t3340pn5mkmkh" // AP PassWord
-#define HOST_NAME "104.199.222.173" // HOST Address
-#define HOST_URL "/r-king/space/webapi.php?" // HOST URL
-#define HOST_PORT (80) // HOST Port
+//#define WLAN_SSID "4CE67630E22B" // AP Name
+//#define WLAN_PASS "t3340pn5mkmkh" // AP PassWord
+//#define HOST_NAME "104.199.222.173" // HOST Address
+//#define HOST_URL "/r-king/space/webapi.php?" // HOST URL
+
+
+#define WLAN_SSID "DIRECT-W4Q0:DSC-QX10" // AP Name
+#define WLAN_PASS "kXocAsgx" // AP PassWord
+#define HOST_NAME "10.0.0.1" // HOST Address
+#define HOST_PORT (10000) // HOST Port
#define ESP_Serial serial_buffered // WiFi Module Port
#define ESP_Baud 115200 // WiFi Module Port
#define WIFI_BUF 256 // WiFi Buffer Length
+#define CAMERA_SHOT "{\"method\": \"actTakePicture\",\"params\": [],\"id\": 1,\"version\": \"1.0\"}"
+#define CAMERA_REC_START "{\"method\": \"startMovieRec\",\"params\": [],\"id\": 1,\"version\": \"1.0\"}"
+#define CAMERA_REC_STOP "{\"method\": \"stopMovieRec\",\"params\": [],\"id\": 1,\"version\": \"1.0\"}"
+
+#endif // WIFI_ENABLE
+
/****************************************************************************/
/* グローバル変数の定義 */
/****************************************************************************/
@@ -39,9 +72,15 @@
/* プロトタイプ宣言 */
/****************************************************************************/
static void loop(void);
+#if ETHER_ENABLE
+static int setupEther();
+static int sendEther();
+#endif // ETHER_ENABLE
+#if WIFI_ENABLE
static int setupWiFi();
static int sendWiFi();
static void resetWiFi();
+#endif // WIFI_ENABLE
#if GPS_ENABLE
int setupGPS();
static void onGpsGdaReceivedCallback(SerialGPS::NMEA_GGA* data);
@@ -63,8 +102,14 @@
printf("[Serial Start]\r\n");
// Setup Wi-Fi
+#if WIFI_ENABLE
isEnableWiFi = setupWiFi();
-
+#endif // WIFI_ENABLE
+
+#if ETHER_ENABLE
+ setupEther();
+#endif // ETHER_ENABLE
+
// Setup GPS
isEnableGPS = setupGPS();
@@ -106,16 +151,76 @@
if(cnt >= 1000)
{
- if(isEnableWiFi == true)
- {
- sendWiFi();
- }
+#if ETHER_ENABLE
+ sendEther();
+#endif // ETHER_ENABLE
+#if WIFI_ENABLE
+ sendWiFi();
+#endif // WIFI_ENABLE
cnt = 0;
}
cnt++;
}
}
+#if ETHER_ENABLE
+/****************************************************************************/
+// 機能 : Ether通信機能のセットアップ
+// 引数 : なし
+// 返り値 : ret FALSE(0):失敗 TRUE(1):成功
+// 備考 : なし
+/****************************************************************************/
+static int setupEther()
+{
+ eth.init(); //Use DHCP
+ eth.connect();
+ printf("IP Address is %s\n", eth.getIPAddress());
+
+ return 1;
+}
+
+/****************************************************************************/
+// 機能 : Ether送信処理
+// 引数 : なし
+// 返り値 : ret FALSE(0):失敗 TRUE(1):成功
+// 備考 : なし
+/****************************************************************************/
+static int sendEther()
+{
+ TCPSocketConnection sock;
+ sock.connect(HOST_NAME, HOST_PORT);
+
+ // build GET Request
+ char buf[1024] = {'\0'};
+ // sprintf(buf, "GET %saction=add&token=001&lat=%lf&lon=%lf&height=%lf HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n",
+ sprintf(buf, "GET %saction=add&token=001&lat=%lf&lon=%lf&height=%lf HTTP/1.1\r\nHost: %s\r\n\r\n",
+ HOST_URL,
+ g_lat,
+ g_lon,
+ g_alt,
+ HOST_NAME);
+
+ printf(buf);
+
+ sock.send_all(buf, sizeof(buf)-1);
+
+ char buffer[300];
+ int ret;
+ while (true) {
+ ret = sock.receive(buffer, sizeof(buffer)-1);
+ if (ret <= 0)
+ break;
+ buffer[ret] = '\0';
+ printf("Received %d chars from server:\n%s\n", ret, buffer);
+ }
+
+ sock.close();
+
+ return 1;
+}
+#endif // ETHER_ENABLE
+
+#if WIFI_ENABLE
/****************************************************************************/
// 機能 : Wi-Fi通信機能のセットアップ
// 引数 : なし
@@ -201,15 +306,20 @@
}
wait(1);
- // build GET Request
+ // build POST Request
char buf[1024] = {'\0'};
- // sprintf(buf, "GET %saction=add&token=001&lat=%lf&lon=%lf&height=%lf HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n",
+ // 写真の撮影
+ char dat[] = CAMERA_SHOT;
+ sprintf(buf, "POST /sony/camera HTTP/1.1\r\nHost: 10.0.0.1\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s\r\n",sizeof(dat), dat);
+
+ /*
sprintf(buf, "GET %saction=add&token=001&lat=%lf&lon=%lf&height=%lf HTTP/1.1\r\nHost: %s\r\n\r\n",
HOST_URL,
g_lat,
g_lon,
g_alt,
HOST_NAME);
+ */
printf(buf);
@@ -260,7 +370,7 @@
wifi.restart(); // AT+RST
wait(10);
}
-
+#endif // WIFI_ENABLE
#if GPS_ENABLE
/****************************************************************************
