Skip to content

quick fix GPS compilation #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TTGO-TBeam/TBeam-GPS-Example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
22 changes: 18 additions & 4 deletions TTGO-TBeam/TBeam-GPS-Example/TBeam-GPS-Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>
#include "arduino-timer.h"
#include <MamaDuck.h>
#include <vector>

#ifdef SERIAL_PORT_USBVIRTUAL
#define Serial SERIAL_PORT_USBVIRTUAL
Expand Down Expand Up @@ -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<byte> devId;
devId.insert(devId.end(), deviceId.begin(), deviceId.end());
std::string deviceId("MAMA0001");
std::array<byte,8> devId;
std::copy(deviceId.begin(), deviceId.end(), devId.begin());

// Use the default setup provided by the SDK
duck.setupWithDefaults(devId);
Expand Down Expand Up @@ -124,6 +125,18 @@ String getGPSData() {
return sensorVal;
}

// Converting String to byte vector
std::vector<byte> stringToByteVector(const String& str) {
std::vector<byte> byteVec;
byteVec.reserve(str.length());

for (unsigned int i = 0; i < str.length(); ++i) {
byteVec.push_back(static_cast<byte>(str[i]));
}

return byteVec;
}

bool runSensor(void *) {
bool result;
String sensorVal = getGPSData();
Expand All @@ -132,6 +145,7 @@ bool runSensor(void *) {
Serial.println(sensorVal);

//Send gps data
duck.sendData(topics::location, sensorVal);
std::vector<byte> message = stringToByteVector(sensorVal);
duck.sendData(topics::location, message);
return true;
}