button read and send

This commit is contained in:
Klaus K Wilting 2018-07-21 18:25:03 +02:00
parent baa93ad916
commit eb37a79d46
7 changed files with 85 additions and 57 deletions

View File

@ -167,6 +167,10 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
bytes 10-11: HDOP bytes 10-11: HDOP
bytes 12-13: Altitude [meter] bytes 12-13: Altitude [meter]
**Port #5:** Button pressed signal
byte 1: static value 0x01
[**plain_decoder.js**](src/TTN/plain_decoder.js) [**plain_decoder.js**](src/TTN/plain_decoder.js)

View File

@ -1,4 +1,4 @@
/* switches wifi antenna, if board has switch internal / external antenna */ /* switches wifi antenna, if board has switch internal / external antenna */
#ifdef HAS_ANTENNA_SWITCH #ifdef HAS_ANTENNA_SWITCH

View File

@ -139,9 +139,9 @@ void readButton() {
ButtonPressedIRQ = 0; ButtonPressedIRQ = 0;
portEXIT_CRITICAL(&timerMux); portEXIT_CRITICAL(&timerMux);
ESP_LOGI(TAG, "Button pressed"); ESP_LOGI(TAG, "Button pressed");
ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); payload.reset();
eraseConfig(); payload.addButton(0x01);
esp_restart(); senddata(BUTTONPORT);
} }
} }
#endif #endif
@ -211,7 +211,7 @@ void sendPayload() {
} }
#endif #endif
senddata(PAYLOADPORT); senddata(COUNTERPORT);
} }
} // sendPayload() } // sendPayload()
@ -442,7 +442,7 @@ void loop() {
"Memory full, counter cleared (heap low water mark = %d Bytes / " "Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)", "free heap = %d bytes)",
esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); 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_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes reset_salt(); // get new salt for salting hashes
} }

View File

@ -47,11 +47,12 @@
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy #define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
// Ports on which the device sends and listenes on LoRaWAN and SPI // 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 RCMDPORT 2 // Port on which device listenes for remote commands
#define STATUSPORT 2 // Port on which device sends remote command results #define STATUSPORT 2 // Port on which device sends remote command results
#define CONFIGPORT 3 // Port on which device sends gps query results #define CONFIGPORT 3 // Port on which device sends gps query results
#define GPSPORT 4 // 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 #define CAYENNEPORT 2 // Port for Cayenne LPP 2.0 packet sensor encoding
// Default RGB LED luminosity (in %) // Default RGB LED luminosity (in %)

View File

@ -26,24 +26,6 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = 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) { void PayloadConvert::addConfig(configData_t value) {
buffer[cursor++] = value.lorasf; buffer[cursor++] = value.lorasf;
buffer[cursor++] = value.txpower; buffer[cursor++] = value.txpower;
@ -83,6 +65,28 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
buffer[cursor++] = (uint32_t)cputemp; 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 ---------- */ /* ---------------- packed format with LoRa serialization Encoder ---------- */
// derived from // derived from
// https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp // 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); 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) { void PayloadConvert::addConfig(configData_t value) {
writeUint8(value.lorasf); writeUint8(value.lorasf);
writeUint8(value.txpower); writeUint8(value.txpower);
@ -124,6 +119,19 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
writeTemperature(cputemp); 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) { void PayloadConvert::intToBytes(uint8_t pos, int32_t i, uint8_t byteSize) {
for (uint8_t x = 0; x < byteSize; x++) { for (uint8_t x = 0; x < byteSize; x++) {
buffer[x + pos] = (byte)(i >> (x * 8)); buffer[x + pos] = (byte)(i >> (x * 8));
@ -200,27 +208,6 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = val2; 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) { void PayloadConvert::addConfig(configData_t value) {
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_ADR_CHANNEL; buffer[cursor++] = LPP_ADR_CHANNEL;
@ -246,6 +233,37 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
buffer[cursor++] = (uint16_t)val; 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 #else
#error "No valid payload converter defined" #error "No valid payload converter defined"
#endif #endif

View File

@ -7,6 +7,7 @@
#define LPP_COUNT_WIFI_CHANNEL 21 #define LPP_COUNT_WIFI_CHANNEL 21
#define LPP_COUNT_BLE_CHANNEL 22 #define LPP_COUNT_BLE_CHANNEL 22
#define LPP_BATT_CHANNEL 23 #define LPP_BATT_CHANNEL 23
#define LPP_BUTTON_CHANNEL 24
#define LPP_ADR_CHANNEL 25 #define LPP_ADR_CHANNEL 25
#define LPP_TEMP_CHANNEL 26 #define LPP_TEMP_CHANNEL 26
#endif #endif
@ -34,6 +35,10 @@ public:
#ifdef HAS_GPS #ifdef HAS_GPS
void addGPS(gpsStatus_t value); void addGPS(gpsStatus_t value);
#endif #endif
#ifdef HAS_BUTTON
void addButton(uint8_t value);
#endif
#if PAYLOAD_ENCODER == 1 // format plain #if PAYLOAD_ENCODER == 1 // format plain

View File

@ -24,10 +24,10 @@ void senddata(uint8_t port) {
#endif #endif
// clear counter if not in cumulative counter mode // 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_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes reset_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode); ESP_LOGI(TAG, "Counter cleared");
} }
} // senddata } // senddata