Hi,
Our sensor based on the RAK3172 is almost finalized but I have just encountered a problem with the acknowledgment of uplink messages.
The RAK is awakened by an external signal. This signal can come from an external RTC (RV-3028-C7) or from a magnet passing in front of a reed switch (measurement forced by the user when installing the sensor).
The program (very simplified) is as follows:
#include "RV-3028-C7.h"
#define WAKEUP_PIN PA0
#define REED_PIN PA8
#define LED_PIN PA9
// RTC
RV3028 rtc;
// --------------------------------------------------------------------------------
// rtc_wakeup
// --------------------------------------------------------------------------------
void rtc_wakeup()
{
measurement(); // <-- the message following this measurement is not acknowledged (callback TX status = 4)**
}
// --------------------------------------------------------------------------------
// reed_wakeup
// --------------------------------------------------------------------------------
void reed_wakeup()
{
measurement(); // <-- the message following this measurement is not acknowledged (callback TX status = 4)**
}
// --------------------------------------------------------------------------------
// send_packet
// --------------------------------------------------------------------------------
void send_packet(time_t timestamp, ushort p1, ushort p2, ushort p3, ushort iTemp1, ushort iTemp2, ushort iTemp3, ushort iVBatt)
{
uint8_t payload[16] = {};
[...]
if (api.lorawan.njs.get() == 1)
{
if (api.lorawan.send(sizeof(payload), payload, 2, true, 1))
{
Serial1.println("Send Success");
msg_count++;
}
else
{
Serial1.println("Send fail");
}
}
}
// --------------------------------------------------------------------------------
// measurement
// --------------------------------------------------------------------------------
void measurement()
{
ushort p1;
ushort p2;
ushort p3;
ushort iTemp1;
ushort iTemp2;
ushort iTemp3;
ushort iVBatt;
[...]
send_packet(time_now_epoch, p1, p2, p3, iTemp1, iTemp2, iTemp3, iVBatt);
}
// --------------------------------------------------------------------------------
// joinCallback
// --------------------------------------------------------------------------------
void joinCallback(int32_t status)
{
[...]
}
// --------------------------------------------------------------------------------
// sendCallback
// --------------------------------------------------------------------------------
void sendCallback(int32_t status)
{
Serial1.printf("TX-CB - TX status %d \r\n", status);
}
// --------------------------------------------------------------------------------
// linkcheckCallback
// --------------------------------------------------------------------------------
void linkcheckCallback(SERVICE_LORA_LINKCHECK_T *data)
{
[...]
}
// --------------------------------------------------------------------------------
// timeReqCallback
// --------------------------------------------------------------------------------
void timeReqCallback(int32_t status)
{
[...]
}
// --------------------------------------------------------------------------------
// receiveCallback
// --------------------------------------------------------------------------------
void receiveCallback(SERVICE_LORA_RECEIVE_T *data)
{
Serial1.printf("RX-CB - RX, port %d, DR %d, RSSI %d, SNR %d", data->Port, data->RxDatarate, data->Rssi, data->Snr);
[...]
}
// --------------------------------------------------------------------------------
// setup
// --------------------------------------------------------------------------------
void setup()
{
delay(5000);
[...]
// Band = EU868
Serial1.printf("Set LoRa region EU868 %s\r\n", api.lorawan.band.set(4) ? "Success" : "Fail");
// Class = A
Serial1.printf("Set class A %s\r\n", api.lorawan.deviceClass.set(0) ? "Success" : "Fail");
// Join mode = OTAA
Serial1.printf("Set network join mode OTAA %s\n\r", api.lorawan.njm.set(1) ? "Success" : "Fail");
// Confirm mode disabled
Serial1.printf("Set confirm mode status enabled %s\n\r", api.lorawan.cfm.set(2) ? "Success" : "Fail");
// Adaptive data rate enabled
Serial1.printf("Set adaptive data rate %s\n\r", api.lorawan.adr.set(true) ? "Success" : "Fail");
// Data rate
Serial1.printf("Get data rate : %d\r\n", api.lorawan.dr.get());
// Linkcheck status
Serial1.printf("Set Verifying network link status 0 %s\r\n", api.lorawan.linkcheck.set(0) ? "Success" : "Fail");
api.lorawan.registerJoinCallback(joinCallback);
api.lorawan.registerSendCallback(sendCallback);
api.lorawan.registerRecvCallback(receiveCallback);
api.lorawan.registerLinkCheckCallback(linkcheckCallback);
api.lorawan.registerTimereqCallback(timeReqCallback);
while (api.lorawan.njs.get() == 0)
{
Serial1.printf("LoRaWan OTAA join ...\r\n");
api.lorawan.join();
delay(10000);
}
service_lora_set_timereq(1);
// Reed switch
pinMode(REED_PIN, INPUT_PULLDOWN);
attachInterrupt(digitalPinToInterrupt(REED_PIN), reed_wakeup, RISING);
[...]
// RTC Wake up
pinMode(WAKEUP_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(WAKEUP_PIN), rtc_wakeup, FALLING);
measurement(); // <-- the message following this measurement is successfully acknowledged (callback TX status = 0)**
}
// --------------------------------------------------------------------------------
// loop
// --------------------------------------------------------------------------------
void loop()
{
api.system.sleep.all();
}
When the measurement is launched from setup, the uplink message is acknowledged by the server (ChirpStack) and the status in the callback (sendCallback) is equal to 0. Good !
When the measurement is triggered by the external RTC or by the Reed switch, the message is sent and acknowledged by the server but the status given by the callback is equal to 4. Which seems to be an RX2 timeout. Not good !
Is it possible that waking up the RAK by an external signal rather than by a Timer (eg RAK_TIMER_0) could impact the reception of the ACK downlink from the server?
I’ve been racking my brains for hours! Thanks for your help.
Joch