Skip to content

Commit

Permalink
bugfix cayenne encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus K Wilting authored and Klaus K Wilting committed Nov 18, 2018
1 parent b38d9ab commit 02b3f1e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define LPP_MSG_CHANNEL 28
#define LPP_HUMIDITY_CHANNEL 29
#define LPP_BAROMETER_CHANNEL 30
#define LPP_GAS_CHANNEL 31
#define LPP_GAS_CHANNEL 31

#endif

Expand Down
4 changes: 2 additions & 2 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ void do_timesync() {
} else {
ESP_LOGI(TAG, "No valid GPS time");
}
#endif
#endif // HAS_GPS
// Schedule a network time request at the next possible time
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
ESP_LOGI(TAG, "Network time request scheduled");
#endif
#endif // TIME_SYNC
} // do_timesync()

#ifndef VERBOSE
Expand Down
2 changes: 1 addition & 1 deletion src/lmic_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define LMIC_USE_INTERRUPTS

//time sync via LoRaWAN network, is not yet supported by TTN (LoRaWAN spec v1.0.3)
//#define LMIC_ENABLE_DeviceTimeReq 1
#define LMIC_ENABLE_DeviceTimeReq 1

// 16 μs per tick
// LMIC requires ticks to be 15.5μs - 100 μs long
Expand Down
12 changes: 8 additions & 4 deletions src/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,26 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f,
writeUint8(bitmap);
}

/* ---------------- Cayenne LPP format ---------- */
// http://community.mydevices.com/t/cayenne-lpp-2-0/7510
/* ---------------- Cayenne LPP 2.0 format ---------- */
// see specs http://community.mydevices.com/t/cayenne-lpp-2-0/7510
// PAYLOAD_ENCODER == 3 -> Dynamic Sensor Payload, using channels -> FPort 1
// PAYLOAD_ENCODER == 4 -> Packed Sensor Payload, not using channels -> FPort 2

#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4)

void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
#endif
buffer[cursor++] = LPP_TEMPERATURE;
buffer[cursor++] =
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
buffer[cursor++] = highByte(value1);
buffer[cursor++] = lowByte(value1);
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
#endif
buffer[cursor++] = LPP_HUMIDITY;
buffer[cursor++] =
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
buffer[cursor++] = highByte(value2);
buffer[cursor++] = lowByte(value2);
}
Expand Down
15 changes: 8 additions & 7 deletions src/senddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// put data to send in RTos Queues used for transmit over channels Lora and SPI
void SendData(uint8_t port) {

MessageBuffer_t SendBuffer;
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]

SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePort = port;
Expand All @@ -14,12 +14,6 @@ void SendData(uint8_t port) {
lora_enqueuedata(&SendBuffer);
spi_enqueuedata(&SendBuffer);

// clear counter if not in cumulative counter mode
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
reset_counters(); // clear macs container and reset all counters
get_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared");
}
} // SendData

// interrupt triggered function to prepare payload to send
Expand All @@ -30,6 +24,13 @@ void sendPayload() {
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
// append GPS data, if present

// clear counter if not in cumulative counter mode
if (cfg.countermode != 1) {
reset_counters(); // clear macs container and reset all counters
get_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared");
}

#ifdef HAS_GPS
// show NMEA data in debug mode, useful for debugging GPS on board
// connection
Expand Down

0 comments on commit 02b3f1e

Please sign in to comment.