This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
esp32-espidf-lora-quickstart [2026/08/24 03:32] sausage created |
esp32-espidf-lora-quickstart [2026/09/28 01:43] (current) sausage [Creating and configuring the project] |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| {{ :lora:rfm95-lora.jpg?direct&400|}} | {{ :lora:rfm95-lora.jpg?direct&400|}} | ||
| - | If you need to bang together a quick LoRa-based project on an ESP32 using esp-idf (not Arduino) so you get going in a hurry, follow along here. | + | If you need to bang together a quick LoRa-based project on an ESP32 using esp-idf (not Arduino) so you can get going in a hurry, follow along here. |
| Parts needed: | Parts needed: | ||
| Line 10: | Line 10: | ||
| * Breadboard and wires | * Breadboard and wires | ||
| - | The focus on this quick start is to aim for 915MHz. Our setup will be configured to pull Meshcore packets out of air configured for the Australia NSW Regional settings. But you can easily change for your region. | + | The focus on this quick start is to aim for 915MHz. Our setup will be configured to pull Meshcore packets out of the air configured for the Australian NSW/ACT Regional settings. But you can easily change this for your region. |
| ===== LoRa 915mhz board pinouts ===== | ===== LoRa 915mhz board pinouts ===== | ||
| Line 24: | Line 24: | ||
| 1. Open ESP-IDF 5.3.2 PowerShell | 1. Open ESP-IDF 5.3.2 PowerShell | ||
| Create a blank project with: | Create a blank project with: | ||
| - | idf.py create-project lorawan-sensor | + | idf.py create-project lora-project |
| If you're using an esp32 set it here. Ensure you set the right esp32 hardware, eg: esp32, esp32s2, etc | If you're using an esp32 set it here. Ensure you set the right esp32 hardware, eg: esp32, esp32s2, etc | ||
| Line 75: | Line 75: | ||
| Sniff the air for lora packets of any type. | Sniff the air for lora packets of any type. | ||
| Configs below for MESHCORE MID packets | Configs below for MESHCORE MID packets | ||
| - | and lorawan gateway packets (not found any yet) | + | or one band of LoRaWAN gateway packets |
| */ | */ | ||
| Line 93: | Line 93: | ||
| struct loraParams { | struct loraParams { | ||
| - | double frequency; | + | double frequency; |
| int cr; | int cr; | ||
| int bw; | int bw; | ||
| Line 151: | Line 151: | ||
| { | { | ||
| gpio_set_direction(BUILT_IN_LED, GPIO_MODE_OUTPUT); | gpio_set_direction(BUILT_IN_LED, GPIO_MODE_OUTPUT); | ||
| - | | + | |
| - | // Initialize LoRa | + | // Initialize LoRa |
| - | int initCode = lora_init(); | + | int initCode = lora_init(); |
| - | if (initCode == 0) { | + | if (initCode == 0) { |
| - | ESP_LOGE(pcTaskGetName(NULL), "LoRa module not found."); | + | ESP_LOGE(pcTaskGetName(NULL), "LoRa module not found."); |
| - | //don't proceed | + | //don't proceed |
| - | while(1) { | + | while(1) { |
| - | vTaskDelay(1); | + | vTaskDelay(1); |
| - | } | + | } |
| - | } else { | + | } else { |
| - | ESP_LOGI(pcTaskGetName(NULL), "LoRa module found. Return code: %d", initCode); | + | ESP_LOGI(pcTaskGetName(NULL), "LoRa module found. Return code: %d", initCode); |
| - | } | + | } |
| struct loraParams MESHCORE_MID = { 915075, 1, 7, 9, 16 }; | struct loraParams MESHCORE_MID = { 915075, 1, 7, 9, 16 }; | ||
| Line 168: | Line 168: | ||
| struct loraParams CURRENT = MESHCORE_MID; | struct loraParams CURRENT = MESHCORE_MID; | ||
| - | lora_set_frequency(CURRENT.frequency); | + | lora_set_frequency(CURRENT.frequency); |
| ESP_LOGI(pcTaskGetName(NULL), "Frequency is %.3f MHz", CURRENT.frequency/1000); | ESP_LOGI(pcTaskGetName(NULL), "Frequency is %.3f MHz", CURRENT.frequency/1000); | ||
| | | ||
| - | lora_enable_crc(); | + | lora_enable_crc(); |
| lora_set_coding_rate(CURRENT.cr); | lora_set_coding_rate(CURRENT.cr); | ||
| - | ESP_LOGI(pcTaskGetName(NULL), "coding_rate=%d", CURRENT.cr); | + | ESP_LOGI(pcTaskGetName(NULL), "coding_rate=%d", CURRENT.cr); |
| - | lora_set_bandwidth(CURRENT.bw); | + | lora_set_bandwidth(CURRENT.bw); |
| - | ESP_LOGI(pcTaskGetName(NULL), "bandwidth=%d", CURRENT.bw); | + | ESP_LOGI(pcTaskGetName(NULL), "bandwidth=%d", CURRENT.bw); |
| - | lora_set_spreading_factor(CURRENT.sf); | + | lora_set_spreading_factor(CURRENT.sf); |
| - | ESP_LOGI(pcTaskGetName(NULL), "spreading_factor=%d", CURRENT.sf); | + | ESP_LOGI(pcTaskGetName(NULL), "spreading_factor=%d", CURRENT.sf); |
| - | lora_set_preamble_length(CURRENT.preamble); | + | lora_set_preamble_length(CURRENT.preamble); |
| - | ESP_LOGI(pcTaskGetName(NULL), "preamble: %d", CURRENT.preamble); | + | ESP_LOGI(pcTaskGetName(NULL), "preamble: %d", CURRENT.preamble); |
| xTaskCreate(&taskScan, "RX", 1024*3, NULL, 5, NULL); | xTaskCreate(&taskScan, "RX", 1024*3, NULL, 5, NULL); | ||
| Line 215: | Line 215: | ||
| It shouldn't take too long to have the LED light up indicating that something is found. If the LED goes out and lights again, it has found another packet. If you're connected to a PC and are using something like Putty to serial to COM5 (in this case), you can watch the logs and see the content of packet. | It shouldn't take too long to have the LED light up indicating that something is found. If the LED goes out and lights again, it has found another packet. If you're connected to a PC and are using something like Putty to serial to COM5 (in this case), you can watch the logs and see the content of packet. | ||
| - | It's fun to copy the bytes and paste then into a LoRa packet decoder. | + | It's fun to copy the bytes and paste them into a [[https://lora-packet.vercel.app|LoRa packet decoder]] or specific [[https://jkingsman.github.io/meshcore-packet-knife|Meshcore packet decoder]]. |
| ===== Troubleshooting LoRa ===== | ===== Troubleshooting LoRa ===== | ||
| Line 221: | Line 221: | ||
| So what happens if you get nothing, no light, nothing in the logs. A few things to check, many are elemental but please recheck them. Basics first!: | So what happens if you get nothing, no light, nothing in the logs. A few things to check, many are elemental but please recheck them. Basics first!: | ||
| - | * Check the frequency. Close is not good enough. | + | * Check the frequency, this is the major cause. Close is not good enough. If you get nothing... ever... look to this first. Even if you set the input correctly, make sure your library set it right. Check your number format. If the library doesn't support something like ''lora_get_frequency'', check registers 0x06 = E4, 0x07 = C4 and 0x08 = CC which is 915.075. |
| - | * Check the SF, BW, CR and Preamble. Check the values are correct as per the libary enums: https://github.com/nopnop2002/esp-idf-sx127x#advanced-settings | + | * Check the SF, BW, CR and Preamble. Getting these four wrong is the next most likely. Preamble never gets much of a mention but for picking up Meshcore packets, it's important. Check the values are correct as per the library enums: https://github.com/nopnop2002/esp-idf-sx127x#advanced-settings |
| - | * You can use the init message to test if the LoRa module is wired up correctly. Please note that if MOSI, MISO, NSS or SCK are wrong, you will get a failure. But if power/ground are missing, the module will still initialize. | + | * You can use the init message to test if the LoRa module is wired up correctly. Please note that if MOSI, MISO, NSS or SCK are wrong, you will get a failure. But if power/ground are missing, the HopeRF module will still initialize over SPI. |
| - | * Try it outside, though unlikely. LoRa has great penetration through walls and over great distances. | + | * Try it outside, though unlikely to help. LoRa has great penetration through walls and over great distances. |
| - | * Is the little antenna connected? Check it on a VNA. As long as it's around the target frequency of 915 Mhz you're good. You can get something from antennas being reasonbly off so this is less likely a cause. | + | * Is the little antenna connected? Also check it on a VNA. As long as it's around the target frequency of 915 Mhz you're good. You should still be able to pick up a lot even if your antenna is a bit out of tune. So this is less likely a cause. |
| + | * Leave it running for a good 24 hours. | ||