How to convert the AT+CSQ RSSI reading into dB(mW)

I want to convert the return from getSignalStrength() into an the signal power given in dB(mW).
One problem is, that the return is of the datatype string. In order to calculate the signal strengeth in dB(mW), I tried to convert it to an integer. I found that function:

int rssiInt = atoi(rssi.c_str());

The sketch compiles fine, however the serial monitor doesnt show the expected result. The conversion result is not shown/incorrect.

Opened the serial port - COM3
RSSI to dB(mW) converter

Get current carrier: AT+COPS?

+COPS: 1,0,"262 01",9

262 01
Get current signal strength: AT+CSQ

+CSQ: 10,99


+CSQ: 10,99

�FpG���F����FpGRSSI to dB(mW) converter

According to that link, every inkrement in the getSignalStrength() return value starting at 0 equals an improvement of 2 dB(mW) over -113 db(mW), topping out 31 and -51 dB(mW).

Question: Is my conversion wrong? What alternatives are there for typecasting from string to interger?

Below is the full code:

#include <MKRNB.h>

NBScanner scanner;
NB nb(1);

void setup()
    Serial.println(F("RSSI to dB(mW) converter"));

    Serial.print("Get current carrier: ");

    Serial.print("Get current signal strength: ");
    //convert RSSI to dB(mW)
    String rssi = scanner.getSignalStrength();
    int rssiInt = atoi(rssi.c_str());                           //String -> Int
    int dBm = (-113 + 2*rssiInt);                               //RSSI -> dB(mW) : -113 dBm = 0, -111 dBm = 1, -109 dBm = 2, ... -51 dBm = 31
    Serial.println(dBm +" dB(mW) [-113 < P < -51]dB(mW)");      //     

void loop()

This is the function I use, which strips away the the unwanted text so the result is readable, and returns the signal_power as an INT. For the SARA-R4 it will always report the qual as 99. (I can’t remember where I got this, I may have modified it from the library, or from another forum post, I don’t think I wrote it):

// returns "+CSQ: <signal_power>,<qual>"
int getSignalStrength()
  String response;
  int rssi = -1;

  if (MODEM.waitForResponse(100, &response) == 1) {
    int firstSpaceIndex = response.indexOf(' ');
    int lastCommaIndex = response.lastIndexOf(',');
    // Serial.println(response);

    if (firstSpaceIndex != -1 && lastCommaIndex != -1) {
      String temp = response.substring(firstSpaceIndex + 1, lastCommaIndex);
      rssi = temp.toInt();

  return rssi;

Then, you could use the map function to reassign the value to dBm as per your reference to the documentation.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.