We shall create a UDP “connection” to our UDP Test Server with a BG96. The server simply replies whatever is typed into the prompt/terminal.
1.0 Remote Host Details
The following table lists the remote server details.
IP Address | 13.237.19.148 |
Port | 3000 |
2.0 Start a UDP Service and Send Data
Initially its required to configure and activate a context. In our example we are using a Telstra SIM and the APN may be different in your case.
Important
Before continuing on please make sure you disable the Power Save Mode: AT+CPSMS=0
2.1. Configure a Context and Activate
For Telstra SIM the following parameters are used:
APN | telstra.internet |
Context Number | 1 |
Send the following AT Commands using your preferred terminal program such as QCOM or Putty. On how to connect to the BG96 with USB/Serial please refer to the /wiki/how-to/establish-a-virtual-com-port-connection-to-bg96-with-usb/
Configure and Activate Context:
AT+QICSGP=1,1,"telstra.internet","","",1
OK
Activate the context:
AT+QIACT=1
OK
Check the active context:
AT+QIACT?
+QIACT: 1,1,1,"10.102.135.75"
OK
“10.102.135.75” is the IP address associated to our active context. The IP returned for you will be different.
2.2. Start a UDP Service
There are three types of data access modes available when opening a socket service.
- Buffer access mode
- Direct push mode
- Transparent access mode
In our example we shall use direct push mode. Please refer to the Quectel BG96 TCP(IP) AT Commands document for a detailed explanation of the data access modes.
AT+QIOPEN=1,2,"UDP SERVICE","127.0.0.1",0,3030,0
OK
+QIOPEN: 2,0
Query if the connection status of the associated context id, in our case its 1.
AT+QISTATE=0,1
+QISTATE: 2,"UDP SERVICE","10.121.9.118",0,3030,2,1,2,0,"usbmodem"
OK
2.3. Send Data to the Remote Server
We will now send the text “hello\r” to the remote server. For this we shall use the fixed length AT+QISEND command.
AT+QISEND=2,6,"13.237.19.148",3000
>
After the “>” is prompted we are ready to send the text.
>hello
SEND OK
+QIURC: "recv",2
2.3. Read the Data
Read the echoed text with the following command.
AT+QIRD=2
+QIRD: 6,"13.237.19.148",3000
hello
OK
2.4. Close the UDP Service
To be polite we shall close the active UDP service with the following command:
AT+QICLOSE=2
OK
3.0 AT Command Sequence
Bellow is the complete command sequence.
AT+QICSGP=1,1,"telstra.internet","","",1
OK
AT+QIACT=1
OK
AT+QIACT?
+QIACT: 1,1,1,"10.102.135.75"
OK
AT+QIOPEN=1,2,"UDP SERVICE","127.0.0.1",0,3030,0
OK
+QIOPEN: 2,0
AT+QISEND=2,6,"13.237.19.148",3000
>hello
SEND OK
+QIURC: "recv",2
AT+QIRD=2
+QIRD: 6,"13.237.19.148",3000
hello
OK