Hi everyone
I have a project that i call "GPS Tracker". In my project, i'm want to tracking vessel using GPS UBLOX neo, LoRa RFM95 and microcontroller arduino uno. For data transmission, i used multi-hop transmission using LoRa that has a purpose for increase data transmission distance.
I'm used 3 node which one for source node, one for intermediate node and last for destination node.I already made code for all three, but when I did a trial by entering the code into the device, it didn't produce any results on the serial monitor on Arduino
I'm pretty sure about the code that I made because there aren't any errors that come out when I compile it but to be sure I want to ask for suggestions or improvements from all of you for the project that I made
This my code for source node
#include <RHRouter.h>
#include <RH_RF95.h>
#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define RADIO_FREQUENCY 915.0
#define RADIO_TX_POWER 6
#define RADIO_SPREADFACTOR 8
#define CLIENT_ADDRESS 1
#define SERVER1_ADDRESS 2
#define SERVER2_ADDRESS 3
#define SERVER3_ADDRESS 4
RH_RF95 driver;
//RH_RF95 (CLIENT_ADDRESS);
// Class to manage message delivery and receipt, using the driver declared above
RHRouter manager(driver, CLIENT_ADDRESS);
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
// Setup ISM frequency
driver.setFrequency(RADIO_FREQUENCY);
// Setup Power,dBm
driver.setTxPower(RADIO_TX_POWER);
// Manually define the routes for this network
manager.addRouteTo(SERVER1_ADDRESS, SERVER1_ADDRESS);
manager.addRouteTo(SERVER2_ADDRESS, SERVER1_ADDRESS);
// manager.addRouteTo(SERVER3_ADDRESS, SERVER3_ADDRESS);
}
//uint8_t data[] = "Hallo ini dari kapal 1 !";
// Dont put this on the stack:
/*struct{
double lat;
double lng;
} data;*/
//uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
void loop()
{
if (driver.available())
{
while(ss.available() > 0)
if (gps.encode(ss.read()))
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print("Latitude= ");
double lat=gps.location.lat();
Serial.print(lat, 6);
Serial.print(" Longitude= ");
double lng=gps.location.lat();
Serial.print(lng, 6);
uint8_t data[2*sizeof(double)];
data[0]=lat;
data[sizeof(double)]=lng;
Serial.println("Sending to rf22_router_server3");
if (manager.sendtoWait((uint8_t)data, sizeof(data), SERVER2_ADDRESS) != RH_ROUTER_ERROR_NONE)
Serial.println("sendtoWait failed");
else
{
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 3000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is rf22_router_server1, rf22_router_server2 and rf22_router_server3 running?");
}
}
}
else
{
Serial.print(F("INVALID"));
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
}
and this is for intermediate node
#include <RHRouter.h>
#include <RH_RF95.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER1_ADDRESS 2
#define SERVER2_ADDRESS 3
#define SERVER3_ADDRESS 4
#define RADIO_FREQUENCY 915.0
#define RADIO_TX_POWER 6
#define RADIO_SPREADFACTOR 8
// Singleton instance of the radio
RH_RF95 driver;
// Class to manage message delivery and receipt, using the driver declared above
RHRouter manager(driver, SERVER1_ADDRESS);
void setup()
{
Serial.begin(9600);
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
// Setup ISM frequency
driver.setFrequency(RADIO_FREQUENCY);
// Setup Power,dBm
driver.setTxPower(RADIO_TX_POWER);
// Manually define the routes for this network
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
// manager.addRouteTo(SERVER2_ADDRESS, SERVER1_ADDRESS);
}
void loop()
{
if (driver.available())
{
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(driver.lastRssi(), DEC);
// Send a reply back to the originator client
uint8_t data[] = "And hello back to you from server1";
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
Serial.println("sendtoWait failed");
}
}
}
this's for destination node
#include <RHRouter.h>
#include <RH_RF95.h>
#include <SPI.h>
// In this small artifical network of 4 nodes,
// messages are routed via intermediate nodes to their destination
// node. All nodes can act as routers
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
#define CLIENT_ADDRESS 1
#define SERVER1_ADDRESS 2
#define SERVER2_ADDRESS 3
#define SERVER3_ADDRESS 4
#define RADIO_FREQUENCY 915.0
#define RADIO_TX_POWER 6
#define RADIO_SPREADFACTOR 8
// Singleton instance of the radio
RH_RF95 driver;
// Class to manage message delivery and receipt, using the driver declared above
RHRouter manager(driver, SERVER2_ADDRESS);
void setup()
{
Serial.begin(9600);
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
// Setup ISM frequency
driver.setFrequency(RADIO_FREQUENCY);
// Setup Power,dBm
driver.setTxPower(RADIO_TX_POWER);
// Manually define the routes for this network
manager.addRouteTo(CLIENT_ADDRESS, SERVER1_ADDRESS);
manager.addRouteTo(SERVER1_ADDRESS, SERVER1_ADDRESS);
//manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
}
void loop()
{
if (driver.available())
{
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(driver.lastRssi(), DEC);
// Send a reply back to the originator client
uint8_t data[] = "And hello back to you from server2";
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
Serial.println("sendtoWait failed");
}
}
}
can anyone help me? Is there something wrong with my code so no results come out on the serial monitor on the source node? I really appreciate your help!