CCCPaste

**LoRa Setup** rev_16

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: **LoRa Setup**
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-11-29 23:08:15

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* configure a lora gateway */
/****** SYSTEM REQUIREMENT 2 *****/
	/* send periodically a message to receiver. */
/****** END SYSTEM REQUIREMENTS *****/

/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 	//https://github.com/sandeepmistry/arduino-LoRa

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs();
void sendLoRaMessage(const char* message);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t module_SX127x_DIO0_PIN_D3		= 3;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t module_SX127x_NRESET_PIN_D2		= 2;

/***** DEFINITION OF SPI PINS *****/
const uint8_t module_SX127x_SPI_PIN_MOSI_D11		= 11;
const uint8_t module_SX127x_SPI_PIN_MISO_D12		= 12;
const uint8_t module_SX127x_SPI_PIN_SCLK_D13		= 13;
const uint8_t module_SX127x_SPI_PIN_CS_D10		= 10;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool	module_SX127x_NRESET_PIN_D2_rawData		= 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float	module_SX127x_NRESET_PIN_D2_phyData		= 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/

// Instantiate LoRa object
LoRaClass LoRa;

void setup(void)
{
	// put your setup code here, to run once:

	pinMode(module_SX127x_DIO0_PIN_D3,	INPUT);
	pinMode(module_SX127x_NRESET_PIN_D2,	 OUTPUT);
	pinMode(module_SX127x_SPI_PIN_CS_D10,	 OUTPUT);
	
	// start the SPI library:
	SPI.begin();

	// Initialize LoRa
	LoRa.setPins(module_SX127x_SPI_PIN_CS_D10, module_SX127x_NRESET_PIN_D2, module_SX127x_DIO0_PIN_D3);
	if (!LoRa.begin(915E6)) { // Set frequency to 915 MHz
		while (1); // if failed, do nothing
	}
}

void loop(void)
{
	// put your main code here, to run repeatedly:
	updateOutputs(); // Refresh output data

	// Send a message every 5 seconds
	sendLoRaMessage("Hello, LoRa!");
	delay(5000);
}

void updateOutputs()
{
	digitalWrite(module_SX127x_NRESET_PIN_D2, module_SX127x_NRESET_PIN_D2_rawData);
}

void sendLoRaMessage(const char* message)
{
	LoRa.beginPacket();
	LoRa.print(message);
	LoRa.endPacket();
}

/* END CODE */