RAK3172 send gps datas

hello everyone I don’t know much about my new RAK3172 module but I managed to connect to chirpstack with the arduino ‘test’ script so it works, on the other hand I have an E108 GPS and a script to read the coordinates, I can’t manage to merge the two, for everything sent to the server all help and welcome, thank you.

Welcome to RAK forum @fanfan6966 ,

Can you please share more info about the issue/difficulty you have so we can provide better support to you on using the RAK3172?

hello, yes of course, I am attaching the two scripts used, one to receive the GPS data and the other to send the data to the server, as said in my message, I cannot manage to merge the two, I tried several modifications and I can’t do it, if anyone has an example script I’m interested, thank you
GPS script ==>
#include <Arduino.h>
#include <TinyGPS++.h>

TinyGPSPlus gps;

void setup() {
Serial.begin(115200);
Serial1.begin(9600); // Default baud of NEO-6M GPS module is 9600
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, 0);
delay(1000);
digitalWrite(WB_IO2, 1);
delay(1000);
Serial.println(“GPS uart init ok!”);
}

void loop() {
if (Serial1.available() > 0) {
if (gps.encode(Serial1.read())) {
if (gps.location.isValid()) {
Serial.print(F("- latitude: "));
Serial.println(gps.location.lat(), 7); // Précision de 7 chiffres après la virgule

    Serial.print(F("- longitude: "));
    Serial.println(gps.location.lng(), 7); // Précision de 7 chiffres après la virgule

    Serial.print(F("- altitude: "));
    if (gps.altitude.isValid())
      Serial.println(gps.altitude.meters());
    else
      Serial.println(F("INVALID"));
    
    // Arrêter les demandes dès que le GPS a acquis une position
    return;
  } else {
    Serial.println(F("- location: INVALID"));
  }

  Serial.print(F("- speed: "));
  if (gps.speed.isValid()) {
    Serial.print(gps.speed.kmph());
    Serial.println(F(" km/h"));
  } else {
    Serial.println(F("INVALID"));
  }

  Serial.print(F("- GPS date&time: "));
  if (gps.date.isValid() && gps.time.isValid()) {
    Serial.print(gps.date.year());
    Serial.print(F("-"));
    Serial.print(gps.date.month());
    Serial.print(F("-"));
    Serial.print(gps.date.day());
    Serial.print(F(" "));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    Serial.println(gps.time.second());
  } else {
    Serial.println(F("INVALID"));
  }

  Serial.println();
}

}
}
lorawan send to chirpstak ==>
#define OTAA_PERIOD (30000)
/*************************************

LoRaWAN band setting:
RAK_REGION_EU433
RAK_REGION_CN470
RAK_REGION_RU864
RAK_REGION_IN865
RAK_REGION_EU868
RAK_REGION_US915
RAK_REGION_AU915
RAK_REGION_KR920
RAK_REGION_AS923

*************************************/
#define OTAA_BAND (RAK_REGION_EU868)
#define OTAA_DEVEUI {0x71, 0x8c, 0xde, 0xa9, 0x0d, 0x83, 0x5b, 0x20}
#define OTAA_APPEUI {0xAE, 0x04, 0xBA, 0xD9, 0x3E, 0x85, 0x2F, 0x93}
#define OTAA_APPKEY {0x19, 0x45, 0x64, 0x93, 0x56, 0x6D, 0xBE, 0xCD, 0x3D, 0xFB, 0x0F, 0x72, 0x67, 0xE8, 0xB5, 0x1D}

/** Packet buffer for sending */
uint8_t collected_data[64] = { 0 };

void recvCallback(SERVICE_LORA_RECEIVE_T * data)
{
if (data->BufferSize > 0) {
Serial.println(“Something received!”);
for (int i = 0; i < data->BufferSize; i++) {
Serial.printf(“%x”, data->Buffer[i]);
}
Serial.print(“\r\n”);
}
}

void joinCallback(int32_t status)
{
Serial.printf(“Join status: %d\r\n”, status);
}

/*************************************

  • enum type for LoRa Event
    RAK_LORAMAC_STATUS_OK = 0,
    RAK_LORAMAC_STATUS_ERROR,
    RAK_LORAMAC_STATUS_TX_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_TIMEOUT,
    RAK_LORAMAC_STATUS_RX2_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_ERROR,
    RAK_LORAMAC_STATUS_RX2_ERROR,
    RAK_LORAMAC_STATUS_JOIN_FAIL,
    RAK_LORAMAC_STATUS_DOWNLINK_REPEATED,
    RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
    RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
    RAK_LORAMAC_STATUS_ADDRESS_FAIL,
    RAK_LORAMAC_STATUS_MIC_FAIL,
    RAK_LORAMAC_STATUS_MULTICAST_FAIL,
    RAK_LORAMAC_STATUS_BEACON_LOCKED,
    RAK_LORAMAC_STATUS_BEACON_LOST,
    RAK_LORAMAC_STATUS_BEACON_NOT_FOUND,
    *************************************/

void sendCallback(int32_t status)
{
if (status == RAK_LORAMAC_STATUS_OK) {
Serial.println(“Successfully sent”);
} else {
Serial.println(“Sending failed”);
}
}

void setup()
{
Serial.begin(115200, RAK_AT_MODE);
delay(2000);

Serial.println("RAKwireless LoRaWan OTAA Example");
Serial.println("------------------------------------------------------");

if(api.lorawan.nwm.get() != 1)
{
    Serial.printf("Set Node device work mode %s\r\n",
        api.lorawan.nwm.set(1) ? "Success" : "Fail");
    api.system.reboot();
}

// OTAA Device EUI MSB first
uint8_t node_device_eui[8] = OTAA_DEVEUI;
// OTAA Application EUI MSB first
uint8_t node_app_eui[8] = OTAA_APPEUI;
// OTAA Application Key MSB first
uint8_t node_app_key[16] = OTAA_APPKEY;

if (!api.lorawan.appeui.set(node_app_eui, 8)) {
    Serial.printf("LoRaWan OTAA - set application EUI is incorrect! \r\n");
    return;
}
if (!api.lorawan.appkey.set(node_app_key, 16)) {
    Serial.printf("LoRaWan OTAA - set application key is incorrect! \r\n");
    return;
}
if (!api.lorawan.deui.set(node_device_eui, 8)) {
    Serial.printf("LoRaWan OTAA - set device EUI is incorrect! \r\n");
    return;
}

if (!api.lorawan.band.set(OTAA_BAND)) {
    Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n");
    return;
}
if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
    Serial.printf("LoRaWan OTAA - set device class is incorrect! \r\n");
    return;
}
if (!api.lorawan.njm.set(RAK_LORA_OTAA))	// Set the network join mode to OTAA
{
    Serial.printf("LoRaWan OTAA - set network join mode is incorrect! \r\n");
    return;
}
if (!api.lorawan.join())	// Join to Gateway
{
    Serial.printf("LoRaWan OTAA - join fail! \r\n");
    return;
}

/** Wait for Join success */
while (api.lorawan.njs.get() == 0) {
    Serial.print("Wait for LoRaWAN join...");
    api.lorawan.join();
    delay(10000);
}

if (!api.lorawan.adr.set(true)) {
    Serial.printf("LoRaWan OTAA - set adaptive data rate is incorrect! \r\n");
    return;
}
if (!api.lorawan.rety.set(1)) {
    Serial.printf("LoRaWan OTAA - set retry times is incorrect! \r\n");
    return;
}
if (!api.lorawan.cfm.set(1)) {
    Serial.printf("LoRaWan OTAA - set confirm mode is incorrect! \r\n");
    return;
}

/** Check LoRaWan Status*/
Serial.printf("Duty cycle is %s\r\n", api.lorawan.dcs.get()? "ON" : "OFF");	// Check Duty Cycle status
Serial.printf("Packet is %s\r\n", api.lorawan.cfm.get()? "CONFIRMED" : "UNCONFIRMED");	// Check Confirm status
uint8_t assigned_dev_addr[4] = { 0 };
api.lorawan.daddr.get(assigned_dev_addr, 4);
Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]);	// Check Device Address
Serial.printf("Uplink period is %ums\r\n", OTAA_PERIOD);
Serial.println("");
api.lorawan.registerRecvCallback(recvCallback);
api.lorawan.registerJoinCallback(joinCallback);
api.lorawan.registerSendCallback(sendCallback);

}

void uplink_routine()
{
/** Payload of Uplink */
uint8_t data_len = 0;
collected_data[data_len++] = (uint8_t) ‘t’;
collected_data[data_len++] = (uint8_t) ‘e’;
collected_data[data_len++] = (uint8_t) ‘s’;
collected_data[data_len++] = (uint8_t) ‘t’;

Serial.println("Data Packet:");
for (int i = 0; i < data_len; i++) {
    Serial.printf("0x%02X ", collected_data[i]);
}
Serial.println("");

/** Send the data package */
if (api.lorawan.send(data_len, (uint8_t *) & collected_data, 2, true, 1)) {
    Serial.println("Sending is requested");
} else {
    Serial.println("Sending failed");
}

}

void loop()
{
static uint64_t last = 0;
static uint64_t elapsed;

if ((elapsed = millis() - last) > OTAA_PERIOD) {
    uplink_routine();

    last = millis();
}
//Serial.printf("Try sleep %ums..", OTAA_PERIOD);
api.system.sleep.all(OTAA_PERIOD);
//Serial.println("Wakeup..");

}

my RAK is RAK3172 STM32WLE5

Hi @fanfan6966 ,

It seems you need to study first C coding as well as do some exercise for Arduino.

The closest tutorial I can share you is our guide for WisBlock Kit 3 - RAK Developer Kit 3 (Tracker Kit) Guide | RAKwireless Documentation Center

You will have an idea on how things works end-to-end. It is based on RAK4631 but it will give you some ideas.

Another example I can share is the one created by @beegee . The collection of RUI3 best practice RUI3-Best-Practice/RUI3-RAK12500-RAK1904-GNSS at main · RAKWireless/RUI3-Best-Practice · GitHub. He spent time to work on these examples and document them so you can have idea what is the purpose of each section.

thank you very much, for C no big problem, I know the syntax even if I am not a specialist, I will read all that, for the moment I can send fake GPS data to the server, I still have the codec (hex to ascii to write and connect my GPS to the code level to send the real coordinates.

1 Like