diff --git a/.gitignore b/.gitignore index a535321a..030b6f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,8 @@ .vscode/c_cpp_properties.json .vscode/settings.json .vscode/launch.json -src/loraconf.h .vscode/*.db .vscode/.browse.c_cpp.db* .clang_complete .gcc-flags.json +src/loraconf.h diff --git a/README.md b/README.md index 4d42fa2e..8c6400aa 100644 --- a/README.md +++ b/README.md @@ -140,9 +140,8 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. byte 1-2: Battery or USB Voltage [mV], 0 if no battery probe byte 3-10: Uptime [seconds] - bytes 11-14: CPU temperature [°C] - bytes 15-18: Free RAM [bytes] - bytes 19-20: Last reset reasons core 0 / core 1 + byte 11: CPU temperature [°C] + bytes 12-15: Free RAM [bytes] **Port #3:** Device configuration query result diff --git a/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/radio.c b/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/radio.c index 780226c2..0fffaa4f 100644 --- a/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/radio.c +++ b/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/radio.c @@ -790,8 +790,12 @@ void radio_irq_handler (u1_t dio) { // now read the FIFO readBuf(RegFifo, LMIC.frame, LMIC.dataLen); // read rx quality parameters - LMIC.snr = readReg(LORARegPktSnrValue); // SNR [dB] * 4 - LMIC.rssi = readReg(LORARegPktRssiValue) - 125 + 64; // RSSI [dBm] (-196...+63) + //LMIC.snr = readReg(LORARegPktSnrValue); // SNR [dB] * 4 + LMIC.snr = readReg(LORARegPktSnrValue) / 4; + //LMIC.rssi = readReg(LORARegPktRssiValue) - 125 + 64; // RSSI [dBm] (-196...+63) + LMIC.rssi = readReg(LORARegPktRssiValue) - 157; // RFI_HF for 868 and 915MHZ band + if (LMIC.snr < 0) + LMIC.rssi += LMIC.snr; } else if( flags & IRQ_LORA_RXTOUT_MASK ) { // indicate timeout LMIC.dataLen = 0; diff --git a/platformio.ini b/platformio.ini index 65eb1107..d6e092c0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -79,7 +79,7 @@ board_build.partitions = min_spiffs.csv lib_deps_all = ArduinoJson lib_deps_display = - U8g2@>=2.23.12 + U8g2@>=2.23.16 lib_deps_rgbled = SmartLeds@>=1.1.3 lib_deps_gps = diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 32d6dc9f..9aaf1cfc 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -18,10 +18,9 @@ function Decoder(bytes, port) { if (port === 2) { // device status data - return decode(bytes, [uint16, uptime, temperature, uint32, uint8, uint8], ['voltage', 'uptime', 'cputemp', 'memory', 'reset', 'reset']); + return decode(bytes, [uint16, uptime, uint8, uint32], ['voltage', 'uptime', 'cputemp', 'memory']); } - if (port === 3) { // device config data return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags']); diff --git a/src/TTN/plain_decoder.js b/src/TTN/plain_decoder.js index 32850474..ba674d35 100644 --- a/src/TTN/plain_decoder.js +++ b/src/TTN/plain_decoder.js @@ -13,7 +13,7 @@ function Decoder(bytes, port) { if (bytes.length > 4) { decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.longitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); - decoded.sats = (bytes[i++]); + decoded.sats = bytes[i++]; decoded.hdop = (bytes[i++] << 8) | (bytes[i++]); decoded.altitude = (bytes[i++] << 8) | (bytes[i++]); } @@ -24,18 +24,18 @@ function Decoder(bytes, port) { decoded.battery = ((bytes[i++] << 8) | bytes[i++]); decoded.uptime = ((bytes[i++] << 56) | (bytes[i++] << 48) | (bytes[i++] << 40) | (bytes[i++] << 32) | (bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); - decoded.temp = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); + decoded.temp = bytes[i++]; } if (port === 5) { var i = 0; - decoded.button = (bytes[i++]); + decoded.button = bytes[i++]; } if (port === 6) { var i = 0; - decoded.rssi = (bytes[i++]); - decoded.beacon = (bytes[i++]); + decoded.rssi = bytes[i++]; + decoded.beacon = bytes[i++]; } return decoded; diff --git a/src/hal/heltec.h b/src/hal/heltec.h index a860df50..2671fac8 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -5,7 +5,6 @@ #define CFG_sx1276_radio 1 #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board -//#define DISPLAY_FLIP 1 // uncomment this for rotated display #define HAS_LED GPIO_NUM_25 // white LED on board #define HAS_BUTTON GPIO_NUM_0 // button "PROG" on board diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h index 06cda59f..6d59065d 100644 --- a/src/hal/ttgov21.h +++ b/src/hal/ttgov21.h @@ -1,18 +1,52 @@ /* Hardware related definitions for TTGO V2.1 Board / ATTENTION: check your board version! / Different versions are on the market which need different settings in this file: -/ - without label -> "old" -/ - labelled v1.5 on pcb -> "old" -/ - labelled v1.6 on pcb -> "new" +/ - without label -> use settings (2) +/ - labeled V1.5 on pcb -> use settings (2) +/ - labeled V1.6 on pcb -> use settings (1) +/ Choose the right configuration below */ +/* +// (1) settings for board labeled "T3_V1.6" on pcb + #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // HPD13A LoRa SoC +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +#define HAS_LED GPIO_NUM_25 // green on board LED +#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 +#define BATT_FACTOR 2 // voltage divider 100k/100k on board + +// re-define pin definitions of pins_arduino.h +#define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input +#define PIN_SPI_MOSI GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input +#define PIN_SPI_MISO GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output +#define PIN_SPI_SCK GPIO_NUM_5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input + +// non arduino pin definitions +#define RST GPIO_NUM_23 // ESP32 GPIO23 <-> HPD13A RESET +#define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 +#define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 +#define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 + +// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display +#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN +#define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 +#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 + +*/ + +// (2) settings for boards without label on pcb, or labeled v1.5 on pcb + +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define CFG_sx1276_radio 1 // HPD13A LoRa SoC +#define HAS_LED NOT_A_PIN // no usable LED on board + #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C #define DISPLAY_FLIP 1 // rotated display -#define HAS_LED GPIO_NUM_23 // green on board LED (new board ONLY) #define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 #define BATT_FACTOR 2 // voltage divider 100k/100k on board @@ -24,8 +58,7 @@ // non arduino pin definitions #define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN (old board) -//#define RST GPIO_NUM_12 // (old board v1.5) -//#define RST GPIO_NUM_19 //(new board) +//#define RST GPIO_NUM_12 // (boards labeled v1.5) #define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 #define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 #define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 @@ -33,4 +66,4 @@ // Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display #define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN #define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 -#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 \ No newline at end of file +#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 diff --git a/src/payload.cpp b/src/payload.cpp index 958d3fb3..61514f94 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -52,9 +52,9 @@ void PayloadConvert::addConfig(configData_t value) { cursor += 10; } -void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, - uint32_t mem, uint8_t reset1, uint8_t reset2) { - uint32_t temp = (uint32_t)cputemp; +void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, + float cputemp, uint32_t mem) { + buffer[cursor++] = highByte(voltage); buffer[cursor++] = lowByte(voltage); buffer[cursor++] = (byte)((uptime & 0xFF00000000000000) >> 56); @@ -65,10 +65,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, buffer[cursor++] = (byte)((uptime & 0x0000000000FF0000) >> 16); buffer[cursor++] = (byte)((uptime & 0x000000000000FF00) >> 8); buffer[cursor++] = (byte)((uptime & 0x00000000000000FF)); - buffer[cursor++] = (byte)((temp & 0xFF000000) >> 24); - buffer[cursor++] = (byte)((temp & 0x00FF0000) >> 16); - buffer[cursor++] = (byte)((temp & 0x0000FF00) >> 8); - buffer[cursor++] = (byte)((temp & 0x000000FF)); + buffer[cursor++] = (byte)(cputemp); buffer[cursor++] = (byte)((mem & 0xFF000000) >> 24); buffer[cursor++] = (byte)((mem & 0x00FF0000) >> 16); buffer[cursor++] = (byte)((mem & 0x0000FF00) >> 8); @@ -133,7 +130,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem, uint8_t reset1, uint8_t reset2) { writeUint16(voltage); writeUptime(uptime); - writeTemperature(cputemp); + writeUint8((byte)cputemp); writeUint32(mem); writeUint8(reset1); writeUint8(reset2); diff --git a/src/rcommand.cpp b/src/rcommand.cpp index a052c48e..2bae172a 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -273,10 +273,13 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) { TAG, "Remote command x%02X called with missing parameter(s), skipped", table[i].opcode); - break; // exit table lookup loop, command was found - } // command validation - } // command table lookup loop - + break; // command found -> exit table lookup loop + } // end of command validation + } // end of command table lookup loop + if (i < 0) { // command not found -> exit parser + ESP_LOGI(TAG, "Unknown remote command x%02X, ignored", cmd[cursor]); + break; + } } // command parsing loop if (storeflag)