CCCPaste

LoRa Messaging rev_15

/********* 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 Messaging
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-11-29 23:07:10

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* configure a lora gateway */
/****** END SYSTEM REQUIREMENTS *****/


/********* User code review feedback **********
#### Feedback 1 ####
- send periodically a message to a specific receiver
********* User code review feedback **********/

/* START CODE */

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

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void sendMessage(void); // New function prototype for sending messages

/***** 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*****/

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 module
	LoRa.setPins(module_SX127x_SPI_PIN_CS_D10, module_SX127x_NRESET_PIN_D2, module_SX127x_DIO0_PIN_D3); // Set CS, RESET, and DIO0 pins
	if (!LoRa.begin(915E6)) { // Initialize LoRa at 915 MHz
		while (1); // If failed, do nothing
	}
}

void loop(void)
{
	// put your main code here, to run repeatedly:

	updateOutputs(); // Refresh output data
	sendMessage();    // Send message periodically
}

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

void sendMessage()
{
	LoRa.beginPacket(); // Start a new packet
	LoRa.print("Hello, Receiver!"); // Message to send
	LoRa.endPacket(); // Finish the packet and send it
}

/* END CODE */