In India.
I make a Transmitter and Receiver device using Raspbery pi pico, GPS NEO-6M Module and LoRa SX1278 Module at Transmitter end and Raspberry pi pico, LoRa SX1278 Module at the receiver end. In this device i am sending my GPS Cordinate from Transmitter end and receive it at the receiver end.
Transmitter end code are:
#include <SPI.h>
#include <LoRa.h>
#include <TinyGPS++.h>
#define LORA_SCK 18
#define LORA_MISO 16
#define LORA_MOSI 19
#define LORA_CS 8
#define LORA_RST 9
#define LORA_DIO0 7
#define LED_PIN 25
#define BUZZER_PIN 17 // (Connect to GPIO 17 of Raspberry Pi Pico) Replace 17 with the GPIO pin number your buzzer is connected to
#define GPS_RX 1 // Connect GPS TX pin to Raspberry Pi Pico pin 1 (UART1_RX)
#define GPS_TX 0 // Connect GPS RX pin to Raspberry Pi Pico pin 0 (UART1_TX)
#define TRANSMISSION_INTERVAL 60 // Interval between transmissions in milliseconds (e.g., 1 seconds)
TinyGPSPlus gps;
void setup()
{
Serial.begin(115200);
Serial1.begin(9600); // Initialize hardware UART1 for GPS
LoRa.setPins(LORA_CS, LORA_RST, LORA_DIO0);
if (!LoRa.begin(433E6))
{
Serial.println("LoRa init failed. Check your connections.");
while (true);
}
Serial.println("LoRa init succeeded.");
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT); // Set the buzzer pin as output
}
void loop()
{
static unsigned long previousTransmission = 0;
while (Serial1.available() > 0)
{
if (gps.encode(Serial1.read()))
{
if (gps.location.isValid())
{
float latitude = gps.location.lat();
float longitude = gps.location.lng();
Serial.println("GPS Running...");
sendLocation(latitude, longitude);
digitalWrite(LED_PIN, HIGH); // Turn on LED
digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
delay(1000); // Indicate transmission
digitalWrite(LED_PIN, LOW); // Turn off LED
digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
delay(1000);
previousTransmission = millis(); // Update last transmission time
}
else
{
Serial.println("GPS NOT START");
delay(1000);
digitalWrite(LED_PIN, HIGH); // Turn on LED when GPS Not Start but Device Start
}
}
}
// Check if it's time to transmit again
if (millis() - previousTransmission >= TRANSMISSION_INTERVAL)
{
// Transmit periodic status message
//sendStatus("I'm alive!");
previousTransmission = millis(); // Update last transmission time
}
}
void sendLocation(float latitude, float longitude)
{
String message = String(latitude, 6) + "," + String(longitude, 6);
Serial.print("Sending GPS Signal: ");
Serial.println(message);
LoRa.beginPacket();
LoRa.print(message);
LoRa.endPacket();
}
void sendStatus(const char* statusMessage)
{
Serial.print("Sending status: ");
Serial.println(statusMessage);
LoRa.beginPacket();
LoRa.print(statusMessage);
LoRa.endPacket();
}
Receiver end code are:
#include <SPI.h>
#include <LoRa.h>
// Pin Definitions
const int LORA_SCK = 18;
const int LORA_MISO = 16;
const int LORA_MOSI = 19;
const int LORA_CS = 8;
const int LORA_RST = 9;
const int LORA_DIO0 = 7;
const int LED_PIN = 25;
const int BUZZER_PIN = 17;
void setupLoRa() {
Serial.begin(115200);
LoRa.setPins(LORA_CS, LORA_RST, LORA_DIO0);
if (!LoRa.begin(525E6)) {
Serial.println("LoRa init failed. Check your connections.");
while (true);
}
Serial.println("LoRa init succeeded.");
}
void setup() {
setupLoRa();
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void indicateTransmission() {
digitalWrite(LED_PIN, HIGH); // Turn on LED
digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
delay(1000); // Indicate transmission
digitalWrite(LED_PIN, LOW); // Turn off LED
digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
delay(1000);
}
void receiveAndIndicate() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.println("GPS Running...");
Serial.print("Received GPS Signal: ");
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
Serial.print(" with RSSI ");
Serial.println(LoRa.packetRssi());
indicateTransmission();
} else {
digitalWrite(LED_PIN, HIGH); // Turn on LED when GPS Not Start but Device Start
}
}
void loop() {
receiveAndIndicate();
}
I am using Transmitter and Receiver Device both but communication between them is not going to long range.
After that i ordered "DLOS8N - Outdoor LoRaWAN Gateway" to increase my communication range.
Now, tell me in brief with code to use my LoRaWAN Gateway as middle point which receive the GPS coordinate from my Transmitter device and then send it to my Receiver device.