43 #include "STM32CubeWL/LoRaWAN/Mac/LoRaMac.h"
44 #include "BSP/mw_log_conf.h"
45 #include "BSP/timer_if.h"
136 bool joinOTAA(String appEui, String appKey) {
return joinOTAA(appEui.c_str(), appKey.c_str()); }
137 bool joinOTAA(String appEui, String appKey, String devEui) {
return joinOTAA(appEui.c_str(), appKey.c_str(), devEui.c_str()); }
143 bool joinOTAA(uint64_t appEui, String appKey, uint64_t devEui) {
return joinOTAA(appEui, appKey.c_str(), devEui); }
180 bool joinABP(String devAddr, String nwkSKey, String appSKey) {
return joinABP(devAddr.c_str(), nwkSKey.c_str(), appSKey.c_str()); }
249 virtual size_t write(uint8_t c);
250 virtual size_t write(
const uint8_t *buffer,
size_t size);
252 template <
typename T>
inline size_t write(T val) {
return write((uint8_t *)&val,
sizeof(T)); };
329 int read(uint8_t *buf,
size_t size);
366 return mibSetHex(
"AppKey", MIB_APP_KEY, value)
374 return mibSetHex(
"NwkKey", MIB_NWK_KEY, value);
381 #if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 ))
385 return mibSetHex(
"NwkSEncKey", MIB_NWK_S_ENC_KEY, value)
386 &&
mibSetHex(
"FNwkSIntKey", MIB_F_NWK_S_INT_KEY, value)
387 &&
mibSetHex(
"SNwkSIntKey", MIB_S_NWK_S_INT_KEY, value);
389 return mibSetHex(
"NwkSKey", MIB_NWK_S_KEY, value);
394 #if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 ))
395 bool setNwkSEncKey(
const char *value) {
return mibSetHex(
"NwkSEncKey", MIB_NWK_S_ENC_KEY, value); }
396 bool setNwkSEncKey(String value) {
return setNwkSEncKey(value.c_str()); }
397 bool setFNwkSIntKey(
const char *value) {
return mibSetHex(
"FNwkSIntKey", MIB_F_NWK_S_INT_KEY, value); }
398 bool setFNwkSIntKey(String value) {
return setFNwkSIntKey(value.c_str()); }
399 bool setSNwkSIntKey(
const char *value) {
return mibSetHex(
"SNwkSIntKey", MIB_S_NWK_S_INT_KEY, value); }
400 bool setSNwkSIntKey(String value) {
return setSNwkSIntKey(value.c_str()); }
495 bool power(uint8_t index);
647 [[gnu::error(
"Not implemented in STM32LoRaWAN")]]
651 [[gnu::error(
"Not implemented in STM32LoRaWAN")]]
668 bool mibGet(
const char *name, Mib_t type, MibRequestConfirm_t &mibReq);
669 bool mibGetBool(
const char *name, Mib_t type,
bool *value);
670 bool mibGetUint8(
const char *name, Mib_t type, uint8_t *value);
671 bool mibGetInt8(
const char *name, Mib_t type, int8_t *value);
672 bool mibGetUint32(
const char *name, Mib_t type, uint32_t *value);
673 bool mibGetUint64(
const char *name, Mib_t type, uint64_t *value);
674 bool mibGetHex(
const char *name, Mib_t type, String *value);
676 bool mibGetPtr(
const char *name, Mib_t type,
void **value);
677 bool mibSet(
const char *name, Mib_t type, MibRequestConfirm_t &mibReq);
678 bool mibSetBool(
const char *name, Mib_t type,
bool value);
679 bool mibSetUint8(
const char *name, Mib_t type, uint8_t value);
680 bool mibSetInt8(
const char *name, Mib_t type, int8_t value);
681 bool mibSetUint32(
const char *name, Mib_t type, uint32_t value);
682 bool mibSetUint64(
const char *name, Mib_t type, uint64_t value);
683 bool mibSetHex(
const char *name, Mib_t type,
const char *value);
685 bool mibSetPtr(
const char *name, Mib_t type,
void *value);
686 size_t mibHexSize(
const char *name, Mib_t type);
742 bool send(
const uint8_t *payload,
size_t size,
bool confirmed);
819 bool continuousWave(uint32_t frequency, int8_t powerdBm, uint16_t timeout);
844 [[gnu::deprecated(
"minPollInterval is a no-op on STM32LoRaWAN")]]
863 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
867 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
871 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
875 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
879 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
883 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
887 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
891 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
895 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
899 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to restart")]]
903 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to poll")]]
907 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to sleep")]]
911 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to reset")]]
915 [[gnu::error(
"Not implemented in STM32LoRaWAN: No protocol stream to configure")]]
919 [[gnu::error(
"Not implemented in STM32LoRaWAN: No protocol stream to configure")]]
923 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN")]]
927 [[gnu::error(
"Not implemented in STM32LoRaWAN: Only class A supported")]]
931 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
935 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
939 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
943 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
947 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
951 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
955 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
962 [[gnu::error(
"Not implemented in STM32LoRaWAN: Changing band after initialization not supported")]]
968 static void MacMcpsIndication(McpsIndication_t *McpsIndication, LoRaMacRxStatus_t *RxStatus);
970 static void MacMlmeIndication(MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus);
985 .GetTemperatureLevel =
nullptr,
986 .GetUniqueId =
nullptr,
987 .GetDevAddress =
nullptr,
988 .NvmDataChange =
nullptr,
1000 static const char *
toString(LoRaMacStatus_t);
1002 static const char *
toString(LoRaMacEventInfoStatus_t);
1004 static const char *
toString(Mlme_t);
1006 static const char *
toString(Mcps_t);
1011 static bool parseHex(uint8_t *dest,
const char *hex,
size_t dest_len);
1013 static char toHex(uint8_t b);
1015 static bool toHex(String *dest,
const uint8_t *src,
size_t src_len);
1018 static uint32_t
makeUint32(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
return (uint32_t)a << 24 | (uint32_t)b << 16 | (uint32_t)c << 8 | (uint32_t)d << 0; }
1024 static bool failure(
const char *fmt, ...)
1025 __attribute__((
format(printf, 1, 2)));
1031 void add_rx(
const uint8_t *buf,
size_t len);
_rf_mode
Definition: STM32LoRaWAN.h:67
@ PABOOST
Definition: STM32LoRaWAN.h:69
@ RFO
Definition: STM32LoRaWAN.h:68
DeviceClass_t _lora_class
Definition: STM32LoRaWAN.h:73
_lora_band
Definition: STM32LoRaWAN.h:53
@ US915
Definition: STM32LoRaWAN.h:62
@ KR920
Definition: STM32LoRaWAN.h:60
@ AU915
Definition: STM32LoRaWAN.h:55
@ RU864
Definition: STM32LoRaWAN.h:63
@ EU868
Definition: STM32LoRaWAN.h:59
@ EU433
Definition: STM32LoRaWAN.h:58
@ CN779
Definition: STM32LoRaWAN.h:57
@ IN865
Definition: STM32LoRaWAN.h:61
@ AS923
Definition: STM32LoRaWAN.h:54
@ CN470
Definition: STM32LoRaWAN.h:56
Definition: STM32LoRaWAN.h:75
bool begin(_lora_band band, uint32_t baud, uint16_t config=SERIAL_8N2)
uint8_t getPort()
Definition: STM32LoRaWAN.cpp:263
LoRaMacPrimitives_t LoRaMacPrimitives
Definition: STM32LoRaWAN.h:976
bool joinABP(const char *devAddr, const char *nwkSKey, const char *appSKey)
Definition: STM32LoRaWAN.h:179
int getChannelMaskSize(_lora_band band)
bool setAppSKey(const char *value)
Definition: STM32LoRaWAN.h:377
bool configureClass(_lora_class _class)
bool power(_rf_mode mode, uint8_t index)
Definition: STM32LoRaWAN.h:506
bool modifyChannelEnabled(unsigned pos, bool value)
Definition: STM32LoRaWAN.cpp:358
bool mibSet(const char *name, Mib_t type, MibRequestConfirm_t &mibReq)
Definition: STM32LoRaWAN.cpp:474
uint8_t rx_port
Definition: STM32LoRaWAN.h:1046
bool getDevAddr(uint32_t *value)
Definition: STM32LoRaWAN.h:421
uint64_t builtinDevEUI()
Definition: STM32LoRaWAN.cpp:1273
bool mibGetRxChannelParams(const char *name, Mib_t type, RxChannelParams_t *value)
Definition: STM32LoRaWAN.cpp:852
bool getDevEui(String *value)
Definition: STM32LoRaWAN.h:416
int32_t getFCU()
Definition: STM32LoRaWAN.cpp:342
bool joinABP()
Definition: STM32LoRaWAN.cpp:221
bool joinOTAA(uint64_t appEui, String appKey)
Definition: STM32LoRaWAN.h:145
bool joinABP(uint32_t devAddr, String nwkSKey, String appSKey)
Definition: STM32LoRaWAN.h:181
bool setFCD(uint16_t fcd)
bool nwk_key_set
Definition: STM32LoRaWAN.h:1048
static constexpr uint32_t DEFAULT_JOIN_TIMEOUT
Definition: STM32LoRaWAN.h:1066
bool mibGetBool(const char *name, Mib_t type, bool *value)
Definition: STM32LoRaWAN.cpp:483
bool mibSetInt8(const char *name, Mib_t type, int8_t value)
Definition: STM32LoRaWAN.cpp:552
void maintain()
Definition: STM32LoRaWAN.cpp:139
uint8_t tx_port
Definition: STM32LoRaWAN.h:1043
String setTConf(String params)
bool mibSetHex(const char *name, Mib_t type, const char *value)
Definition: STM32LoRaWAN.cpp:792
uint32_t fcnt_down
Definition: STM32LoRaWAN.h:1059
bool joinOTAA()
Definition: STM32LoRaWAN.cpp:188
static void MacMcpsIndication(McpsIndication_t *McpsIndication, LoRaMacRxStatus_t *RxStatus)
Definition: STM32LoRaWAN.cpp:1293
int getADR()
Definition: STM32LoRaWAN.cpp:283
bool mibSetPtr(const char *name, Mib_t type, void *value)
Definition: STM32LoRaWAN.cpp:894
bool format(bool hexMode)
bool joinOTAAAsync()
Definition: STM32LoRaWAN.cpp:168
bool getAppEui(String *value)
Definition: STM32LoRaWAN.h:418
uint8_t lastAck()
Definition: STM32LoRaWAN.h:753
uint8_t tx_buf[255]
Definition: STM32LoRaWAN.h:1052
bool last_tx_acked
Definition: STM32LoRaWAN.h:1057
bool setDevAddr(String value)
Definition: STM32LoRaWAN.h:354
static const char * toString(LoRaMacStatus_t)
Definition: STM32LoRaWAN.cpp:947
bool mibSetUint64(const char *name, Mib_t type, uint64_t value)
Definition: STM32LoRaWAN.cpp:656
bool autoBaud(unsigned long timeout=10000L)
void beginPacket()
Definition: STM32LoRaWAN.cpp:1161
bool setDevAddr(uint32_t value)
Definition: STM32LoRaWAN.h:355
bool mac_process_pending
Definition: STM32LoRaWAN.h:1064
int parsePacket()
Definition: STM32LoRaWAN.cpp:1244
std::function< uint8_t(void)> battery_level_callback
Definition: STM32LoRaWAN.h:1062
size_t mibHexSize(const char *name, Mib_t type)
Definition: STM32LoRaWAN.cpp:678
bool connected()
Definition: STM32LoRaWAN.cpp:929
int endPacketAsync(bool confirmed=false)
Definition: STM32LoRaWAN.cpp:1165
bool dataRate(uint8_t dr)
Definition: STM32LoRaWAN.cpp:231
int getDataRate()
Definition: STM32LoRaWAN.cpp:235
bool joinOTAA(uint64_t appEui, String appKey, uint64_t devEui)
Definition: STM32LoRaWAN.h:143
bool setAppEui(String value)
Definition: STM32LoRaWAN.h:351
bool joinOTAA(const char *appEui, const char *appKey, const char *devEui)
Definition: STM32LoRaWAN.h:134
bool mibGetPtr(const char *name, Mib_t type, void **value)
Definition: STM32LoRaWAN.cpp:880
bool setAppEui(const char *value)
Definition: STM32LoRaWAN.h:350
bool setAppEui(uint64_t value)
Definition: STM32LoRaWAN.h:352
bool setRX2Freq(uint32_t freq)
Definition: STM32LoRaWAN.cpp:318
static char toHex(uint8_t b)
Definition: STM32LoRaWAN.cpp:1135
bool mibGetHex(const char *name, Mib_t type, String *value)
Definition: STM32LoRaWAN.cpp:727
static STM32LoRaWAN * instance
Definition: STM32LoRaWAN.h:974
bool mibGetUint64(const char *name, Mib_t type, uint64_t *value)
Definition: STM32LoRaWAN.cpp:631
virtual size_t write(uint8_t c)
Definition: STM32LoRaWAN.cpp:1185
static void MacMlmeIndication(MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus)
Definition: STM32LoRaWAN.cpp:1318
int getrxfreq()
Definition: STM32LoRaWAN.cpp:291
virtual void flush()
Definition: STM32LoRaWAN.h:270
bool enableChannel(unsigned pos)
Definition: STM32LoRaWAN.cpp:350
bool disableChannel(unsigned pos)
Definition: STM32LoRaWAN.cpp:354
static void MacMcpsConfirm(McpsConfirm_t *McpsConfirm)
Definition: STM32LoRaWAN.cpp:1277
bool joinOTAA(String appEui, String appKey, String devEui)
Definition: STM32LoRaWAN.h:137
String deviceEUI()
Definition: STM32LoRaWAN.cpp:939
static void MacProcessNotify()
Definition: STM32LoRaWAN.cpp:120
int endPacket(bool confirmed=false)
Definition: STM32LoRaWAN.cpp:1174
bool mibSetRxChannelParams(const char *name, Mib_t type, RxChannelParams_t value)
Definition: STM32LoRaWAN.cpp:867
bool joinABP(String devAddr, String nwkSKey, String appSKey)
Definition: STM32LoRaWAN.h:180
int32_t getFCD()
Definition: STM32LoRaWAN.cpp:346
bool mibGetInt8(const char *name, Mib_t type, int8_t *value)
Definition: STM32LoRaWAN.cpp:533
LoRaMacCallback_t LoRaMacCallbacks
Definition: STM32LoRaWAN.h:983
virtual int availableForWrite()
Definition: STM32LoRaWAN.cpp:1201
bool configureBand(_lora_band band)
bool setNwkKey(String value)
Definition: STM32LoRaWAN.h:376
bool setNwkKey(const char *value)
Definition: STM32LoRaWAN.h:371
bool mibGetUint32(const char *name, Mib_t type, uint32_t *value)
Definition: STM32LoRaWAN.cpp:569
bool setAppSKey(String value)
Definition: STM32LoRaWAN.h:378
bool getAppEui(uint64_t *value)
Definition: STM32LoRaWAN.h:419
virtual int peek()
Definition: STM32LoRaWAN.cpp:1238
void setBaud(unsigned long baud)
bool setNwkSKey(String value)
Definition: STM32LoRaWAN.h:392
virtual int available()
Definition: STM32LoRaWAN.cpp:1228
bool joinOTAA(uint64_t appEui, const char *appKey)
Definition: STM32LoRaWAN.h:141
virtual int read()
Definition: STM32LoRaWAN.cpp:1232
bool getDevEui(uint64_t *value)
Definition: STM32LoRaWAN.h:417
bool mibSetUint8(const char *name, Mib_t type, uint8_t value)
Definition: STM32LoRaWAN.cpp:522
bool isChannelEnabled(unsigned pos)
Definition: STM32LoRaWAN.cpp:388
size_t write(T val)
Definition: STM32LoRaWAN.h:252
bool setDevEui(String value)
Definition: STM32LoRaWAN.h:348
static uint8_t parseHex(char c)
Definition: STM32LoRaWAN.cpp:1105
bool setFCU(uint16_t fcu)
void setBatteryLevelCallback(std::function< uint8_t(void)> callback)
Definition: STM32LoRaWAN.h:804
bool busy()
Definition: STM32LoRaWAN.cpp:935
String version()
Definition: STM32LoRaWAN.h:837
bool setDevEui(uint64_t value)
Definition: STM32LoRaWAN.h:349
static uint32_t makeUint32(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Definition: STM32LoRaWAN.h:1018
bool setAppKey(const char *value)
Definition: STM32LoRaWAN.h:356
static uint8_t GetBatteryLevel()
Definition: STM32LoRaWAN.cpp:128
bool continuousWave(uint32_t frequency, int8_t powerdBm, uint16_t timeout)
Definition: STM32LoRaWAN.cpp:154
bool setDevAddr(const char *value)
Definition: STM32LoRaWAN.h:353
uint8_t tx_dr
Definition: STM32LoRaWAN.h:1040
uint8_t * tx_ptr
Definition: STM32LoRaWAN.h:1053
uint8_t rx_buf[255]
Definition: STM32LoRaWAN.h:1054
bool mibGet(const char *name, Mib_t type, MibRequestConfirm_t &mibReq)
Definition: STM32LoRaWAN.cpp:465
static bool void clear_rx()
Definition: STM32LoRaWAN.h:1028
bool powerdB(int8_t db)
Definition: STM32LoRaWAN.cpp:246
uint32_t fcnt_up
Definition: STM32LoRaWAN.h:1058
bool begin(_lora_band band)
Definition: STM32LoRaWAN.cpp:62
bool send(const uint8_t *payload, size_t size, bool confirmed)
Definition: STM32LoRaWAN.cpp:412
bool dutyCycle(bool on)
Definition: STM32LoRaWAN.cpp:253
void add_rx(const uint8_t *buf, size_t len)
Definition: STM32LoRaWAN.cpp:1249
std::function< void(void)> maintain_needed_callback
Definition: STM32LoRaWAN.h:1061
bool mibSetBool(const char *name, Mib_t type, bool value)
Definition: STM32LoRaWAN.cpp:497
bool mibSetUint32(const char *name, Mib_t type, uint32_t value)
Definition: STM32LoRaWAN.cpp:601
bool power(uint8_t index)
Definition: STM32LoRaWAN.cpp:242
uint32_t getRX2Freq()
Definition: STM32LoRaWAN.cpp:311
bool mibGetUint8(const char *name, Mib_t type, uint8_t *value)
Definition: STM32LoRaWAN.cpp:509
uint8_t * rx_ptr
Definition: STM32LoRaWAN.h:1055
void minPollInterval(unsigned long)
Definition: STM32LoRaWAN.h:845
static void MacMlmeConfirm(MlmeConfirm_t *MlmeConfirm)
Definition: STM32LoRaWAN.cpp:1310
static bool failure(const char *fmt,...) __attribute__((format(printf
Definition: STM32LoRaWAN.cpp:1153
bool setADR(bool adr)
Definition: STM32LoRaWAN.cpp:279
bool setRX2DR(uint8_t dr)
Definition: STM32LoRaWAN.cpp:302
bool joinOTAA(uint64_t appEui, const char *appKey, uint64_t devEui)
Definition: STM32LoRaWAN.h:139
uint8_t getDownlinkPort()
Definition: STM32LoRaWAN.h:301
void setMaintainNeededCallback(std::function< void(void)> callback)
Definition: STM32LoRaWAN.h:791
int getRX2DR()
Definition: STM32LoRaWAN.cpp:295
bool sendMask(String newMask)
bool setAppKey(String value)
Definition: STM32LoRaWAN.h:370
bool setPort(uint8_t port)
Definition: STM32LoRaWAN.cpp:258
bool joinOTAA(String appEui, String appKey)
Definition: STM32LoRaWAN.h:136
bool getDevAddr(String *value)
Definition: STM32LoRaWAN.h:420
bool setDevEui(const char *value)
Definition: STM32LoRaWAN.h:347
bool setNwkSKey(const char *value)
Definition: STM32LoRaWAN.h:379
bool joinOTAA(const char *appEui, const char *appKey)
Definition: STM32LoRaWAN.h:135
bool publicNetwork(bool publicNetwork)
Definition: STM32LoRaWAN.cpp:274
void maintainUntilIdle()
Definition: STM32LoRaWAN.cpp:147