WeStudio技术社区

 找回密码
 立即注册

快捷登录

QQ登录

只需一步,快速开始

查看: 833|回复: 0

4G模块怎么查看信号强度?

[复制链接]

99

主题

142

帖子

1046

积分

版主

Rank: 7Rank: 7Rank: 7

积分
1046
发表于 2022-6-23 17:17:16 | 显示全部楼层 |阅读模式
本帖最后由 hixon 于 2022-6-23 18:09 编辑

在WeStudio中4G模块对应的是device.net.mobile控件,可以通过发送AT+CSQ命令来查询当前的信号强度。
1、在Pi-Pro主板上安装好4G模块及天线

2、新建一个工程, 在主界面上拖入一个按钮,在按钮的动作脚本里面发送AT命令,如:
send_at_command.png
  1. ui.main.btn_up.onRelease = function() {
  2.     var cmd = 'AT+CSQ';
  3.     device.net.mobile.sendAtCommand(cmd);
  4. };
复制代码


3、在mobile控件接收事件方法中读取modem的返回值:
mobile_read.png
  1. device.net.mobile.onReceive = function(count) {
  2.     var result = this.read();
  3.     var from = result.indexOf('+CSQ:');  // '\n\r+CSQ: 27,99\n\rOK\n\r'
  4.     if (from >= 0) {
  5.         var to = result.indexOf(',', from);   
  6.         var rssi = result.substring(from + 5, to).trim();
  7.         util.console.log('----rssi:' + rssi);
  8.     }
  9. };
复制代码

AT+CSQ
命令解释:检查网络信号强度和SIM卡情况
命令格式:AT+CSQ<CR>
命令返回:AT+CSQ: <rssi>,<ber>
           其中<rssi>应在0到31之间(含99表示无信号),数值越大表明信号质量越好,ber应为99。
           否则应检查天线或SIM卡是否正确安装

我们可以参考Android系统信号格数与信号强度的关系,asu就是<rssi>
  1. public int getGsmLevel() {
  2. int level;
  3. // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
  4. // asu = 0 (-113dB or less) is very weak
  5. // signal, its better to show 0 bars to the user in such cases.
  6. // asu = 99 is a special case, where the signal strength is unknown.
  7. int asu = getGsmSignalStrength();
  8. if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
  9. else if (asu >= 12) level = SIGNAL_STRENGTH_GREAT;
  10. else if (asu >= 8)  level = SIGNAL_STRENGTH_GOOD;
  11. else if (asu >= 5)  level = SIGNAL_STRENGTH_MODERATE;
  12. else level = SIGNAL_STRENGTH_POOR;
  13. if (DBG) log("getGsmLevel=" + level);
  14. return level;
  15. }
复制代码






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|物一世(北京)科技有限公司 ( 京ICP备20025895 )

GMT+8, 2024-4-25 18:37 , Processed in 0.012092 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表