|
本帖最后由 hixon 于 2022-6-23 18:09 编辑
在WeStudio中4G模块对应的是device.net.mobile控件,可以通过发送AT+CSQ命令来查询当前的信号强度。
1、在Pi-Pro主板上安装好4G模块及天线
2、新建一个工程, 在主界面上拖入一个按钮,在按钮的动作脚本里面发送AT命令,如:
- ui.main.btn_up.onRelease = function() {
- var cmd = 'AT+CSQ';
- device.net.mobile.sendAtCommand(cmd);
- };
复制代码
3、在mobile控件接收事件方法中读取modem的返回值:
- device.net.mobile.onReceive = function(count) {
- var result = this.read();
- var from = result.indexOf('+CSQ:'); // '\n\r+CSQ: 27,99\n\rOK\n\r'
- if (from >= 0) {
- var to = result.indexOf(',', from);
- var rssi = result.substring(from + 5, to).trim();
- util.console.log('----rssi:' + rssi);
- }
- };
复制代码
AT+CSQ
命令解释:检查网络信号强度和SIM卡情况
命令格式:AT+CSQ<CR>
命令返回:AT+CSQ: <rssi>,<ber>
其中<rssi>应在0到31之间(含99表示无信号),数值越大表明信号质量越好,ber应为99。
否则应检查天线或SIM卡是否正确安装
我们可以参考Android系统信号格数与信号强度的关系,asu就是<rssi>- public int getGsmLevel() {
- int level;
- // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
- // asu = 0 (-113dB or less) is very weak
- // signal, its better to show 0 bars to the user in such cases.
- // asu = 99 is a special case, where the signal strength is unknown.
- int asu = getGsmSignalStrength();
- if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- else if (asu >= 12) level = SIGNAL_STRENGTH_GREAT;
- else if (asu >= 8) level = SIGNAL_STRENGTH_GOOD;
- else if (asu >= 5) level = SIGNAL_STRENGTH_MODERATE;
- else level = SIGNAL_STRENGTH_POOR;
- if (DBG) log("getGsmLevel=" + level);
- return level;
- }
复制代码
|
|