hello. I came across NB-IoT while studying at a university in Korea.
I am currently blocked in the BC95-G TCP Send/Recv part.
In the case of Send and Recv, we want to operate each.
CASE.1 → MODULE → SERVER
CASE.2 → SERVER → MODULE
CASE. 1
AT+NSOCR=STREAM,6,0,1 => OK
AT+NSOCO=1,SERVER_IP,SERVER_PORT => OK
AT+NSOSD=1,4,AB21 => ERROR
CASE. 2
AT+NSOCR=STREAM,6,0,1 => OK
AT+NSOCO=1,SERVER_IP,SERVER_PORT => OK
AT+NSORF=1,4 => OK appears for about 2 minutes, then ERROR No data is received.
Quectel_BC95-G&BC96_AT_Commands_Manual_v1.5.pdf
Examples 8.3. I am working on Arduino while watching Send/Receive/Read a TCP Message.
#define BAUDRATE 9600 //define the baud is 9600bps/s
static char retmcu[256] = {'\0'}; //save the mcu return message for AT Command
void Serial1_clearbuf()
{
Serial1.flush();
while (Serial1.available()) {
Serial1.read();
}
}
void Serial1_read()
{
int i = 0;
String str_recv;
memset(retmcu, 0, sizeof(retmcu));//reference c language lib menset
//array is cleaned in here
Serial1.flush(); //Waits for the transmission of outgoing serial data to complete.
delay(1500); //Waits for respones from server
while (Serial1.available() && i < sizeof(retmcu) - 1) {
retmcu[i] = Serial1.read();//read return's value and strage in this array
str_recv.concat(String(retmcu[i]));
i++;
}
retmcu[i] = '\0'; //
str_recv.trim();
Serial.println(str_recv); //for debug
}
void Serial1_read_recv()
{
int i = 0;
String str_recv;
memset(retmcu, 0, sizeof(retmcu));//reference c language lib menset
//array is cleaned in here
Serial1.flush(); //Waits for the transmission of outgoing serial data to complete.
delay(1500); //Waits for respones from server
while (Serial1.available() && i < sizeof(retmcu) - 1) {
retmcu[i] = Serial1.read();//read return's value and strage in this array
str_recv.concat(String(retmcu[i]));
i++;
}
retmcu[i] = '\0'; //
str_recv.trim();
Serial.println(str_recv); //for debug
if(str_recv == "ERROR")
{
nsocl();
nsocr();
nsoco();
}
}
void mcu_get_qregswt()
{
Serial1_clearbuf(); //flush Serial1
Serial.println(F("AT+QREGSWT=2")); //
Serial1.println(F("AT+QREGSWT=2")); //send AT+CIMI command to NB-IoT module
Serial1_read(); //read the return value
}
void cfun()
{
while (1) {
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+CFUN?"));
Serial1.println(F("AT+CFUN?")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
if (strstr(retmcu, "+CFUN:1") != NULL) { //if return value is"1",reprense NB-IoT enable receive and send port,at the moment break the while
break;
} else { //or wait for return is"1"
//Do Nothing
}
}
}
void cgpaddr()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+CGPADDR=0"));
Serial1.println(F("AT+CGPADDR=0")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
}
//AT+NSOCR=STREAM,6,0,1
void nsocr()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+NSOCR=STREAM,6,0,1,AF_INET"));
Serial1.println(F("AT+NSOCR=STREAM,6,0,1,AF_INET")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
}
//AT+NSOCO=1,220.180.239.212,8009
void nsoco()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+NSOCO=1,SERVER_IP,SERVER_PORT"));
Serial1.println(F("AT+NSOCO=1,SERVER_IP,SERVER_PORT")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
}
//AT+NSOSD=1,4,01020304,0x100,101
void nsosd()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+NSOSD=1,2,AB"));
Serial1.println(F("AT+NSOSD=1,2,AB")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
}
void nsorf()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+NSORF=1,2"));
Serial1.println(F("AT+NSORF=1,2")); //send "AT+CFUN"command to NB-IoT module
Serial1_read_recv(); //read return value
}
void nsocl()
{
Serial1_clearbuf(); //clear the buffer
Serial.println(F("AT+NSOCL=1"));
Serial1.println(F("AT+NSOCL=1")); //send "AT+CFUN"command to NB-IoT module
Serial1_read(); //read return value
}
void setup() {
// put your setup code here, to run once:
Serial1.setRX(1);
Serial1.setTX(0);
Serial1.begin(BAUDRATE);
Serial.begin(BAUDRATE); // Use Serial Port for debug(config the baud of uart is 9600bps/s)
cfun();
mcu_get_qregswt();
cgpaddr();
nsocr();
nsoco();
}
unsigned long checking_time = millis();
void loop() {
nsosd();
}