RAK3172 not receiving message class C






#define Uart1BaudRate  115200

String comdata = "";
//char * buf1 = "AT+APPEUI=48FF000000000008\r\n";
//char * buf2 = "AT+DEVEUI=48E663FFFE300008\r\n";
//char * buf3 = "AT+APPSKEY=64A60D27D87E88D65BD7E0B734EDE2F0\r\n";
char * buf4 = "AT+JOIN=1:0:10:8\r\n";
char * buf5 = "AT+VER=?\r\n";

char * buf1 = "AT+APPEUI=5E9D1E0857CF25F1\r\n";
char * buf2 = "AT+DEVEUI=5E9D1E0857CF25F1\r\n";
char * buf3 = "AT+APPKEY=F921D50CD7D02EE3C5E6142154F274B2\r\n";

char * buf6 = "AT+APPEUI=?\r\n";
char * buf7 = "AT+DEVEUI=?\r\n";
char * buf8 = "AT+APPKEY=?\r\n";

char * buf9 = "AT+VER=?\r\n";
char * buf10 = "AT+CLASS=A\r\n";
char * buf11 = "AT+NJM=1\r\n";
char * buf12 = "AT+BAND=5\r\n";
char * buf13 = "AT+NWM=1\r\n";
char * buf14 = "AT+MASK=0002\r\n";
char * buf15 = "AT+CHE=1:2:3:4:5:6:7:8\r\n";
char * buf16 = "AT+CFM=0\r\n";
char * buf17 = "AT+SEND=2:1234\r\n";
char * buf18 = "AT+RECV=?\r\n";

char * buf19 = "AT+DCS=1\r\n";
char * buf20 = "AT+CFS=?\r\n";
char * buf21 = "ATR\r\n";
char * buf22 = "AT+ADR=1\r\n";




void sendCommand(const char* cmd) {
  Serial1.write(cmd);  // Komutu gönder
  delay(2000);  // Yeterli zaman ver
  String response = "";  // Yanıtı tutacak string
  while (Serial1.available() > 0) {
    response += char(Serial1.read());  // Yanıtı oku
  }
  if (response.length() > 0) {
    Serial.println(response);  // Yanıtı seri porttan yazdır
  }
}

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, 18, 17);
  delay(1500);
 
  //sendCommand(buf21); 
  sendCommand("ATR\r\n");
  delay(3000);
  sendCommand("ATE\r\n");
  delay(1000);
  sendCommand("AT+VER=?\r\n");
  delay(1500);
  sendCommand("AT+DEBUG=0\r\n");
  delay(1500);
  sendCommand("AT+NWM=1\r\n");
  delay(1000);
  sendCommand("AT+NJM=1\r\n");
  delay(1000);
  sendCommand("AT+CLASS=C\r\n");
  delay(1000);
  sendCommand("AT+BAND=5\r\n");
  delay(1000);
  sendCommand("AT+MASK=0002\r\n");
  delay(1000);
  sendCommand("AT+ADR=1\r\n");
  delay(1000);
  sendCommand("AT+CFM=0\r\n");
  delay(1000);
  sendCommand("AT+CHS=904900000\r\n");
  delay(1000);
  sendCommand("AT+RX2FQ=?\r\n");
  delay(1000);
 // sendCommand("AT+JN2DL=6\r\n");
 /// delay(1000);
 // sendCommand("AT+RX1DL=5\r\n");
 // delay(1000);
 // sendCommand("AT+RX2DL=5\r\n");
 // delay(1000);
 // sendCommand("AT+RX2DR=8\r\n");
 // delay(1000);
 //sendCommand("AT+RX2FQ=923300000\r\n");
  //delay(1000);
  //sendCommand("AT+TTX=4\r\n");
  //delay(1000);
  sendCommand("AT+DEVEUI=5E9D1E0857CF25C1\r\n");
  delay(1000);
  sendCommand("AT+APPEUI=5E9D1E0857CF25C1\r\n");
  delay(1000);
  sendCommand("AT+APPKEY=F921D50CD7D02EE3C5E6142154F274C2\r\n");
  delay(1000);
  sendCommand("AT+JOIN=1:0:10:8\r\n");
  delay(1000);



  // Diğer komutlarınızı da ekleyebilirsiniz
}
unsigned long previousMillis = 0;  // Son gönderim zamanını takip eder
const unsigned long interval = 60000;  // 60 saniye (60000 ms)
void loop() {
  // Yine komutları gönderebilirsiniz
 // sendCommand(buf17);  // AT+SEND komutunu gönder
  //delay(1000);  // Sabit bir gecikme ile tekrar gönderim yapabilirsiniz


 // sendCommand(buf17);
 // delay(10000);
 unsigned long currentMillis = millis();

  // 60 saniyede bir `sendCommand` çalıştır
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;  // Zamanlayıcıyı sıfırla
    sendCommand("AT+SEND=2:0103080404\r\n");
  }

  //  sendCommand("AT+RECV=?\r\n");
 // delay(1000);
   // sendCommand("AT+NJS=?\r\n");
 // UART üzerinden gelen veriyi oku
  if (Serial1.available() > 0) {
    comdata = "";
    while (Serial1.available() > 0) {
      comdata += char(Serial1.read()); // Veriyi oku
      delay(2);
    }

    if (comdata.length() > 0) {
      // Gelen veriyi konsola yazdır
      Serial.println("Received data: ");
      Serial.println(comdata);
    }
  }

  delay(10); // Delay, stabilite için

}

I sent 5 messages from chirpstack to end device but it only receives 1 of them
sometimes my messages are never delivered

Are you using RAK3172 as an UART module to another MCU?

yes, im using rak3172 with esp32s3

Is the device setup as Class C in your LNS?

im using chirpstack v4.10 and i created class c profile. do I need any other settings ?

After you send a packet, I don’t see any processing for the response. You just assume a delay of 2000ms is enough and that the sending is always ok.

You are not checking (anymore) if a packet was received with “AT+RECV=?” (you commented it out) instead you are hoping that after 2 seconds some data was received.

That is a quite unreliable method.

(1) After sending a packet, wait for “OK”, then wait for “+EVT:SEND_CONFIRMED_OK” (if you use confirmed mode) or " +EVT:TX_DONE" (if you use unconfirmed mode) or any other error response
(2) Check with AT+RECV=? for 10 seconds (at least) if you got a downlink.

You may want to check if the frequency and datarate of RX2 in your RAK and ChirpStack.

To see if they match.

Can’t I listen continuously without sending packets in class C? Do I need to send packets?

i checked same freq both sir



AT+RECV=0:
OK

AT+SEND=2:0103080404

QueryTxPossible: OK, UserDataSize 5 PossibleDataSize 11 AdditionalFOptsSize 0
Frequency:902300000
Rx1Frequency:902500000
RxCFrequency:923300000
RxC Datarate:8
ChannelsDatarate:0
AdrAckCounter:0
ChannelsTxPower:0
OK

AT+RECV=?

AT+RECV=0:
OK

AT+RECV=?

AT+RECV=0:
OK
+EVT:SEND_CONFIRMED_FAILED(4)

AT+RECV=?

AT+RECV=0:
OK

AT+RECV=?

AT+RECV=0:
OK

AT+RECV=?

AT+RECV=0:
OK

i sended 10 message but just arrived 2 message

AT+RECV=?

AT+RECV=0:
OK

AT+RECV=?

AT+RECV=0:
OK
+EVT:RX_C:-41:3:UNICAST:1:3232
Frequency:902300000
Rx1Frequency:902500000
RxCFrequency:923300000
RxC Datarate:8
ChannelsDatarate:0
AdrAckCounter:1
ChannelsTxPower:0

AT+RECV=?

AT+RECV=1:3232
OK

AT+RECV=?

AT+RECV=0:
OK

You have to check the logs in your gateway to see if the packets were really sent by the LNS.

Instead of using your ESP32, connect a serial terminal with a TTL-USB adapter and check if the packets arrive. I still have a feeling that your flow on the ESP32 might miss something.

I don’t think the problem is in the esp. I see that some of the messages I send from rak3172 never reach the LNS.
When I make the single channel , the messages reach the LNS.