Linux gets 4G signal strength __linux

Source: Internet
Author: User
Tags readline

I got a lot of information, but I didn't find it. Get 4G signal Strength application code

There's no way, I can only write it myself.

First you need to know what the AT command is. This can refer to the following connection:

Https://www.cnblogs.com/yuweifeng/p/5587473.html


If the 4G device is running normally at the Terminal Input command will get the device current signal

Command:cat/dev/ttyusb2&

Echo-e "at+csq\r\n" >/DEV/TTYUSB2


Get:

At+csq
+csq:28,99
Ok
Aat+csq
+csq:28,99

28 is Rssi converted into a signal lattice reference article http://velep.com/archives/1147.html

I guess I'll just take a look. The following is the code is written in Qt, common discussion, welcome message


void Mainwindow::getcursignalstrenght (void) {printf ("============geting cursignalstrenght============\n");
	
    int sentatcount = 100; if (ec20check==1) {System ("CAT/DEV/TTYUSB2 |
		
		grep \ ' csq\ ' > signalstrength& ');
			while (sentatcount--) {printf ("============launch at command============\n");
			System ("ECHO-E \" at+csq\\r\\n\ ">/dev/ttyusb2");
			printf ("Echo-e \" at+csq\\r\\n\ ">/dev/ttyusb2\n");
			
			Usleep (1000);
			
			Qfile tempfile ("Signalstrength"); if (!tempfile.open (qiodevice::readonly |
			Qiodevice::text)) {qdebug () << "open signalstrength fail";
				else {Qtextstream templinefile (&tempfile);
				QString Templine;
				Templine = Templinefile.readline (). simplified ();
				Tempfile.close (); if (!templine.isempty ()) {printf ("============get data from temp file, say OH HO!!!!
					============\n ");
				Break
				else {printf ("============fuck, There no useful Data yet============\n");	Continue wile do Nothine}} system ("grep \ +csq:\ ' signalstrength > tempfilesignal");

		Qfile signalfile ("tempfilesignal"); if (!signalfile.open (qiodevice::readonly |
 			Qiodevice::text)) {signalstrenght = 0;
		Qdebug () << "open tempfilesignal fail";
			else {Qtextstream infile (&signalfile);
			QString Line;
			line = Infile.readline (). simplified ();
	
			Signalfile.close ();
				if (!line.isempty ()) {//--------------------------QString linedate;
				QString Rssi;  
				BOOL OK;
				Rssi = Line.mid (6,2);
				Qdebug () << "signal number is-tmpchr>=" <<rssi;
				printf ("Tmp.toint (&ok,10) is->%d\n", Rssi.toint (&ok,10));
				
				int Signaltrans =-113 + (2 * rssi.toint (&ok,10));

				printf ("Signaltrans is->%d\n", Signaltrans);
				if (Signaltrans >-91) {signalstrenght = 5;
				else if (Signaltrans <= -91 && signaltrans>-101) {signalstrenght = 4; }
				else if (Signaltrans <= -101 && signaltrans>-103) {signalstrenght = 3;
				else if (Signaltrans <= -103 && signaltrans>-107) {signalstrenght = 2;
				else if (Signaltrans <= -107 && signaltrans>-113) {signalstrenght = 1;
				else {//no signal signalstrenght = 0;
			printf ("=======get signalstrenght success.= signalstrenght is%d=======\n", signalstrenght);
				else {printf ("=======get signalstrenght failed...==set signalstrenght zero=======\n");
			signalstrenght = 0;
} System ("rm tempfilesignal-rf");
 }






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.