// Only supports SX1276/SX1278 #include #include "LoRaBoards.h" #ifndef CONFIG_RADIO_FREQ #define CONFIG_RADIO_FREQ 868.0 #endif #ifndef CONFIG_RADIO_OUTPUT_POWER #define CONFIG_RADIO_OUTPUT_POWER 17 #endif #ifndef CONFIG_RADIO_BW #define CONFIG_RADIO_BW 125.0 #endif #if !defined(USING_SX1276) && !defined(USING_SX1278) #error "LoRa example is only allowed to run SX1276/78. For other RF models, please run examples/RadioLibExamples #endif int counter = 0; void setup() { setupBoards(); // When the power is turned on, a delay is required. delay(1500); #ifdef RADIO_TCXO_ENABLE pinMode(RADIO_TCXO_ENABLE, OUTPUT); digitalWrite(RADIO_TCXO_ENABLE, HIGH); #endif #ifdef RADIO_CTRL Serial.println("Turn off LAN,Trun on PA, Enter Tx mode."); /* * BPF LoRa LAN Control ,set Low turn off LAN , TX Mode * */ digitalWrite(RADIO_CTRL, LOW); #endif /*RADIO_CTRL*/ Serial.println("LoRa Sender"); LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN); if (!LoRa.begin(CONFIG_RADIO_FREQ * 1000000)) { Serial.println("Starting LoRa failed!"); while (1); } LoRa.setTxPower(CONFIG_RADIO_OUTPUT_POWER); LoRa.setSignalBandwidth(CONFIG_RADIO_BW * 1000); LoRa.setSpreadingFactor(10); LoRa.setPreambleLength(16); LoRa.setSyncWord(0xAB); LoRa.disableCrc(); LoRa.disableInvertIQ(); LoRa.setCodingRate4(7); } void loop() { Serial.print("Sending packet: "); Serial.println(counter); // send packet LoRa.beginPacket(); LoRa.print("hello "); LoRa.print(counter); LoRa.endPacket(); if (u8g2) { char buf[256]; u8g2->clearBuffer(); u8g2->drawStr(0, 12, "Transmitting: OK!"); snprintf(buf, sizeof(buf), "Sending: %d", counter); u8g2->drawStr(0, 30, buf); u8g2->sendBuffer(); } counter++; delay(5000); }