Advertisement
pleasedontcode

**LoRa Messaging** rev_14

Nov 29th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **LoRa Messaging**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-29 23:06:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* configure a lora gateway */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /********* User code review feedback **********
  25. #### Feedback 1 ####
  26. - send periodically a message to a specific receiver
  27. ********* User code review feedback **********/
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <SPI.h>
  33. #include <LoRa.h>   //https://github.com/sandeepmistry/arduino-LoRa
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38. void updateOutputs(void);
  39. void sendMessage(void); // New function prototype for sending messages
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t module_SX127x_DIO0_PIN_D3     = 3;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t module_SX127x_NRESET_PIN_D2       = 2;
  46.  
  47. /***** DEFINITION OF SPI PINS *****/
  48. const uint8_t module_SX127x_SPI_PIN_MOSI_D11        = 11;
  49. const uint8_t module_SX127x_SPI_PIN_MISO_D12        = 12;
  50. const uint8_t module_SX127x_SPI_PIN_SCLK_D13        = 13;
  51. const uint8_t module_SX127x_SPI_PIN_CS_D10      = 10;
  52.  
  53. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  54. /***** used to store raw data *****/
  55. bool    module_SX127x_NRESET_PIN_D2_rawData     = 0;
  56.  
  57. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  58. /***** used to store data after characteristic curve transformation *****/
  59. float   module_SX127x_NRESET_PIN_D2_phyData     = 0.0;
  60.  
  61. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  62.  
  63. void setup(void)
  64. {
  65.     // put your setup code here, to run once:
  66.  
  67.     pinMode(module_SX127x_DIO0_PIN_D3,  INPUT);
  68.     pinMode(module_SX127x_NRESET_PIN_D2,    OUTPUT);
  69.     pinMode(module_SX127x_SPI_PIN_CS_D10,   OUTPUT);
  70.    
  71.     // start the SPI library:
  72.     SPI.begin();
  73.  
  74.     // Initialize LoRa module
  75.     LoRa.setPins(module_SX127x_SPI_PIN_CS_D10, module_SX127x_NRESET_PIN_D2, module_SX127x_DIO0_PIN_D3); // Set CS, RESET, and DIO0 pins
  76.     if (!LoRa.begin(915E6)) { // Initialize LoRa at 915 MHz
  77.         while (1); // If failed, do nothing
  78.     }
  79. }
  80.  
  81. void loop(void)
  82. {
  83.     // put your main code here, to run repeatedly:
  84.  
  85.     updateOutputs(); // Refresh output data
  86.     sendMessage();    // Send message periodically
  87. }
  88.  
  89. void updateOutputs()
  90. {
  91.     digitalWrite(module_SX127x_NRESET_PIN_D2, module_SX127x_NRESET_PIN_D2_rawData);
  92. }
  93.  
  94. void sendMessage()
  95. {
  96.     LoRa.beginPacket(); // Start a new packet
  97.     LoRa.print("Hello, Receiver!"); // Message to send
  98.     LoRa.endPacket(); // Finish the packet and send it
  99. }
  100.  
  101. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement