Skip to content

Commit

Permalink
these should all work now
Browse files Browse the repository at this point in the history
Signed-off-by: Brenton Poke <[email protected]>
  • Loading branch information
BrentonPoke committed Oct 31, 2024
1 parent c5adad1 commit 37eeef0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void setup() {
// setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it
// will get rejected
std::string deviceId("MAMA0001");
std::vector<byte> devId;
devId.insert(devId.end(), deviceId.begin(), deviceId.end());
std::array<byte,8> devId;
std::copy(deviceId.begin(), deviceId.end(), devId.begin());
duck.setupWithDefaults(devId);
detect.setDeviceId(devId);
detect.setDeviceId(deviceId);

// Load DetectorDuck profile
detect.setupRadio();
Expand Down
13 changes: 13 additions & 0 deletions examples/Custom-Mama-Examples/Custom-Mama-Detect/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,16 @@ description = Custom Mama Detect examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}

[env:local_ttgo_lora32_v1_3]
platform = espressif32
board = ttgo-lora32-v1
framework = arduino
monitor_speed = 115200
monitor_filters = time
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
build_flags =
${env.build_flags}
-DTTGO_1_3
31 changes: 14 additions & 17 deletions examples/Custom-Papa-Examples/AWS-PapaDuck/AWS-PapaDuck.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::queue<std::vector<byte>> packetQueue;

WiFiClientSecure wifiClient;
PubSubClient client(AWS_IOT_ENDPOINT, 8883, gotMsg, wifiClient);

void subscribeTo(const char* topic);
// / DMS locator URL requires a topicString, so we need to convert the topic
// from the packet to a string based on the topics code
std::string toTopicString(byte topic) {
Expand Down Expand Up @@ -137,22 +137,19 @@ int quackJson(CdpPacket packet) {
std::string dduid(packet.dduid.begin(), packet.dduid.end());

std::string muid(packet.muid.begin(), packet.muid.end());
std::string path(packet.path.begin(), packet.path.end());

Serial.println("[PAPA] Packet Received:");
Serial.println("[PAPA] sduid: " + std::string(sduid.c_str()));
Serial.println("[PAPA] dduid: " + std::string(dduid.c_str()));
Serial.printf("[PAPA] sduid: %s\n" , sduid.c_str());
Serial.printf("[PAPA] dduid: %s\n" , dduid.c_str());

Serial.println("[PAPA] muid: " + std::string(muid.c_str()));
Serial.println("[PAPA] path: " + std::string(path.c_str()));
Serial.println("[PAPA] data: " + std::string(payload.c_str()));
Serial.println("[PAPA] hops: " + std::string(packet.hopCount));
Serial.println("[PAPA] duck: " + std::string(packet.duckType));
Serial.printf("[PAPA] muid: %s\n" , muid.c_str());
Serial.printf("[PAPA] data: %s\n" , payload.c_str());
Serial.printf("[PAPA] hops: %s\n", packet.hopCount);
Serial.printf("[PAPA] duck: %s\n" , packet.duckType);

doc["DeviceID"] = sduid;
doc["MessageID"] = muid;
doc["Payload"].set(payload);
doc["path"].set(path);
doc["hops"].set(packet.hopCount);
doc["duckType"].set(packet.duckType);

Expand Down Expand Up @@ -190,8 +187,8 @@ int quackJson(CdpPacket packet) {
// The callback method simply takes the incoming packet and
// converts it to a JSON string, before sending it out over WiFi
void handleDuckData(std::vector<byte> packetBuffer) {
Serial.println("[PAPA] got packet: " +
convertToHex(packetBuffer.data(), packetBuffer.size()));
Serial.printf("[PAPA] got packet: %s\n" ,
convertToHex(packetBuffer.data(), packetBuffer.size()).c_str());

CdpPacket packet = CdpPacket(packetBuffer);
if(packet.topic != reservedTopic::ack) {
Expand Down Expand Up @@ -287,14 +284,14 @@ void gotMsg(char* topic, byte* payload, unsigned int payloadLength) {
destination += (char)payload[i];
}

std::vector<byte> dDevId;
dDevId.insert(dDevId.end(),destination.begin(),destination.end());
std::array<byte,8> dDevId;
std::copy(destination.begin(), destination.end(), dDevId.begin());

duck.sendCommand(sCmd, sValue, dDevId);
} else {
duck.sendCommand(sCmd, sValue);
}
} else if (std::string(topic).indexOf(CMD_STATE_HEALTH) > 0) {
} else if (std::string(topic).find(CMD_STATE_HEALTH) > 0) {
byte sCmd = 0;
std::vector<byte> sValue = {payload[0]};
if(payloadLength >= 8) {
Expand All @@ -303,8 +300,8 @@ void gotMsg(char* topic, byte* payload, unsigned int payloadLength) {
destination += (char)payload[i];
}

std::vector<byte> dDevId;
dDevId.insert(dDevId.end(),destination.begin(),destination.end());
std::array<byte,8> dDevId;
std::copy(destination.begin(), destination.end(), dDevId.begin());

duck.sendCommand(sCmd, sValue, dDevId);

Expand Down
13 changes: 13 additions & 0 deletions examples/Custom-Papa-Examples/AWS-PapaDuck/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,16 @@ description = AWS PapaDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}

[env:local_ttgo_lora32_v1_3]
platform = espressif32
board = ttgo-lora32-v1
framework = arduino
monitor_speed = 115200
monitor_filters = time
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
build_flags =
${env.build_flags}
-DTTGO_1_3
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void processMessageFromDucks(std::vector<byte> packetBuffer) {
// The callback method simply takes the incoming packet and
// converts it to a JSON string, before sending it out over MQTT
void handleDuckData(std::vector<byte> packetBuffer) {
Serial.println("[HUB] got packet: " + arduinoStringFromHex(packetBuffer.data(), packetBuffer.size()));
Serial.printf("[HUB] got packet: %s\n", arduinoStringFromHex(packetBuffer.data(), packetBuffer.size()).c_str());
processMessageFromDucks(packetBuffer);
}

Expand Down
13 changes: 13 additions & 0 deletions examples/Custom-Papa-Examples/MQTT-PapaDuck/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,16 @@ description = Papa MQTT CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}

[env:local_ttgo_lora32_v1_3]
platform = espressif32
board = ttgo-lora32-v1
framework = arduino
monitor_speed = 115200
monitor_filters = time
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
build_flags =
${env.build_flags}
-DTTGO_1_3

0 comments on commit 37eeef0

Please sign in to comment.