diff --git a/prototype/esp32/esp32.ino b/prototype/esp32/esp32.ino index a0d830f..0e7eb88 100644 --- a/prototype/esp32/esp32.ino +++ b/prototype/esp32/esp32.ino @@ -1,58 +1,49 @@ -#include -#include -#include // the TinyGPS++ librarie -//#include // to convert serial from the GPS into something TinyGPS can understand -#include // from the ESP32 plugin -#include // for basic TCP t/rx -#include // for web server impl. -//#include // to send data back over USB +#include "TinyGPS++.h"; -#define GPS_TX_PIN 1 -#define GPS_RX_PIN 3 +#define GPS_RX_PIN 16 +#define GPS_TX_PIN 17 -const char* SSID = "Bytetools Technologies Inc."; -const char* PASS = "Fuck commies #69420!"; - -AsyncWebServer server(80); TinyGPSPlus gps; -//HardwareSerial SerialGPS(1); -// Load variables into globals +/* LAT = latitude +LON = longitude +ALT = altitude +Note: all 32-bit flaoting point decimal operations ARE atomic for the ESP32. +This means that sharing data across threads and cores IS SAFE! +So launching the web server on a separate thread will ot cause a data race */ +float LAT, LON, ALT; + void setup() { - Serial.begin(9600); - //SerialGPS.begin(9600, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); - WiFi.begin(SSID, PASS); - Serial.print("Connecting to wifi"); - Serial.print("."); - while (WiFi.status() != WL_CONNECTED) { - delay(1000); - Serial.print("."); - } - Serial.println(WiFi.localIP()); - server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { - request->send(200, "text/plain", "HELO"); - }); - server.begin(); + /* + Serial speed of USB. + NOTE: this model of ESP has a native baud rate of 115200, meaning that boot message will display properly along with all other serial output + */ + Serial.begin(115200); + // Serial speed of GPS module + Serial2.begin(9600, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); + Serial.println("Setup complete!"); } -// loop forever void loop() { - /* - //while (SerialGPS.available() > 0) { - //gps.encode(SerialGPS.read()); + // if there is anything to read from serial port 2 + while (Serial2.available()) { + // read one character into the char "in" + char in = Serial2.read(); + //Serial.print(in); + // send to GPS encoder to create new data + gps.encode(in); + // if a new location is given if (gps.location.isUpdated()) { - Serial.println("HELLO"); + // set all location attributes we desire + LAT = gps.location.lat(); + LON = gps.location.lng(); + ALT = gps.altitude.meters(); Serial.print("LAT="); - Serial.println(gps.location.lat()); - Serial.print("LON="); - Serial.println(gps.location.lng()); - Serial.print("ALT="); - Serial.println(gps.altitude.meters()); - } else { - Serial.println("INVALID LOCATION"); - } - //} - */ - //Serial.println("Nothing in buffer."); - //delay(1000); -} + Serial.print(LAT, 6); + Serial.print(" LON="); + Serial.print(LON, 6); + Serial.print(" ALT="); + Serial.println(ALT, 6); + } // close if + } // close while +} // close loop