SIM868向程序发送命令时出错AT+CGATT=1 出错是怎么回事

这里用的是移动卡为例子
[08:49:12.562]发→◇AT
[08:49:12.562]收←◆AT
[11:30:18.950]发→◇41 54 0D 0A □
//(41 45表示AT,0D 0A表示回车换行,4F 4B表示OK)
[11:30:18.950]收←◆41 54 0D 0D 0D 0A 4F 4B 0D 0A
-------------------------------------------------------------
[08:51:04.663]发→◇AT+CPIN?
[08:51:04.663]收←◆AT+CPIN?
+CPIN: READY
[13:41:57.297]发→◇41 54 2B 43 50 49 4E 3F 0D 0A □
[13:41:57.302]收←◆41 54 2B 43 50 49 4E 3F 0D 0D 0A 2B 43 50 49 4E 3A 20 52 45 41 44 59 0D 0A 0D 0A 4F 4B 0D 0A
--------------------------------------------------------------
[08:51:17.258]发→◇AT+CSQ
[08:51:17.273]收←◆AT+CSQ
+CSQ: 31,0
[13:55:11.527]发→◇41 54 2B 43 53 51 0D 0A □
[13:55:11.533]收←◆41 54 2B 43 53 51 0D 0D 0A 2B 43 53 51 3A 20 33 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
--------------------------------------------------------------
[08:51:49.074]发→◇AT+CREG?
[08:51:49.074]收←◆AT+CREG?
+CREG: 0,1
[13:57:27.574]发→◇41 54 2B 43 52 45 47 3F 0D 0A □
[13:57:27.580]收←◆41 54 2B 43 52 45 47 3F 0D 0D 0A 2B 43 52 45 47 3A 20 30 2C 31 0D 0A 0D 0A 4F 4B 0D 0A
--------------------------------------------------------------
[08:52:05.520]发→◇AT+CGREG?
[08:52:05.535]收←◆AT+CGREG?
+CGREG: 0,1
[13:58:49.558]发→◇41 54 2B 43 47 52 45 47 3F 0D 0A □
[13:58:49.564]收←◆41 54 2B 43 47 52 45 47 3F 0D 0D 0A 2B 43 47 52 45 47 3A 20 30 2C 31 0D 0A 0D 0A 4F 4B 0D 0A
----------------------------------------------------------------
[08:56:48.376]发→◇AT+CMGF=0
[08:56:48.376]收←◆AT+CMGF=0
[14:05:58.302]发→◇41 54 2B 43 4D 47 46 3D 30 0D 0A □
[14:05:58.306]收←◆41 54 2B 43 4D 47 46 3D 30 0D 0D 0A 4F 4B 0D 0A
---------------------------------------------------------------
[08:57:35.293]发→◇AT+CNMI=2,1,0,0,0
[08:57:35.293]收←◆AT+CNMI=2,1,0,0,0
[14:07:21.677]发→◇41 54 2B 43 4E 4D 49 3D 32 2C 31 2C 30 2C 30 2C 30 0D 0A □
[14:07:21.684]收←◆41 54 2B 43 4E 4D 49 3D 32 2C 31 2C 30 2C 30 2C 30 0D 0D 0A 4F 4B 0D 0A
------------------------------------------------------------------
[08:58:16.855]发→◇AT+CGATT=1
[08:58:16.855]收←◆AT+CGATT=1
[14:07:56.773]发→◇41 54 2B 43 47 41 54 54 3D 31 0D 0A □
[14:07:56.778]收←◆41 54 2B 43 47 41 54 54 3D 31 0D 0D 0A 4F 4B 0D 0A
-------------------------------------------------------------------
[08:58:41.326]发→◇AT+CIPMODE=1
[08:58:41.326]收←◆AT+CIPMODE=1
[14:09:08.582]发→◇41 54 2B 43 49 50 4D 4F 44 45 3D 31 0D 0A □
[14:09:08.587]收←◆41 54 2B 43 49 50 4D 4F 44 45 3D 31 0D 0D 0A 4F 4B 0D 0A
---------------------------------------------------------------------
[08:59:20.315]发→◇AT+CSTT="CMNET"
[08:59:20.315]收←◆AT+CSTT="CMNET"
[08:59:20.315]发→◇41 54 2B 43 53 54 54 3D 22 43 4D 4E 45 54 22 20 0D 0A □
[08:59:20.315]收←◆41 54 2B 43 53 54 54 3D 22 43 4D 4E 45 54 22 20 0D 0D 0A 4F 4B 0D 0A
---------------------------------------------------------------------
[08:59:36.473]发→◇AT+CIICR
[08:59:36.488]收←◆AT+CIICR
[08:59:37.004]收←◆
[15:11:48.105]发→◇41 54 2B 43 49 49 43 52 0D 0A □
[15:11:48.110]收←◆41 54 2B 43 49 49 43 52 0D
[15:11:48.920]收←◆0D 0A 4F 4B 0D 0A
-----------------------------------------------------------------------------
[08:59:56.206]发→◇AT+CIFSR
[08:59:56.206]收←◆AT+CIFSR
10.37.219.156
[08:59:56.206]发→◇41 54 2B 43 49 46 53 52 0D 0A □
[08:59:56.206]收←◆41 54 2B 43 49 46 53 52 0D 0D 0A 31 30 2E 33 37 2E 32 31 39 2E 31 35 36 0D 0A
------------------------------------------------------------------------
[09:02:09.158]发→◇AT+CIPSTART="TCP","lohas.f3322.net","1231"
[09:02:09.173]收←◆AT+CIPSTART="TCP","lohas.f3322.net","1231"
[09:02:14.322]收←◆
[15:14:16.242]发→◇41 54 2B 43 49 50 53 54 41 52 54 3D 22 54 43 50 22 2C 22 6C 6F 68 61 73 2E 66 33 33 32 32 2E 6E 65 74 22 2C 22 31 32 33 31 22 0D 0A □
[15:14:16.249]收←◆41 54 2B 43 49 50 53 54 41 52 54 3D 22 54 43 50 22 2C 22 6C 6F 68 61 73 2E 66 33 33 32 32 2E 6E 65 74 22 2C 22 31 32 33 31 22 0D 0D 0A 4F 4B 0D 0A
[15:14:24.157]收←◆0D 0A 43 4F 4E 4E 45 43 54 0D 0A
--------------------------------------------------------------------------
[09:03:29.723]收←◆
+CMTI: "SM",4
+CMTI: "SM",5
sim868 c++二次开发基本完成
SIM868硬件设计学习(一)
没有更多推荐了,NB-IoT现在有华为和高通两种最主流的方案,两个方案的代表分别是移远和SIMCOM。
前头试玩了移远BC95,这次玩玩SIM7000C。本小能手作为IoT的弄潮儿,自然是不能拉下。(拉倒吧,人家4月出的模组,你11月才来玩。)
BC95-B8 : 900MHz
BC95-B5 : 850MHz
BC95-B20 : 800MHz
BC95-B28 : 700MHz
BC95-G*: B1/B3/B5/B8/B20/B28
在移远的多频NB-IoT还没出来的时候,SIM7000C显得领先了很多。SIM7000C是一款多频LTE-FDD及双频GPRS/EDGE无线模块,支持LTE CAT-M1(eMTC)、NB-IoT和GPRS/EDGE。
所以用SIM7000C的便利性很明显了,一个板子做出来几乎可以打天下,不用NB-IoT时,那就可以用GPRS,也可以赶时髦上 eMTC。本文在同一个板子分别使用电信NB卡和移动GPRS物联网卡做了验证测试,初步都能打通。
本文作者twowinter,转载请注明作者:
二、开发板准备
这里最主要参考官方文档《《SIMCOM_EVB KIT_User Guide_V1.01.pdf》》。不难看到,SIMCOM的一系列模块都是用这个评估板 8PYA00-SIMCOM-EVB。因此这里我们首先熟悉官方的评估板。
这是主卡座,NB卡放这里就好。
2 调试串口
Enhanced COM port: AT communication
Standard COM port: Debug
CP2105 driver is available here:
http://www.silabs.com/products/interface/usb-bridges/Pages/usb-bridges.aspx
USB线一连接PC,在设备管理器就可以看到两个串口。这个CP2105还挺厉害。本尊算是第一次见到这种双串口操作,挺酷的。
5.2 Power on Module:
1) Connect the SIMCOM-TE to the 2x60pins connector on EVB, plug in 5V DC adapter, switch S201 to “ON”
keep S401 to “ON” position.
2) Press the POWER_ON button for more than 1.5 second and then release, SIMCOM module power on.After
the module is on, the LED light D402 will be bright ,and the LED light D401will blink at a certain frequency.
Through the state of LED, you can judge registering status of the module. For detailed description, please
refer to SIMCOM HD document.
POWER_ON 按键按住1.5秒以上,就可以启动了。
三、NB-IoT注册网络思路
1. 手册梳理
流程操作,可参考《SIM7000 系列TCPIP应用文档_V1.00.pdf》,但这里头仅有TCP/UDP等处理。额外的NB-IoT操作示例在公开渠道上还没有,联系FAE会拿到。当然我的读者朋友们就有这个福利,如下是NB-IoT的操作范例。
Revision:1351B01SIM7000_TEST_
+CSUB:&V01
+CGREG:&0,1
+CPSI:&LTE&NB-IOT,Online,460-01,0x6,171,EUTRAN-BAND8,,-6,-91,-85,12
+COPS:&0,0,"460&01",9
+CSQ:&14,99
+CGNAPN:&1,"CUIOT"
AT+CSTT="CUIOT"
10.48.3.213&
AT+CIPSTART="TCP","47.94.228.89",4066
AT+CIPSTATUS
STATE:&TCP&CONNECTING
CONNECT&OK
AT+CIPATS=1,3
AT+CIPSEND
&&ABCDEFGHIJ
ABCDEFGHIJ
SIM7000C由于是多频模块,不能直接使用NB-IoT。具体的NB相关模式还要再配置下,参考操作示例,发现涉及两条命令。
5.2.20 AT+CNMP Preferred mode selection
5.2.21 AT+CMNB Preferred selection between CAT-M and NB-IoT
[17:57:06.704]发→◇+?
[17:57:06.707]收←◆+?
[17:57:34.167]发→◇+?
[17:57:34.172]收←◆+?
所以我手头这个模块是 CAT-M and NB-IoT 的模式,按照示例改成单NB模式。
四、NB-IoT加网测试具体细节
1.SIM卡状态
[17:53:09.094]收←◆
[17:53:11.488]收←◆
[17:53:11.796]收←◆
[17:53:13.005]收←◆
打印出这个说明SIM卡识别到了,这是由于 AT+CPIN 命令就是查询SIM卡状况。
另外也可使用AT+CIMI查询IMSI号,如果反馈错误,那说明卡没识别到,或者卡有问题。
2.信号强度
[18:02:52.867]发→◇+
[18:02:52.872]收←◆+
Parameters
0 -115 dBm or less
1 -111 dBm
2...30 -110... -54 dBm
31 -52 dBm or greater
99 not known or not detectable
看来这个信号强度是 -110… -54 dBm 之间。
3.网络注册情况
这个网络注册需要1分钟左右。
[19:03:36.179]发→◇AT+COPS?
[19:03:36.182]收←◆AT+COPS?
+COPS: 0,0,"460 11 ????",9
最后1位数字,为9的话,就表示是NB网络。
0 User-specified GSM access technology
8 User-specified LTE M1 A GB access technology
9 User-specified LTE NB S1 access technology
[19:04:19.232]发→◇+?
[19:04:19.237]收←◆+?
4.网络附着情况
[19:04:53.581]发→◇+?
[19:04:53.585]收←◆+?
主要设下APN,范例中给的是中国联通NB的APN “cuiot”,如果是中国电信的,那APN应当是 “ctnb”。
发→◇AT+CGNAPN
收←◆AT+CGNAPN
+CGNAPN: 1,"ctnb"
CSTT要设置对应的APN。
发→◇AT+CSTT?
收←◆AT+CSTT?
+CSTT: "CMNET","",""
发→◇AT+CSTT="ctnb"
收←◆AT+CSTT="ctnb"
6.激活移动场景
[20:24:10.748]发→◇+
[20:24:10.752]收←◆+
[20:24:10.800]收←◆
[20:26:20.768]发→◇+
[20:26:20.773]收←◆+
10.163.190.175
7.TCP连接及数据收发
AT+CIPSTART="TCP","xx.xx.xx.xx",xx
CONNECT OK
AT+CIPSEND=12
& ABCDEFGHIJ
早期电信那边貌似有个说法:因为电信的业务默认是定向,受理时需要在白名单中加入服务器地址,不添加IP是不会通的。
现在测试了一个没有添加的服务器地址,照例连接上了。看来之前的限制取消掉了。
8.断开连接
[21:04:38.011]发→◇AT+CIPCLOSE=1
[21:04:38.014]收←◆AT+CIPCLOSE=1
[21:04:51.087]发→◇AT+CIPSHUT
[21:04:51.090]收←◆AT+CIPSHUT
五、GSM模式测试
1.模式调整为GSM
[21:06:14.415]发→◇AT+CNMP=13
[21:06:14.418]收←◆AT+CNMP=13
[21:06:41.514]发→◇AT+CMNB=1
[21:06:41.519]收←◆AT+CMNB=1
2.基础查询
[21:17:27.264]发→◇+
[21:17:27.268]收←◆+
[21:17:35.098]发→◇+?
[21:17:35.103]收←◆+?
[21:17:41.905]发→◇+?
[21:17:41.910]收←◆+?
[21:17:56.977]发→◇+?
[21:17:56.982]收←◆+?
+: "","",""
[21:18:59.080]发→◇AT+CSTT=”CMNET”
[21:18:59.084]收←◆AT+CSTT=”CMNET”
[21:19:07.305]发→◇AT+CIICR
[21:19:07.308]收←◆AT+CIICR
[21:19:08.146]收←◆
[21:19:20.248]发→◇AT+CIFSR
[21:19:20.252]收←◆AT+CIFSR
10.184.208.143
4 TCP连接及数据收发
[21:19:33.103]发→◇AT+CIPSTART="TCP","xx.xx.xx.xx",xx
[21:19:33.112]收←◆AT+CIPSTART="TCP","xx.xx.xx.xx",xx
[21:19:33.643]收←◆
CONNECT OK
[21:20:02.407]发→◇AT+CIPSEND
[21:20:02.410]收←◆AT+CIPSEND
[21:20:12.519]发→◇xy
[21:20:12.522]收←◆xy
[21:20:58.670]发→◇xy
[21:20:58.673]收←◆xy
[21:21:01.565]收←◆
[21:21:02.303]收←◆
[21:21:15.175]发→◇AT+CIPSEND
[21:21:15.178]收←◆AT+CIPSEND
[21:21:29.342]发→◇xy
[21:21:29.345]收←◆xy
[21:21:31.816]收←◆
[21:21:32.542]收←◆
CIPSEND这条命令是用 CTRL+Z 发送,发了两包数据,服务器都收到了。
刚调试完,还是有点小兴奋,SIM7000C这“多模”搞地真的挺帅。意味着一个硬件定型后,前期宣传可以用NB-IoT,考虑实际网络覆盖还能用GPRS撑上去,非常方便。
另外一点,就是支持TCP连接,这也很方便。很多旧的TCP业务就可以无缝迁移到NB体系中。
扫码向博主提问
物联网技术交流
擅长领域:
NB-IoT中PSM和eDRX功能及配置
物联网:GPRS和NB-IOT
SIM7000C TCP
SIM7000C在NB模式下的非透传模式的TCPIP
GPRSsim800c
没有更多推荐了,/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free, non-transferable use of the information. NO * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * *//** @file * @defgroup uart_example_pca10000_main main.c * @{ * @ingroup uart_example_pca10000 * * @brief UART Example Application main file. * * This file contains the source code for a sample application using UART. * */#include &stdbool.h&#include &stdint.h&#include "nrf_delay.h"#include "nrf.h"#include "simple_uart.h"#include "nrf_gpio.h"#include "boards.h"#include "app_fifo.h"#include "app_uart.h"#include "compiler_abstraction.h"#include "app_error.h"//BLE#include "softdevice_handler.h"#include "ble.h"#include "ble_bas.h"#include "ble_hrs.h"#include "ble_dis.h"#include "ble_advdata.h"#include "ble_srv_common.h"//#include "device_manager.h"#define IS_SRVC_CHANGED_CHARACT_PRESENT
/**& Include or not the service_changed characteristic. if not enabled, the server's database cannot be changed for the lifetime of the device*/
#define HR_INC_BUTTON_PIN_NO
/**& Button used to increment heart rate. */#define HR_DEC_BUTTON_PIN_NO
/**& Button used to decrement heart rate. */#define BOND_DELETE_ALL_BUTTON_ID
HR_DEC_BUTTON_PIN_NO
/**& Button used for deleting all bonded centrals during startup. */#define DEVICE_NAME
"Nordic_HRM"
/**& Name of device. Will be included in the advertising data. */#define MANUFACTURER_NAME
"NordicSemiconductor"
/**& Manufacturer. Will be passed to Device Information Service. */#define APP_ADV_INTERVAL
/**& The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms). */#define APP_ADV_TIMEOUT_IN_SECONDS
/**& The advertising timeout in units of seconds. */#define APP_TIMER_PRESCALER
/**& Value of the RTC1 PRESCALER register. */#define APP_TIMER_MAX_TIMERS
/**& Maximum number of simultaneously created timers. */#define APP_TIMER_OP_QUEUE_SIZE
/**& Size of timer operation queues. */#define BATTERY_LEVEL_MEAS_INTERVAL
APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER) /**& Battery level measurement interval (ticks). */#define HEART_RATE_MEAS_INTERVAL
APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) /**& Heart rate measurement interval (ticks). */#define MIN_HEART_RATE
/**& Minimum heart rate as returned by the simulated measurement function. */#define MAX_HEART_RATE
/**& Maximum heart rate as returned by the simulated measurement function. */#define HEART_RATE_CHANGE
/**& Value by which the heart rate is incremented/decremented during button press. */#define APP_GPIOTE_MAX_USERS
/**& Maximum number of users of the GPIOTE handler. */#define BUTTON_DETECTION_DELAY
APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
/**& Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */#define MIN_CONN_INTERVAL
MSEC_TO_UNITS(500, UNIT_1_25_MS)
/**& Minimum acceptable connection interval (0.5 seconds). */#define MAX_CONN_INTERVAL
MSEC_TO_UNITS(1000, UNIT_1_25_MS)
/**& Maximum acceptable connection interval (1 second). */#define SLAVE_LATENCY
/**& Slave latency. */#define CONN_SUP_TIMEOUT
MSEC_TO_UNITS(4000, UNIT_10_MS)
/**& Connection supervisory timeout (4 seconds). */#define FIRST_CONN_PARAMS_UPDATE_DELAY
APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) /**& Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */#define NEXT_CONN_PARAMS_UPDATE_DELAY
APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER)/**& Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */#define MAX_CONN_PARAMS_UPDATE_COUNT
/**& Number of attempts before giving up the connection parameter negotiation. */#define SEC_PARAM_TIMEOUT
/**& Timeout for Pairing Request or Security Request (in seconds). */#define SEC_PARAM_BOND
/**& Perform bonding. */#define SEC_PARAM_MITM
/**& Man In The Middle protection not required. */#define SEC_PARAM_IO_CAPABILITIES
BLE_GAP_IO_CAPS_NONE
/**& No I/O capabilities. */#define SEC_PARAM_OOB
/**& Out Of Band data not available. */#define SEC_PARAM_MIN_KEY_SIZE
/**& Minimum encryption key size. */#define SEC_PARAM_MAX_KEY_SIZE
/**& Maximum encrypt*/ static ble_gap_adv_params_t
/**& Parameters to be passed to the stack when starting advertising. */ble_bas_t
/**& Structure used to identify the battery service. */static ble_hrs_t
/**& Structure used to identify the heart rate service. */static volatile uint16_t
m_cur_heart_
/**& Current heart rate value. */
//static app_timer_id_t
m_battery_timer_
/**& Battery timer. *///static app_timer_id_t
m_heart_rate_timer_
/**& Heart rate measurement timer. */static bool
m_memory_access_in_progress =
/**& Flag to keep track of ongoing operations on persistent memory. *///static dm_application_instance_t
/**& Application identifier allocated by device manager */static void ble_evt_dispatch(ble_evt_t * p_ble_evt);static void sys_evt_dispatch(uint32_t sys_evt);#define UART_TX_BUF_SIZE
/**& UART TX buffer size. */#define UART_RX_BUF_SIZE
/**& UART RX buffer size. */#define LOG_RX_PIN_NUMBER
23#define LOG_TX_PIN_NUMBER
24#define MAX_DATA_LEN
500static uint8_t uart_rx_data_array[MAX_DATA_LEN];static uint8_t m_uart_rx_data_array[MAX_DATA_LEN];static uint16_t m_uart_data_array_static uint16_t mm_uart_data_array_#define UNUSED_VARIABLE(X)
((void)(X))#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)#define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)uint8_t rx_cmd_data = 0;volatile uint8_t
start_test_flag = 0;void uart_event_handle(app_uart_evt_t * p_event){
switch (p_event-&evt_type)
case APP_UART_DATA_READY:
UNUSED_VARIABLE(app_uart_get(&rx_cmd_data));
m_uart_rx_data_array[mm_uart_data_array_index++] = rx_cmd_
if(m_uart_rx_data_array[mm_uart_data_array_index-8]=='A'&&m_uart_rx_data_array[mm_uart_data_array_index-7]=='T'&&m_uart_rx_data_array[mm_uart_data_array_index-2]=='T')
start_test_flag = m_uart_rx_data_array[mm_uart_data_array_index-1];
if(MAX_DATA_LEN==m_uart_data_array_index)
mm_uart_data_array_index = 0;
case APP_UART_FIFO_ERROR:
APP_ERROR_HANDLER(p_event-&data.error_code);
}}static void m_uart_init(void){
const app_uart_comm_params_t comm_params =
LOG_RX_PIN_NUMBER,
LOG_TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED,
UART_BAUDRATE_BAUDRATE_Baud115200
app_uart_close(0);
app_uart_flush(); nrf_delay_ms(2);
APP_UART_FIFO_INIT( &comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);}#define PCCTL_PIN
29#define UART_TX_BUF_SIZE
/**& UART TX buffer size. */#define UART_RX_BUF_SIZE
/**& UART RX buffer size. */#define GPRS_TX_PIN
4#define GPRS_RX_PIN
5#define GPRS_POWER_ON
nrf_gpio_cfg_output(PCCTL_PIN);nrf_gpio_pin_set(PCCTL_PIN)#define GPRS_POWER_OFF
nrf_gpio_pin_clear(PCCTL_PIN)static uint8_t server[]
= "AT+CIPSTART=\"TCP\",\"14.215.177.38\",80\r\n";uint8_t M_imsi[20]={0};uint8_t M_imei[20]={0};uint8_t M_csq[4]={0};uint8_t TCP_CONNECT[20] = {0};void gprs_event_handle(app_uart_evt_t * p_event){ uint8_t temp = 0;
switch (p_event-&evt_type)
case APP_UART_DATA_READY:
app_uart_get(&temp);
uart_rx_data_array[m_uart_data_array_index++] =
//m_data_array_index++
NRF_LOG_PRINTF("%c",temp);
if(MAX_DATA_LEN==m_uart_data_array_index)
m_uart_data_array_index = 0;
case APP_UART_FIFO_ERROR:
APP_ERROR_HANDLER(p_event-&data.error_code);
}}static void m_gprs_init(void){
const app_uart_comm_params_t comm_params =
GPRS_RX_PIN,
GPRS_TX_PIN,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED,
UART_BAUDRATE_BAUDRATE_Baud115200
app_uart_close(0);
app_uart_flush(); nrf_delay_ms(2);
APP_UART_FIFO_INIT( &comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
gprs_event_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);}typedef uint32_t ret_code_t;//typedef struct//{//
/**& The line number where the error occurred. *///
uint8_t const * p_file_ /**& The file in which the error occurred. *///
/**& The error code representing the error that occurred. *///} error_info_t;
__weak void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);void app_error_handler(ret_code_t error_code, uint32_t line_num, const uint8_t * p_file_name){
error_info_t error_info =
= line_num,
.p_file_name = p_file_name,
= error_code,
app_error_fault_handler(0x, 0, (uint32_t)(&error_info));
UNUSED_VARIABLE(error_info);}void nrf_delay_ms(uint32_t volatile number_of_ms){
while(number_of_ms != 0)
number_of_ms--;
nrf_delay_us(999);
}}void print_log(const uint8_t *pstring){
while(*pstring)
while(app_uart_put(*pstring++) != NRF_SUCCESS);
}}void clear_rx_buffer(uint8_t *buf,uint16_t *index){
memset(buf,0,MAX_DATA_LEN);
*index = 0;}void send_at_cmd(const uint8_t *pstring){
while(*pstring)
while(app_uart_put(*pstring++) != NRF_SUCCESS);
}void get_IMSI(){ clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd("AT+CIMI\r\n"); nrf_delay_ms(2000); memset(M_imsi,0,20); memcpy(M_imsi,&uart_rx_data_array[10],15); nrf_delay_ms(1000);}void get_IMEI(){ clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd("AT+GSN\r\n"); nrf_delay_ms(2000); memset(M_imei,0,20); memcpy(M_imei,&uart_rx_data_array[9],17); nrf_delay_ms(1000);}void Wait_CREG(void){ uint8_t i = 0; clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index); while(i == 0)
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd("AT+CGREG?\r\n");
nrf_delay_ms(2000);
for(uint8_t k=0;k&m_uart_data_array_k++)
if(uart_rx_data_array[k] == ':')
if((uart_rx_data_array[k+4] == '1')||(uart_rx_data_array[k+4] == '5'))
//UART1_SendLR();
}}void check_csq(){ uint8_t i = 0; clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index); while(i == 0)
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
nrf_delay_ms(2000);
send_at_cmd("AT+CSQ\r\n");
nrf_delay_ms(2000);
for(uint8_t k=0;k&m_uart_data_array_k++)
if(uart_rx_data_array[k] == ':')
memcpy(M_csq,&uart_rx_data_array[k+2],2);//
M_csq[0]=uart_rx_data_array[k+2];//
M_csq[1]=uart_rx_data_array[k+3];//
M_csq[2]='\0';
if(M_csq[1]==',')M_csq[1]='\0';
if(atoi((char*)M_csq)&=16)//
if(((uart_rx_data_array[k+2] == '1')&&(uart_rx_data_array[k+3] &= '6'))||(uart_rx_data_array[k+2] &= '2'))
//UART1_SendLR();
}}bool find(uint8_t *s){
if(strstr((char*)uart_rx_data_array,(char*)s)!=NULL)
}void AT_CMD_Handler(uint8_t *p_atcmd,uint8_t *s,uint32_t wait_time){
int i = 0;
bool pass =
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
while(!pass)
if(!find(s))
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd(p_atcmd);
nrf_delay_ms(wait_time);
for(int k = 0;k & 50 ; k++){
if(uart_rx_data_array[k] == 'E' && uart_rx_data_array[k+1] == 'R' ){
if(uart_rx_data_array[k] == 'e' && uart_rx_data_array[k+1] == 'r'){
if(i & 20){
if(!pass){ error:
m_uart_init();
print_log("error");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
// clear_rx_buffer();}void AT_CMD_Handler2(uint8_t *p_atcmd,uint8_t *s,uint32_t wait_time){
int i = 0;
bool pass =
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
while(!pass)
if(!find(s))
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd(p_atcmd);
nrf_delay_ms(wait_time);
if(uart_rx_data_array[k] == 'E' && uart_rx_data_array[k+1] == 'R' ){//
if(uart_rx_data_array[16] == 'O' && uart_rx_data_array[17] == 'K' ){
if(i & 20){
if(!pass){ error:
m_uart_init();
print_log("error");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
// clear_rx_buffer();}void AT_CMD_Handler1(uint8_t *p_atcmd,uint8_t *s,uint32_t wait_time){
int i = 0;
bool pass =
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
while(!pass)
if(!find(s))
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd(p_atcmd);
nrf_delay_ms(wait_time);
for(int k = 0;k & 50 ; k++){
if(uart_rx_data_array[k] == 'E' && uart_rx_data_array[k+1] == 'R' ){
if(i & 20){
if(uart_rx_data_array[23] == '1'){
m_uart_init();
print_log("GNSS Link OK");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
m_uart_init();
print_log("GNSS Link error");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
if(uart_rx_data_array[25] == '1'){
m_uart_init();
print_log("Location OK");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
m_uart_init();
print_log("Location error");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
if(!pass){ error:
m_uart_init();
print_log("error");
nrf_delay_ms(100);
print_log("\r\n");
m_gprs_init();
// clear_rx_buffer();}void Get_LocalIP(){
//uint8_t i = 0;
clear_rx_buffer(uart_rx_data_array,&m_uart_data_array_index);
send_at_cmd("AT+CIFSR\r\n");
nrf_delay_ms(2000);
}//void connect_server(void)//{
//// AT_CMD_Handler("ATE1\r\n","OK",1000);//// //// AT_CMD_Handler("AT+CIPSHUT\r\n","SHUT OK",1000);//// AT_CMD_Handler("AT+CGATT=1\r\n","OK",1000);// AT_CMD_Handler("AT+CGATT?\r\n","+CGATT: 1",1000);// AT_CMD_Handler("AT+CSTT = \"CMNET\"\r\n","OK",2000);//
AT_CMD_Handler("AT+CIICR\r\n","OK",2000);// Get_LocalIP();// // //AT_CMD_Handler("AT+CIPCSGP=1,\"CMNET\"","OK",2);// AT_CMD_Handler("AT+CSTT\r\n","OK",2000);// AT_CMD_Handler("AT+CIICR\r\n","OK",2000);// //AT_CMD_Handler("AT+CGATT?\r\n","OK",2);//
Get_LocalIP();// AT_CMD_Handler("AT+CIPHEAD=1\r\n","OK",1000);// AT_CMD_Handler(server,"CONNECT OK",4000);// AT_CMD_Handler("AT+CIPSHUT\r\n","SHUT OK",1000);//// AT_CMD_Handler("AT+CIPSEND\r\n","&",2000);//}void connect_server(void){
AT_CMD_Handler("ATE1\r\n","OK",1000);
AT_CMD_Handler("AT+CIPSHUT\r\n","SHUT OK",1000); AT_CMD_Handler("AT+CGATT=1\r\n","OK",1000); AT_CMD_Handler("AT+CGATT?\r\n","+CGATT: 1",1000); //AT_CMD_Handler("AT+CIPCSGP=1,\"CMNET\"","OK",2); AT_CMD_Handler("AT+CSTT\r\n","OK",2000); AT_CMD_Handler("AT+CIICR\r\n","OK",2000); //AT_CMD_Handler("AT+CGATT?\r\n","OK",2);
Get_LocalIP(); AT_CMD_Handler("AT+CIPHEAD=1\r\n","OK",1000); AT_CMD_Handler(server,"CONNECT OK",4000); memcpy(TCP_CONNECT,&uart_rx_data_array[45],15); nrf_delay_ms(10); AT_CMD_Handler("AT+CIPSHUT\r\n","SHUT OK",1000);// AT_CMD_Handler("AT+CIPSEND\r\n","&",2000);}void GPS_server(void){
// AT_CMD_Handler("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n","OK",1000);// AT_CMD_Handler("AT+SAPBR=3,1,\"APN\",\"3GNET\"\r\n","OK",1000);// AT_CMD_Handler("AT+SAPBR=1,1\r\n","OK",1000);// AT_CMD_Handler("AT+SAPBR=2,1\r\n","OK",1000);// // AT_CMD_Handler("AT+CNTPCID=1\r\n","OK",1000);// AT_CMD_Handler("AT+CNTP?\r\n","OK",1000);// AT_CMD_Handler("AT+CNTP\r\n","OK",1000);// AT_CMD_Handler("AT+CCLK?\r\n","OK",1000);// AT_CMD_Handler("AT+CLBS=1,1\r\n","OK",1000);// // AT_CMD_Handler("AT+FTPSERV=\"116.247.119.165\"\r\n","OK",1000);// AT_CMD_Handler("AT+FTPUN=\"customer\"\r\n","OK",1000);// AT_CMD_Handler("AT+FTPPW=\"111111\"\r\n","OK",1000);// AT_CMD_Handler("AT+FTPGETNAME=\"MTK3.EPO\"\r\n","OK",1000);// AT_CMD_Handler("AT+FTPGETPATH=\"/\"\r\n","OK",1000);// AT_CMD_Handler("AT+FTPEXTGET=1\r\n","OK",1000);// AT_CMD_Handler("AT+FTPEXTGET=4,\"epo\"\r\n","OK",3000);// AT_CMD_Handler("AT+FSLS=C:\\User\\\r\n","OK",1000);// AT_CMD_Handler("AT+CGNSCHK=3,1\r\n","OK",1000);// AT_CMD_Handler("AT+CGNSPWR=1\r\n","OK",1000);// // AT_CMD_Handler("AT+CGNSAID=31,1,1\r\n","+CGNSAID: OK",1000);// AT_CMD_Handler("AT+CGNSINF\r\n","1,1,20",2000);
AT_CMD_Handler2("AT+CGNSPWR=1\r\n","OK",1000); AT_CMD_Handler1("AT+CGNSINF\r\n","+CGNSINF: 1,",1000);}void gprs_test(){ uint32_t err_ GPRS_POWER_ON; nrf_delay_ms(2000);
m_gprs_init(); nrf_delay_ms(1000);// Wait_CREG(); get_IMEI(); m_uart_init();
nrf_delay_ms(100); print_log("IMEI = "); print_log(M_imei); print_log("\r\n");
nrf_delay_ms(100);
m_gprs_init(); get_IMSI(); m_uart_init(); nrf_delay_ms(100);
print_log("IMSI = "); print_log(M_imsi); print_log("\r\n");
nrf_delay_ms(50);
m_gprs_init(); check_csq(); m_uart_init(); nrf_delay_ms(100); print_log("CSQ = "); print_log(M_csq); print_log("\r\n"); nrf_delay_ms(100);
m_gprs_init();
connect_server(); m_uart_init(); nrf_delay_ms(100); print_log(TCP_CONNECT);// print_log("\r\n"); nrf_delay_ms(100);
m_gprs_init(); nrf_delay_ms(1000); GPS_server();// gps_flag = }void uart_disable (void){
NRF_UART0-&ENABLE = (UART_ENABLE_ENABLE_Disabled && UART_ENABLE_ENABLE_Pos);
NRF_UART0-&TASKS_STOPTX = 1;
NRF_UART0-&TASKS_STOPRX = 1;
NRF_UART0-&POWER = 0;}static void ble_evt_dispatch(ble_evt_t * p_ble_evt){//
dm_ble_evt_handler(p_ble_evt);
ble_hrs_on_ble_evt(&m_hrs, p_ble_evt);
ble_bas_on_ble_evt(&bas, p_ble_evt);
ble_conn_params_on_ble_evt(p_ble_evt);//
on_ble_evt(p_ble_evt);}static void sys_evt_dispatch(uint32_t sys_evt){
pstorage_sys_event_handler(sys_evt);//
on_sys_evt(sys_evt);}static void ble_stack_init(void){
uint32_t err_
// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
// Enable BLE stack
ble_enable_params_t ble_enable_
memset(&ble_enable_params, 0, sizeof(ble_enable_params));
ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
err_code = sd_ble_enable(&ble_enable_params);
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);}static void gap_params_init(void){
ble_gap_conn_params_t
ble_gap_conn_sec_mode_t sec_
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)DEVICE_NAME,
strlen(DEVICE_NAME));
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT);
APP_ERROR_CHECK(err_code);
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency
= SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout
= CONN_SUP_TIMEOUT;
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);}static void advertising_init(void){
ble_advdata_
flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
ble_uuid_t adv_uuids[] =
{BLE_UUID_HEART_RATE_SERVICE,
BLE_UUID_TYPE_BLE},
{BLE_UUID_BATTERY_SERVICE,
BLE_UUID_TYPE_BLE},
{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));
advdata.name_type
= BLE_ADVDATA_FULL_NAME;
advdata.include_appearance
advdata.flags.size
= sizeof(flags);
advdata.flags.p_data
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
advdata.uuids_complete.p_uuids
err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code);
// Initialize advertising parameters (used when starting advertising).
memset(&m_adv_params, 0, sizeof(m_adv_params));
m_adv_params.type
= BLE_GAP_ADV_TYPE_ADV_IND;
m_adv_params.p_peer_addr = NULL;
// Undirected advertisement.
m_adv_params.fp
= BLE_GAP_ADV_FP_ANY;
m_adv_params.interval
= APP_ADV_INTERVAL;
m_adv_params.timeout
= APP_ADV_TIMEOUT_IN_SECONDS;}static void services_init(void){
ble_hrs_init_t hrs_
ble_bas_init_t bas_
ble_dis_init_t dis_
body_sensor_
// Initialize Heart Rate Service.
body_sensor_location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER;
memset(&hrs_init, 0, sizeof(hrs_init));
hrs_init.is_sensor_contact_supported =
hrs_init.p_body_sensor_location
= &body_sensor_
// Here the sec level for the Heart Rate Service can be changed/increased.
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&hrs_init.hrs_hrm_attr_md.cccd_write_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hrs_init.hrs_hrm_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hrs_init.hrs_hrm_attr_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&hrs_init.hrs_bsl_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hrs_init.hrs_bsl_attr_md.write_perm);
err_code = ble_hrs_init(&m_hrs, &hrs_init);
APP_ERROR_CHECK(err_code);
// Initialize Battery Service.
memset(&bas_init, 0, sizeof(bas_init));
// Here the sec level for the Battery Service can be changed/increased.
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.cccd_write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&bas_init.battery_level_char_attr_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_report_read_perm);
bas_init.evt_handler
bas_init.support_notification =
bas_init.p_report_ref
bas_init.initial_batt_level
err_code = ble_bas_init(&bas, &bas_init);
APP_ERROR_CHECK(err_code);
// Initialize Device Information Service
memset(&dis_init, 0, sizeof(dis_init));
ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm);
err_code = ble_dis_init(&dis_init);
APP_ERROR_CHECK(err_code);}static void advertising_start(void){
uint32_t err_
err_code = sd_ble_gap_adv_start(&m_adv_params);
APP_ERROR_CHECK(err_code);//
led_start();}int main(void){
ble_stack_init();
gap_params_init();
advertising_init();
services_init();
advertising_start();
nrf_gpio_cfg_output(27);// nrf_gpio_cfg_input(28, NRF_GPIO_PIN_PULLDOWN);// nrf_gpio_cfg_sense_input(28, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW );// // gprs_test();// // m_uart_init();// print_log("\r\n");// print_log("GPS test STOP!\r\n");// nrf_delay_ms(100);// // // GPRS_POWER_OFF;// uart_disable();// //
nrf_gpio_cfg_output(2);////
nrf_gpio_pin_set(2);//// nrf_gpio_pin_write(2, 1);// // nrf_gpio_pin_clear(23);// nrf_gpio_pin_clear(24);// nrf_gpio_pin_clear(4);// nrf_gpio_pin_clear(5);// //// nrf_gpio_pin_clear(2);// //
nrf_gpio_cfg_input(2,
NRF_GPIO_PIN_PULLUP );// // nrf_gpio_cfg_input(23, NRF_GPIO_PIN_PULLDOWN);// nrf_gpio_cfg_input(24, NRF_GPIO_PIN_PULLDOWN);// nrf_gpio_cfg_input(4, NRF_GPIO_PIN_PULLDOWN);// nrf_gpio_cfg_input(5, NRF_GPIO_PIN_PULLDOWN);// // nrf_gpio_cfg_input(29, NRF_GPIO_PIN_PULLDOWN);// // // // NRF_POWER-&RAMON = POWER_RAMON_ONRAM0_RAM0On && POWER_RAMON_ONRAM0_Pos//| POWER_RAMON_ONRAM1_RAM1On && POWER_RAMON_ONRAM1_Pos//| POWER_RAMON_OFFRAM0_RAM0Off && POWER_RAMON_OFFRAM0_Pos//| POWER_RAMON_OFFRAM1_RAM1Off && POWER_RAMON_OFFRAM1_P//while(1){//NRF_POWER-&SYSTEMOFF = 1;//}while(1){}
}bool find(uint8_t *s){
if(strstr((char*)uart_rx_data_array,(char*)s)!=NULL)
}/** *@} **/
nrf51822-添加DFU服务
NRF51822自学笔记(三)心率计
这两天学习nRF51822的心得
NRF51822 回顾总结
蓝牙nrf51822程序的分析(一)
没有更多推荐了,

我要回帖

更多关于 老的电信版WP手机SIM卡出错 的文章

 

随机推荐