diff --git a/examples/receive_fsk/main/main.c b/examples/receive_fsk/main/main.c index 4193d60..244a1f9 100644 --- a/examples/receive_fsk/main/main.c +++ b/examples/receive_fsk/main/main.c @@ -27,14 +27,16 @@ TaskHandle_t handle_interrupt; int total_packets_received = 0; static const char *TAG = "sx127x"; -void IRAM_ATTR handle_interrupt_fromisr(void *arg) { +void IRAM_ATTR + +handle_interrupt_fromisr(void *arg) { xTaskResumeFromISR(handle_interrupt); } void handle_interrupt_task(void *arg) { while (1) { vTaskSuspend(NULL); - sx127x_handle_interrupt((sx127x *)arg); + sx127x_handle_interrupt((sx127x *) arg); } } @@ -50,7 +52,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) { int32_t frequency_error; ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error)); - ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + int16_t rssi; + int code = sx127x_rx_get_packet_rssi(device, &rssi); + if (code == SX127X_ERR_NOT_FOUND) { + ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + } else { + ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error); + } total_packets_received++; } @@ -59,7 +67,7 @@ void setup_gpio_interrupts(gpio_num_t gpio, sx127x *device) { gpio_pulldown_en(gpio); gpio_pullup_dis(gpio); gpio_set_intr_type(gpio, GPIO_INTR_POSEDGE); - gpio_isr_handler_add(gpio, handle_interrupt_fromisr, (void *)device); + gpio_isr_handler_add(gpio, handle_interrupt_fromisr, (void *) device); } void app_main() { @@ -89,7 +97,7 @@ void app_main() { .address_bits = 8, .dummy_bits = 0, .mode = 0}; - spi_device_handle_t spi_device; + spi_device_handle_t spi_device; ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device)); ESP_ERROR_CHECK(sx127x_create(spi_device, &device)); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device)); @@ -110,6 +118,7 @@ void app_main() { ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device)); ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device)); ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device)); + ESP_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device)); sx127x_rx_set_callback(rx_callback, device); @@ -121,9 +130,9 @@ void app_main() { } gpio_install_isr_service(0); - setup_gpio_interrupts((gpio_num_t)DIO0, device); - setup_gpio_interrupts((gpio_num_t)DIO1, device); - setup_gpio_interrupts((gpio_num_t)DIO2, device); + setup_gpio_interrupts((gpio_num_t) DIO0, device); + setup_gpio_interrupts((gpio_num_t) DIO1, device); + setup_gpio_interrupts((gpio_num_t) DIO2, device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device)); } diff --git a/examples/receive_fsk_beacon/main/main.c b/examples/receive_fsk_beacon/main/main.c index a0329bd..ba1bbc2 100644 --- a/examples/receive_fsk_beacon/main/main.c +++ b/examples/receive_fsk_beacon/main/main.c @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) { int32_t frequency_error; ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error)); - ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + int16_t rssi; + int code = sx127x_rx_get_packet_rssi(device, &rssi); + if (code == SX127X_ERR_NOT_FOUND) { + ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + } else { + ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error); + } total_packets_received++; } diff --git a/examples/receive_fsk_filtered/main/main.c b/examples/receive_fsk_filtered/main/main.c index a9c7603..b791832 100644 --- a/examples/receive_fsk_filtered/main/main.c +++ b/examples/receive_fsk_filtered/main/main.c @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) { int32_t frequency_error; ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error)); - ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + int16_t rssi; + int code = sx127x_rx_get_packet_rssi(device, &rssi); + if (code == SX127X_ERR_NOT_FOUND) { + ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + } else { + ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error); + } total_packets_received++; } diff --git a/examples/receive_fsk_fixed/main/main.c b/examples/receive_fsk_fixed/main/main.c index a276aeb..f620e92 100644 --- a/examples/receive_fsk_fixed/main/main.c +++ b/examples/receive_fsk_fixed/main/main.c @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) { int32_t frequency_error; ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error)); - ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + int16_t rssi; + int code = sx127x_rx_get_packet_rssi(device, &rssi); + if (code == SX127X_ERR_NOT_FOUND) { + ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + } else { + ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error); + } total_packets_received++; } diff --git a/examples/receive_fsk_raspberrypi/main.c b/examples/receive_fsk_raspberrypi/main.c index c6d03d2..0f7a54d 100644 --- a/examples/receive_fsk_raspberrypi/main.c +++ b/examples/receive_fsk_raspberrypi/main.c @@ -18,6 +18,7 @@ #define GPIO_DIO1_PIN 13 #define GPIO_DIO2_PIN 19 #define GPIO_DIO3_PIN 26 +#define GPIO_DIO4_PIN 5 #define GPIO_DIO0_PIN 27 #define GPIO_RESET_PIN 6 #define GPIO_POLL_TIMEOUT (-1) @@ -50,11 +51,15 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) { } payload[data_length * 2] = '\0'; - int16_t rssi; - LINUX_NO_CODE_ERROR_CHECK(sx127x_rx_get_packet_rssi(device, &rssi)); int32_t frequency_error; LINUX_NO_CODE_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error)); - fprintf(stdout, "received: %d %s rssi: %d freq_error: %" PRId32 "\n", data_length, payload, rssi, frequency_error); + int16_t rssi; + int code = sx127x_rx_get_packet_rssi(device, &rssi); + if (code == SX127X_ERR_NOT_FOUND) { + fprintf(stdout, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error); + } else { + fprintf(stdout, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error); + } } int msleep(long msec) { @@ -120,9 +125,9 @@ int setup_and_wait_for_interrupt(sx127x *device) { perror("unable to open device"); return EXIT_FAILURE; } - uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN}; + uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN, GPIO_DIO4_PIN}; int gpios_length = sizeof(gpios); - struct pollfd pfd[4]; + struct pollfd pfd[5]; for (int i = 0; i < gpios_length; i++) { struct gpioevent_request rq; rq.lineoffset = gpios[i]; @@ -200,6 +205,7 @@ int main() { LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device)); + LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device)); sx127x_rx_set_callback(rx_callback, device); LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device)); diff --git a/examples/receive_ook/main/main.c b/examples/receive_ook/main/main.c index 46a59a6..0ea18a8 100644 --- a/examples/receive_ook/main/main.c +++ b/examples/receive_ook/main/main.c @@ -15,12 +15,12 @@ #define RST 23 #define DIO0 26 // older versions of TTGO require manual wiring of pins below -//#define DIO1 33 -//#define DIO2 32 +#define DIO1 33 +#define DIO2 32 // Heltec lora32 v2 -#define DIO1 35 -#define DIO2 34 +//#define DIO1 35 +//#define DIO2 34 sx127x *device = NULL; TaskHandle_t handle_interrupt;