Easy program to print signal strength (RF level) returned by phone. It prints a number that you can assign to a variable or check in a conditional, e.g.:
[ $(rf_level) -lt 1 ] && echo "no signal"
Some phones have a range of -1..4 (with -1 meaning "no signal"), others have a range of 0..100 (with 0 meaning "no signal")
If you can send AT commands to your phone you can get this value using AT+CSQ
but not all phones support this command and some take so long to answer to this command that communication times out if used with gnokii (LG U8120 is one that times out, you might succeed if you first send this command using minicom).
This is the same value reported by gnokii --monitor
while xgnokii
translates this value graphically showing 0 to 4 segments.
C source code:
/* $Id:$ G N O K I I A Linux/Unix toolset and driver for the mobile phones. This file is part of gnokii. Gnokii is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Gnokii is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gnokii; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright (C) 2006 by Daniele Forsi Prints signal strength (not supported by all phones). compile with gcc -Wall -o rf_level rf_level.c `pkg-config --libs gnokii` usage: rf_level usage: [ $(rf_level) -lt 1 ] && echo "no signal" */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <gnokii.h> /* prepare for i18n */ #define _(x) x struct gn_statemachine *state; void businit(void) { gn_error error; error = gn_lib_phoneprofile_load(NULL, &state); if (GN_ERR_NONE == error) { error = gn_lib_phone_open(state); } if (GN_ERR_NONE != error) { fprintf(stderr, "%s\n", _(gn_error_print(error))); exit(-1); } } void busterminate(void) { gn_lib_phone_close(state); gn_lib_phoneprofile_free(&state); gn_lib_library_free(); } void signal_handler(int signal) { busterminate(); exit(-2); } int main(int argc, char *argv[]) { gn_data data; gn_error error; float rflevel = -1; gn_rf_unit rfunit = GN_RF_Arbitrary; if (argc != 1) { fprintf(stderr, _("Usage: %s\nPurpose: print the signal strength\n"), argv[0]); exit(-1); } businit(); signal(SIGINT, signal_handler); gn_data_clear(&data); data.rf_level = &rflevel; data.rf_unit = &rfunit; error = gn_sm_functions(GN_OP_GetRFLevel, &data, state); if (error == GN_ERR_NONE) { printf("%d\n", (int)rflevel); } busterminate(); exit(error); }