diff --git a/TTGO-TBeam/TBeam-GPS-Example/.gitignore b/TTGO-TBeam/TBeam-GPS-Example/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/TTGO-TBeam/TBeam-GPS-Example/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/TTGO-TBeam/TBeam-GPS-Example/TBeam-GPS-Example.ino b/TTGO-TBeam/TBeam-GPS-Example/TBeam-GPS-Example.ino index 7d11508..9480aba 100644 --- a/TTGO-TBeam/TBeam-GPS-Example/TBeam-GPS-Example.ino +++ b/TTGO-TBeam/TBeam-GPS-Example/TBeam-GPS-Example.ino @@ -12,6 +12,7 @@ #include #include "arduino-timer.h" #include +#include #ifdef SERIAL_PORT_USBVIRTUAL #define Serial SERIAL_PORT_USBVIRTUAL @@ -39,9 +40,9 @@ void setup() { // given during the device provisioning then converted to a byte vector to // setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it // will get rejected - std::string deviceId("MAMAGPS1"); - std::vector devId; - devId.insert(devId.end(), deviceId.begin(), deviceId.end()); + std::string deviceId("MAMA0001"); + std::array devId; + std::copy(deviceId.begin(), deviceId.end(), devId.begin()); // Use the default setup provided by the SDK duck.setupWithDefaults(devId); @@ -124,6 +125,18 @@ String getGPSData() { return sensorVal; } +// Converting String to byte vector +std::vector stringToByteVector(const String& str) { + std::vector byteVec; + byteVec.reserve(str.length()); + + for (unsigned int i = 0; i < str.length(); ++i) { + byteVec.push_back(static_cast(str[i])); + } + + return byteVec; +} + bool runSensor(void *) { bool result; String sensorVal = getGPSData(); @@ -132,6 +145,7 @@ bool runSensor(void *) { Serial.println(sensorVal); //Send gps data - duck.sendData(topics::location, sensorVal); + std::vector message = stringToByteVector(sensorVal); + duck.sendData(topics::location, message); return true; }