#include #include //#define _GPS_ #ifdef _GPS_ #include #include #endif #define SECRET_SSID "S7-edge" #define SECRET_PASS "12345678" #ifdef _GPS_ static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 9600; TinyGPSPlus gps; SoftwareSerial ss(RXPin, TXPin); #endif char ssid[] = SECRET_SSID; char pass[] = SECRET_PASS; int status = WL_IDLE_STATUS; WiFiClient client; char server[] = "www.test.com"; unsigned long lastConnectionTime = 0; const unsigned long postingInterval = 60L * 1000L; void setup() { Serial.begin(9600); #ifdef _GPS_ ss.begin(GPSBaud); #endif while (!Serial) { ; } if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); while (true); } while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, pass); delay(10000); } Serial.print("You're connected to the network"); printWifiData(); } void loop() { #ifdef _GPS_ while (ss.available()) { gps.encode(ss.read()); if (gps.location.isUpdated()) { Serial.print("Latitude: "); Serial.println(gps.location.lat(), 6); Serial.print("Longitude: "); Serial.println(gps.location.lng(), 6); if (millis() - lastConnectionTime > postingInterval) { String cmd = "lat=" + String(gps.location.lat(), 6) + "&lng=" + String(gps.location.lng(), 6); Serial.println("Cmd: " + cmd); httpRequest(cmd); delay(10000); } while (client.available()) { char c = client.read(); Serial.write(c); } } } #else while (client.available()) { char c = client.read(); Serial.write(c); } String cmd = "lat=25.05&lng=121.46"; httpRequest(cmd); delay(10000); #endif } void printWifiData() { IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); } void httpRequest(String command) { client.stop(); if (client.connect(server, 80)) { Serial.println("connecting..."); client.println("GET /arduino.php?" + command + " HTTP/1.1"); client.println("Host: www.test.com"); client.println("User-Agent: ArduinoWiFi/1.1"); client.println("Connection: close"); client.println(); //delay(10000); } else { Serial.println("connection failed"); printWifiData(); //delay(5000); } lastConnectionTime = millis(); }