Help required with RAK5860

RAK5860

How do I power it down and up?

#include "lora.h"

#include "cellular.h"

#define BG77_POWER_KEY WB_IO1

// Read the return value of BG77.
void BG77_read(time_t timeout)
{
  time_t timeStamp = millis();
  while ((millis() - timeStamp) < timeout)
  {
    if (Serial1.available() > 0)
    {
      Serial.print((char)Serial1.read());
      delay(1);
    }
  }
}

GPSData BG77_read_gps(time_t timeout)
{
  time_t timeStamp = millis();
  String gpsData = "";
  while ((millis() - timeStamp) < timeout)
  {
    if (Serial1.available() > 0)
    {
      gpsData += (char)Serial1.read();
      delay(1);
    }
  }
  gpsData.trim();
  log("GPS", gpsData.c_str());
  if (gpsData.indexOf("CME ERROR") != -1)
  {
    return {.success = false};
  }
  return {.success = true};
}

// Write commands to BG77.
void BG77_write(const char *command)
{
  while (*command)
  {
    Serial1.write(*command);
    command++;
  }
  Serial1.println();
}

bool setup_cellular(void)
{
  log("BG77", "Setting up");
  // Check if the modem is already awake
  Serial1.begin(115200);
  pinMode(BG77_POWER_KEY, OUTPUT);
  delay(1000);

  bool available = false;
  time_t timeout = millis();
  Serial1.println("ATI");

  // BG77 init
  while ((millis() - timeout) < 4000)
  {
    if (Serial1.available())
    {
      String result = Serial1.readString();
      log("BG77", "Response after start");
      Serial.println(result);
      available = true;
    }
  }

  if (!available) {
    wakeup_cellular();
  }

  // Set UE Functionality to Full
  BG77_write("AT+CFUN=1,0\r");
  BG77_read(15000);

  // Attach to PS
  BG77_write("AT+CGATT=1\r");
  BG77_read(2000);

  // Query EPS Network Registration Status
  BG77_write("AT+CEREG?\r");
  BG77_read(2000);

  // Query Network Information
  BG77_write("AT+QNWINFO\r");
  BG77_read(2000);

  // Query and Report Signal Strength
  BG77_write("AT+QCSQ\r");
  BG77_read(2000);

  // Set Supported GNSS Constellations to Auto
  BG77_write("AT+QGPSCFG=\"gnssconfig\",5\r");
  BG77_read(2000);

  // Enable XTRA Function
  BG77_write("AT+QGPSXTRA=1\r");
  BG77_read(2000);

  // Enable Automatic Downloading of XTRA
  BG77_write("AT+QGPSCFG=\"xtra_autodownload\"\r");
  BG77_read(2000);

  // Query the Existing XTRA File Information
  BG77_write("AT+QGPSCFG=\"xtra_info\"\r");
  BG77_read(2000);

  // 
  BG77_write("AT+CMGF=1\r");
  BG77_read(2000);

  // not working?
  Serial1.println("AT+CMGS=\"+49x\"\r");
  delay(1000);
  Serial1.print("Test\r");
  delay(100);
  Serial1.write(26);
  delay(5000);
  
  BG77_read(5000);

  delay(1000);

  powerdown_cellular();

  return true;
}

void wakeup_cellular(void) {
  time_t timeout = millis();
  bool available = false;
  while ((millis() - timeout) < 4000)
  {
    if (Serial1.available()) {
      available = true;
    }
  }
  if (available) {
    return;
  }
  log("BG77", "Slept, waking up");
  digitalWrite(BG77_POWER_KEY, LOW);
  delay(1000);
  digitalWrite(BG77_POWER_KEY, HIGH);
  delay(2000);
  digitalWrite(BG77_POWER_KEY, LOW);
  delay(1000);
  log("BG77", "Successfully powered up");
  delay(1000);
}

void powerdown_cellular(void) {
  log("BG77", "Powering down");
  digitalWrite(BG77_POWER_KEY, LOW);
  delay(1000);
  digitalWrite(BG77_POWER_KEY, HIGH);
  delay(2000);
  digitalWrite(BG77_POWER_KEY, LOW);
  delay(1000);
  log("BG77", "Successfully powered down");
}

GPSData get_gps(void)
{
  // Turn on GNSS
  BG77_write("AT+QGPS=1\r");
  BG77_read(2000);
  delay(20000);

  // Acquire Positioning Information
  // wont get fix
  BG77_write("AT+QGPSLOC=2\r");
  GPSData val = BG77_read_gps(2000);

  // Turn off GNSS
  BG77_write("AT+QGPSEND\r");
  BG77_read(2000);

  return val;
}

Hi @Majestic_Point_5834 ,

There are three ways you can shutdown the BG77 of the RAK5860.

  1. Via POWERKEY (this is the one in your Arduino sketch code)
  2. Via AT COMMAND using (AT+QPOWD)
  3. Via GPIO7 using (AT+QCFG=“fast/poweroff”)

The details of these methods are in this document - page 34 to 36.

1 Like

Thank you very much.
In the document you provided only pulling the powerkey low shortly turns on the device. but why in the examples its low(1s) high(2s) low(1s) to power it on?

Also. AT+QGPSCFG="xtra_autodownload",1 fails with +CME ERROR: 501.
I suspect its because of a older firmware? Is there a way to update it easily?

The logic is inverted because there is a transistor switch implemented on the circuit of RAK5860.

As for the FW version and updating the BG77, we do not have specific procedure on this but best reference will be the guidelines on quectel documentation itself.

But if i understand correctly my code to power on and off is correct

Is there any alternative to the RAK5860 that does NB-IoT? Maybe with a API like RUI3 instead of writing AT Commands

Hi @Majestic_Point_5834 ,

We have no API approach on any of our cellular modules, they are all based on AT commands.

You can check the examples here for different use cases - WisBlock/examples/common/communications/Cellular/RAK5860_BG77_Module at master · RAKWireless/WisBlock · GitHub

If you can switch hardware like RAK5010, you can use TinyGSM. You have to upload the adafruit bootloader on RAK5010 so you can use it. This library has more abstracted C library for various cellular functionality. I’ve used this before on RAK5010 and it works ok.