I am reading the signal strength (RSSI) from my WiFly shield. I receive the RSSI in the following format:
RSSI=(-84) dBm
I want to store the "-84" number in an int variable and discard the other characters. I have tried to do this using switch case but it hasn't worked reliably.
SpiSerial.println("show rssi"); //requesting RSSI value
while(SpiSerial.available() > 0) {
char ch = SpiSerial.read(); //reads RSSI raw data
switch(ch){
case '0'...'9':
pos = pos * 10 + ch - '0';
break;
case '

-':
chara = (pos); //stores unwanted chars
pos = 0;
break;
case ') dBm':
rssi_val = (pos); //writes just RSSI number into rssi_val
pos = 0;
// Serial.print(SpiSerial.read(), BYTE);
Serial.println();
Serial.print("RSSI value is");
Serial.println(rssi_val);
break;
}
}
Can anyone suggest a better method to grab just the number?