button read and send
This commit is contained in:
parent
baa93ad916
commit
eb37a79d46
@ -167,6 +167,10 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
|
||||
bytes 10-11: HDOP
|
||||
bytes 12-13: Altitude [meter]
|
||||
|
||||
**Port #5:** Button pressed signal
|
||||
|
||||
byte 1: static value 0x01
|
||||
|
||||
|
||||
[**plain_decoder.js**](src/TTN/plain_decoder.js)
|
||||
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -139,9 +139,9 @@ void readButton() {
|
||||
ButtonPressedIRQ = 0;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
ESP_LOGI(TAG, "Button pressed");
|
||||
ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults");
|
||||
eraseConfig();
|
||||
esp_restart();
|
||||
payload.reset();
|
||||
payload.addButton(0x01);
|
||||
senddata(BUTTONPORT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -211,7 +211,7 @@ void sendPayload() {
|
||||
}
|
||||
#endif
|
||||
|
||||
senddata(PAYLOADPORT);
|
||||
senddata(COUNTERPORT);
|
||||
}
|
||||
} // sendPayload()
|
||||
|
||||
@ -442,7 +442,7 @@ void loop() {
|
||||
"Memory full, counter cleared (heap low water mark = %d Bytes / "
|
||||
"free heap = %d bytes)",
|
||||
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
|
||||
senddata(PAYLOADPORT); // send data before clearing counters
|
||||
senddata(COUNTERPORT); // send data before clearing counters
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
reset_salt(); // get new salt for salting hashes
|
||||
}
|
||||
|
@ -47,11 +47,12 @@
|
||||
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
|
||||
|
||||
// Ports on which the device sends and listenes on LoRaWAN and SPI
|
||||
#define PAYLOADPORT 1 // Port on which device sends counts
|
||||
#define COUNTERPORT 1 // Port on which device sends counts
|
||||
#define RCMDPORT 2 // Port on which device listenes for remote commands
|
||||
#define STATUSPORT 2 // Port on which device sends remote command results
|
||||
#define CONFIGPORT 3 // Port on which device sends gps query results
|
||||
#define GPSPORT 4 // Port on which device sends gps query results
|
||||
#define BUTTONPORT 5 // Port on which device sends button pressed signal
|
||||
#define CAYENNEPORT 2 // Port for Cayenne LPP 2.0 packet sensor encoding
|
||||
|
||||
// Default RGB LED luminosity (in %)
|
||||
|
114
src/payload.cpp
114
src/payload.cpp
@ -26,24 +26,6 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
buffer[cursor++] = value2;
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
buffer[cursor++] = value.latitude >> 24;
|
||||
buffer[cursor++] = value.latitude >> 16;
|
||||
buffer[cursor++] = value.latitude >> 8;
|
||||
buffer[cursor++] = value.latitude;
|
||||
buffer[cursor++] = value.longitude >> 24;
|
||||
buffer[cursor++] = value.longitude >> 16;
|
||||
buffer[cursor++] = value.longitude >> 8;
|
||||
buffer[cursor++] = value.longitude;
|
||||
buffer[cursor++] = value.satellites;
|
||||
buffer[cursor++] = value.hdop >> 8;
|
||||
buffer[cursor++] = value.hdop;
|
||||
buffer[cursor++] = value.altitude >> 8;
|
||||
buffer[cursor++] = value.altitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
void PayloadConvert::addConfig(configData_t value) {
|
||||
buffer[cursor++] = value.lorasf;
|
||||
buffer[cursor++] = value.txpower;
|
||||
@ -83,6 +65,28 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
buffer[cursor++] = (uint32_t)cputemp;
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
buffer[cursor++] = value.latitude >> 24;
|
||||
buffer[cursor++] = value.latitude >> 16;
|
||||
buffer[cursor++] = value.latitude >> 8;
|
||||
buffer[cursor++] = value.latitude;
|
||||
buffer[cursor++] = value.longitude >> 24;
|
||||
buffer[cursor++] = value.longitude >> 16;
|
||||
buffer[cursor++] = value.longitude >> 8;
|
||||
buffer[cursor++] = value.longitude;
|
||||
buffer[cursor++] = value.satellites;
|
||||
buffer[cursor++] = value.hdop >> 8;
|
||||
buffer[cursor++] = value.hdop;
|
||||
buffer[cursor++] = value.altitude >> 8;
|
||||
buffer[cursor++] = value.altitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BUTTON
|
||||
void PayloadConvert::addButton(uint8_t value) { buffer[cursor++] = value; }
|
||||
#endif
|
||||
|
||||
/* ---------------- packed format with LoRa serialization Encoder ---------- */
|
||||
// derived from
|
||||
// https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp
|
||||
@ -94,15 +98,6 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
writeUint16(value2);
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
writeLatLng(value.latitude, value.longitude);
|
||||
writeUint8(value.satellites);
|
||||
writeUint16(value.hdop);
|
||||
writeUint16(value.altitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
void PayloadConvert::addConfig(configData_t value) {
|
||||
writeUint8(value.lorasf);
|
||||
writeUint8(value.txpower);
|
||||
@ -124,6 +119,19 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
writeTemperature(cputemp);
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
writeLatLng(value.latitude, value.longitude);
|
||||
writeUint8(value.satellites);
|
||||
writeUint16(value.hdop);
|
||||
writeUint16(value.altitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BUTTON
|
||||
void PayloadConvert::addButton(uint8_t value) { writeUint8(value); }
|
||||
#endif
|
||||
|
||||
void PayloadConvert::intToBytes(uint8_t pos, int32_t i, uint8_t byteSize) {
|
||||
for (uint8_t x = 0; x < byteSize; x++) {
|
||||
buffer[x + pos] = (byte)(i >> (x * 8));
|
||||
@ -200,27 +208,6 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
buffer[cursor++] = val2;
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
int32_t lat = value.latitude / 100;
|
||||
int32_t lon = value.longitude / 100;
|
||||
int32_t alt = value.altitude * 100;
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_GPS_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_GPS;
|
||||
buffer[cursor++] = lat >> 16;
|
||||
buffer[cursor++] = lat >> 8;
|
||||
buffer[cursor++] = lat;
|
||||
buffer[cursor++] = lon >> 16;
|
||||
buffer[cursor++] = lon >> 8;
|
||||
buffer[cursor++] = lon;
|
||||
buffer[cursor++] = alt >> 16;
|
||||
buffer[cursor++] = alt >> 8;
|
||||
buffer[cursor++] = alt;
|
||||
}
|
||||
#endif
|
||||
|
||||
void PayloadConvert::addConfig(configData_t value) {
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_ADR_CHANNEL;
|
||||
@ -246,6 +233,37 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
buffer[cursor++] = (uint16_t)val;
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
int32_t lat = value.latitude / 100;
|
||||
int32_t lon = value.longitude / 100;
|
||||
int32_t alt = value.altitude * 100;
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_GPS_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_GPS;
|
||||
buffer[cursor++] = lat >> 16;
|
||||
buffer[cursor++] = lat >> 8;
|
||||
buffer[cursor++] = lat;
|
||||
buffer[cursor++] = lon >> 16;
|
||||
buffer[cursor++] = lon >> 8;
|
||||
buffer[cursor++] = lon;
|
||||
buffer[cursor++] = alt >> 16;
|
||||
buffer[cursor++] = alt >> 8;
|
||||
buffer[cursor++] = alt;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BUTTON
|
||||
void PayloadConvert::addButton(uint8_t value) {
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_BUTTON_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_DIGITAL_INPUT;
|
||||
buffer[cursor++] = value;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "No valid payload converter defined"
|
||||
#endif
|
@ -7,6 +7,7 @@
|
||||
#define LPP_COUNT_WIFI_CHANNEL 21
|
||||
#define LPP_COUNT_BLE_CHANNEL 22
|
||||
#define LPP_BATT_CHANNEL 23
|
||||
#define LPP_BUTTON_CHANNEL 24
|
||||
#define LPP_ADR_CHANNEL 25
|
||||
#define LPP_TEMP_CHANNEL 26
|
||||
#endif
|
||||
@ -34,6 +35,10 @@ public:
|
||||
#ifdef HAS_GPS
|
||||
void addGPS(gpsStatus_t value);
|
||||
#endif
|
||||
#ifdef HAS_BUTTON
|
||||
void addButton(uint8_t value);
|
||||
#endif
|
||||
|
||||
|
||||
#if PAYLOAD_ENCODER == 1 // format plain
|
||||
|
||||
|
@ -24,10 +24,10 @@ void senddata(uint8_t port) {
|
||||
#endif
|
||||
|
||||
// clear counter if not in cumulative counter mode
|
||||
if ((port == PAYLOADPORT) && (cfg.countermode != 1)) {
|
||||
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
reset_salt(); // get new salt for salting hashes
|
||||
ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode);
|
||||
ESP_LOGI(TAG, "Counter cleared");
|
||||
}
|
||||
|
||||
} // senddata
|
Loading…
Reference in New Issue
Block a user