Untitled
unknown
c_cpp
5 months ago
1.0 kB
1
Indexable
LteClass Lte; String LteClass::getSignalStrength(void) { String response = ""; Serial1.println("AT+CSQ"); // Send AT command to query signal strength // Wait for a response from the module unsigned long start = millis(); while ((millis() - start) < 1000) { if (Serial1.available()) { char c = Serial1.read(); response += c; } } // Parse response to extract signal strength int rssi = -1; // default value if parsing fails if (response.startsWith("+CSQ:")) { int commaIndex = response.indexOf(','); if (commaIndex > 6) { String rssiValue = response.substring(6, commaIndex); int rssiInt = rssiValue.toInt(); if (rssiInt >= 0 && rssiInt <= 31) { rssi = -113 + (rssiInt * 2); // Convert CSQ value to dBm } } } if (rssi != -1) { return String(rssi) + " dBm"; } else { return "Signal strength not available"; } }
Editor is loading...
Leave a Comment