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)); };
339 int read(uint8_t *buf,
size_t size);
376 return mibSetHex(
"AppKey", MIB_APP_KEY, value)
384 return mibSetHex(
"NwkKey", MIB_NWK_KEY, value);
391#if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 ))
395 return mibSetHex(
"NwkSEncKey", MIB_NWK_S_ENC_KEY, value)
396 &&
mibSetHex(
"FNwkSIntKey", MIB_F_NWK_S_INT_KEY, value)
397 &&
mibSetHex(
"SNwkSIntKey", MIB_S_NWK_S_INT_KEY, value);
399 return mibSetHex(
"NwkSKey", MIB_NWK_S_KEY, value);
404#if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 ))
405 bool setNwkSEncKey(
const char *value) {
return mibSetHex(
"NwkSEncKey", MIB_NWK_S_ENC_KEY, value); }
406 bool setNwkSEncKey(String value) {
return setNwkSEncKey(value.c_str()); }
407 bool setFNwkSIntKey(
const char *value) {
return mibSetHex(
"FNwkSIntKey", MIB_F_NWK_S_INT_KEY, value); }
408 bool setFNwkSIntKey(String value) {
return setFNwkSIntKey(value.c_str()); }
409 bool setSNwkSIntKey(
const char *value) {
return mibSetHex(
"SNwkSIntKey", MIB_S_NWK_S_INT_KEY, value); }
410 bool setSNwkSIntKey(String value) {
return setSNwkSIntKey(value.c_str()); }
505 bool power(uint8_t index);
657 [[gnu::error(
"Not implemented in STM32LoRaWAN")]]
661 [[gnu::error(
"Not implemented in STM32LoRaWAN")]]
678 bool mibGet(
const char *name, Mib_t type, MibRequestConfirm_t &mibReq);
679 bool mibGetBool(
const char *name, Mib_t type,
bool *value);
680 bool mibGetUint8(
const char *name, Mib_t type, uint8_t *value);
681 bool mibGetInt8(
const char *name, Mib_t type, int8_t *value);
682 bool mibGetUint32(
const char *name, Mib_t type, uint32_t *value);
683 bool mibGetUint64(
const char *name, Mib_t type, uint64_t *value);
684 bool mibGetHex(
const char *name, Mib_t type, String *value);
686 bool mibGetPtr(
const char *name, Mib_t type,
void **value);
687 bool mibSet(
const char *name, Mib_t type, MibRequestConfirm_t &mibReq);
688 bool mibSetBool(
const char *name, Mib_t type,
bool value);
689 bool mibSetUint8(
const char *name, Mib_t type, uint8_t value);
690 bool mibSetInt8(
const char *name, Mib_t type, int8_t value);
691 bool mibSetUint32(
const char *name, Mib_t type, uint32_t value);
692 bool mibSetUint64(
const char *name, Mib_t type, uint64_t value);
693 bool mibSetHex(
const char *name, Mib_t type,
const char *value);
695 bool mibSetPtr(
const char *name, Mib_t type,
void *value);
696 size_t mibHexSize(
const char *name, Mib_t type);
752 bool send(
const uint8_t *payload,
size_t size,
bool confirmed);
829 bool continuousWave(uint32_t frequency, int8_t powerdBm, uint16_t timeout);
854 [[gnu::deprecated(
"minPollInterval is a no-op on STM32LoRaWAN")]]
873 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
877 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
881 [[gnu::error(
"Not implemented in STM32LoRaWAN: confirmed uplinked better handled through endPacket()")]]
885 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
889 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
893 [[gnu::error(
"Not implemented in STM32LoRaWAN: No serial to configure")]]
897 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
901 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
905 [[gnu::error(
"Not implemented in STM32LoRaWAN: Test method")]]
909 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to restart")]]
913 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to poll")]]
917 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to sleep")]]
921 [[gnu::error(
"Not implemented in STM32LoRaWAN: No remote module to reset")]]
925 [[gnu::error(
"Not implemented in STM32LoRaWAN: No protocol stream to configure")]]
929 [[gnu::error(
"Not implemented in STM32LoRaWAN: No protocol stream to configure")]]
933 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN")]]
937 [[gnu::error(
"Not implemented in STM32LoRaWAN: Only class A supported")]]
941 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
945 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
949 [[gnu::error(
"Not implemented in STM32LoRaWAN: Keys cannot be retrieved")]]
953 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
957 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
961 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
965 [[gnu::error(
"Not implemented in STM32LoRaWAN: Internal method in MKRWAN (use enableChannel/disableChannel instead)")]]
972 [[gnu::error(
"Not implemented in STM32LoRaWAN: Changing band after initialization not supported")]]
978 static void MacMcpsIndication(McpsIndication_t *McpsIndication, LoRaMacRxStatus_t *RxStatus);
980 static void MacMlmeIndication(MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus);
995 .GetTemperatureLevel =
nullptr,
996 .GetUniqueId =
nullptr,
997 .GetDevAddress =
nullptr,
998 .NvmDataChange =
nullptr,
1010 static const char *
toString(LoRaMacStatus_t);
1012 static const char *
toString(LoRaMacEventInfoStatus_t);
1014 static const char *
toString(Mlme_t);
1016 static const char *
toString(Mcps_t);
1021 static bool parseHex(uint8_t *dest,
const char *hex,
size_t dest_len);
1023 static char toHex(uint8_t b);
1025 static bool toHex(String *dest,
const uint8_t *src,
size_t src_len);
1028 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; }
1034 static bool failure(
const char *fmt, ...)
1035 __attribute__((
format(printf, 1, 2)));
1041 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:281
LoRaMacPrimitives_t LoRaMacPrimitives
Definition STM32LoRaWAN.h:986
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:387
bool configureClass(_lora_class _class)
bool power(_rf_mode mode, uint8_t index)
Definition STM32LoRaWAN.h:516
bool modifyChannelEnabled(unsigned pos, bool value)
Definition STM32LoRaWAN.cpp:394
bool mibSet(const char *name, Mib_t type, MibRequestConfirm_t &mibReq)
Definition STM32LoRaWAN.cpp:526
uint8_t rx_port
Definition STM32LoRaWAN.h:1056
bool getDevAddr(uint32_t *value)
Definition STM32LoRaWAN.h:431
uint64_t builtinDevEUI()
Definition STM32LoRaWAN.cpp:1390
bool mibGetRxChannelParams(const char *name, Mib_t type, RxChannelParams_t *value)
Definition STM32LoRaWAN.cpp:929
bool getDevEui(String *value)
Definition STM32LoRaWAN.h:426
int32_t getFCU()
Definition STM32LoRaWAN.cpp:374
bool joinABP()
Definition STM32LoRaWAN.cpp:230
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:1064
static constexpr uint32_t DEFAULT_JOIN_TIMEOUT
Definition STM32LoRaWAN.h:1082
bool mibGetBool(const char *name, Mib_t type, bool *value)
Definition STM32LoRaWAN.cpp:537
bool mibSetInt8(const char *name, Mib_t type, int8_t value)
Definition STM32LoRaWAN.cpp:614
void maintain()
Definition STM32LoRaWAN.cpp:144
uint8_t tx_port
Definition STM32LoRaWAN.h:1053
String setTConf(String params)
bool mibSetHex(const char *name, Mib_t type, const char *value)
Definition STM32LoRaWAN.cpp:866
uint32_t fcnt_down
Definition STM32LoRaWAN.h:1075
bool joinOTAA()
Definition STM32LoRaWAN.cpp:196
static void MacMcpsIndication(McpsIndication_t *McpsIndication, LoRaMacRxStatus_t *RxStatus)
Definition STM32LoRaWAN.cpp:1412
int getADR()
Definition STM32LoRaWAN.cpp:304
bool mibSetPtr(const char *name, Mib_t type, void *value)
Definition STM32LoRaWAN.cpp:976
bool format(bool hexMode)
bool joinOTAAAsync()
Definition STM32LoRaWAN.cpp:175
bool getAppEui(String *value)
Definition STM32LoRaWAN.h:428
uint8_t lastAck()
Definition STM32LoRaWAN.h:763
uint8_t tx_buf[255]
Definition STM32LoRaWAN.h:1068
bool last_tx_acked
Definition STM32LoRaWAN.h:1073
bool setDevAddr(String value)
Definition STM32LoRaWAN.h:364
int8_t getDownlinkSnr()
Definition STM32LoRaWAN.h:311
static const char * toString(LoRaMacStatus_t)
Definition STM32LoRaWAN.cpp:1033
bool mibSetUint64(const char *name, Mib_t type, uint64_t value)
Definition STM32LoRaWAN.cpp:722
bool autoBaud(unsigned long timeout=10000L)
void beginPacket()
Definition STM32LoRaWAN.cpp:1257
bool setDevAddr(uint32_t value)
Definition STM32LoRaWAN.h:365
bool mac_process_pending
Definition STM32LoRaWAN.h:1080
int parsePacket()
Definition STM32LoRaWAN.cpp:1359
std::function< uint8_t(void)> battery_level_callback
Definition STM32LoRaWAN.h:1078
size_t mibHexSize(const char *name, Mib_t type)
Definition STM32LoRaWAN.cpp:745
bool connected()
Definition STM32LoRaWAN.cpp:1012
int endPacketAsync(bool confirmed=false)
Definition STM32LoRaWAN.cpp:1262
bool dataRate(uint8_t dr)
Definition STM32LoRaWAN.cpp:242
int getDataRate()
Definition STM32LoRaWAN.cpp:247
bool joinOTAA(uint64_t appEui, String appKey, uint64_t devEui)
Definition STM32LoRaWAN.h:143
bool setAppEui(String value)
Definition STM32LoRaWAN.h:361
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:960
bool setAppEui(const char *value)
Definition STM32LoRaWAN.h:360
bool setAppEui(uint64_t value)
Definition STM32LoRaWAN.h:362
bool setRX2Freq(uint32_t freq)
Definition STM32LoRaWAN.cpp:348
static char toHex(uint8_t b)
Definition STM32LoRaWAN.cpp:1227
bool mibGetHex(const char *name, Mib_t type, String *value)
Definition STM32LoRaWAN.cpp:795
static STM32LoRaWAN * instance
Definition STM32LoRaWAN.h:984
bool mibGetUint64(const char *name, Mib_t type, uint64_t *value)
Definition STM32LoRaWAN.cpp:697
virtual size_t write(uint8_t c)
Definition STM32LoRaWAN.cpp:1286
int16_t getDownlinkRssi()
Definition STM32LoRaWAN.h:306
static void MacMlmeIndication(MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus)
Definition STM32LoRaWAN.cpp:1441
int getrxfreq()
Definition STM32LoRaWAN.cpp:314
virtual void flush()
Definition STM32LoRaWAN.h:270
bool enableChannel(unsigned pos)
Definition STM32LoRaWAN.cpp:384
bool disableChannel(unsigned pos)
Definition STM32LoRaWAN.cpp:389
static void MacMcpsConfirm(McpsConfirm_t *McpsConfirm)
Definition STM32LoRaWAN.cpp:1395
bool joinOTAA(String appEui, String appKey, String devEui)
Definition STM32LoRaWAN.h:137
String deviceEUI()
Definition STM32LoRaWAN.cpp:1024
static void MacProcessNotify()
Definition STM32LoRaWAN.cpp:124
int endPacket(bool confirmed=false)
Definition STM32LoRaWAN.cpp:1273
bool mibSetRxChannelParams(const char *name, Mib_t type, RxChannelParams_t value)
Definition STM32LoRaWAN.cpp:946
bool joinABP(String devAddr, String nwkSKey, String appSKey)
Definition STM32LoRaWAN.h:180
int32_t getFCD()
Definition STM32LoRaWAN.cpp:379
bool mibGetInt8(const char *name, Mib_t type, int8_t *value)
Definition STM32LoRaWAN.cpp:593
LoRaMacCallback_t LoRaMacCallbacks
Definition STM32LoRaWAN.h:993
virtual int availableForWrite()
Definition STM32LoRaWAN.cpp:1306
bool configureBand(_lora_band band)
bool setNwkKey(String value)
Definition STM32LoRaWAN.h:386
bool setNwkKey(const char *value)
Definition STM32LoRaWAN.h:381
bool mibGetUint32(const char *name, Mib_t type, uint32_t *value)
Definition STM32LoRaWAN.cpp:632
bool setAppSKey(String value)
Definition STM32LoRaWAN.h:388
bool getAppEui(uint64_t *value)
Definition STM32LoRaWAN.h:429
virtual int peek()
Definition STM32LoRaWAN.cpp:1351
void setBaud(unsigned long baud)
bool setNwkSKey(String value)
Definition STM32LoRaWAN.h:402
virtual int available()
Definition STM32LoRaWAN.cpp:1338
bool joinOTAA(uint64_t appEui, const char *appKey)
Definition STM32LoRaWAN.h:141
virtual int read()
Definition STM32LoRaWAN.cpp:1343
bool getDevEui(uint64_t *value)
Definition STM32LoRaWAN.h:427
bool mibSetUint8(const char *name, Mib_t type, uint8_t value)
Definition STM32LoRaWAN.cpp:581
bool isChannelEnabled(unsigned pos)
Definition STM32LoRaWAN.cpp:430
size_t write(T val)
Definition STM32LoRaWAN.h:252
bool setDevEui(String value)
Definition STM32LoRaWAN.h:358
static uint8_t parseHex(char c)
Definition STM32LoRaWAN.cpp:1195
bool setFCU(uint16_t fcu)
void setBatteryLevelCallback(std::function< uint8_t(void)> callback)
Definition STM32LoRaWAN.h:814
bool busy()
Definition STM32LoRaWAN.cpp:1019
String version()
Definition STM32LoRaWAN.h:847
bool setDevEui(uint64_t value)
Definition STM32LoRaWAN.h:359
static uint32_t makeUint32(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Definition STM32LoRaWAN.h:1028
bool setAppKey(const char *value)
Definition STM32LoRaWAN.h:366
static uint8_t GetBatteryLevel()
Definition STM32LoRaWAN.cpp:133
bool continuousWave(uint32_t frequency, int8_t powerdBm, uint16_t timeout)
Definition STM32LoRaWAN.cpp:159
bool setDevAddr(const char *value)
Definition STM32LoRaWAN.h:363
uint8_t tx_dr
Definition STM32LoRaWAN.h:1050
uint8_t * tx_ptr
Definition STM32LoRaWAN.h:1069
uint8_t rx_buf[255]
Definition STM32LoRaWAN.h:1070
bool mibGet(const char *name, Mib_t type, MibRequestConfirm_t &mibReq)
Definition STM32LoRaWAN.cpp:515
static bool void clear_rx()
Definition STM32LoRaWAN.h:1038
bool powerdB(int8_t db)
Definition STM32LoRaWAN.cpp:261
uint32_t fcnt_up
Definition STM32LoRaWAN.h:1074
bool begin(_lora_band band)
Definition STM32LoRaWAN.cpp:62
bool send(const uint8_t *payload, size_t size, bool confirmed)
Definition STM32LoRaWAN.cpp:459
bool dutyCycle(bool on)
Definition STM32LoRaWAN.cpp:269
void add_rx(const uint8_t *buf, size_t len)
Definition STM32LoRaWAN.cpp:1365
std::function< void(void)> maintain_needed_callback
Definition STM32LoRaWAN.h:1077
bool mibSetBool(const char *name, Mib_t type, bool value)
Definition STM32LoRaWAN.cpp:553
bool mibSetUint32(const char *name, Mib_t type, uint32_t value)
Definition STM32LoRaWAN.cpp:666
bool power(uint8_t index)
Definition STM32LoRaWAN.cpp:256
uint32_t getRX2Freq()
Definition STM32LoRaWAN.cpp:339
bool mibGetUint8(const char *name, Mib_t type, uint8_t *value)
Definition STM32LoRaWAN.cpp:566
uint8_t * rx_ptr
Definition STM32LoRaWAN.h:1071
void minPollInterval(unsigned long)
Definition STM32LoRaWAN.h:855
static void MacMlmeConfirm(MlmeConfirm_t *MlmeConfirm)
Definition STM32LoRaWAN.cpp:1432
static bool failure(const char *fmt,...) __attribute__((format(printf
Definition STM32LoRaWAN.cpp:1248
bool setADR(bool adr)
Definition STM32LoRaWAN.cpp:299
bool setRX2DR(uint8_t dr)
Definition STM32LoRaWAN.cpp:328
bool joinOTAA(uint64_t appEui, const char *appKey, uint64_t devEui)
Definition STM32LoRaWAN.h:139
uint8_t getDownlinkPort()
Definition STM32LoRaWAN.h:301
int8_t rx_snr
Definition STM32LoRaWAN.h:1062
void setMaintainNeededCallback(std::function< void(void)> callback)
Definition STM32LoRaWAN.h:801
int getRX2DR()
Definition STM32LoRaWAN.cpp:319
bool sendMask(String newMask)
int16_t rx_rssi
Definition STM32LoRaWAN.h:1059
bool setAppKey(String value)
Definition STM32LoRaWAN.h:380
bool setPort(uint8_t port)
Definition STM32LoRaWAN.cpp:275
bool joinOTAA(String appEui, String appKey)
Definition STM32LoRaWAN.h:136
bool getDevAddr(String *value)
Definition STM32LoRaWAN.h:430
bool setDevEui(const char *value)
Definition STM32LoRaWAN.h:357
bool setNwkSKey(const char *value)
Definition STM32LoRaWAN.h:389
bool joinOTAA(const char *appEui, const char *appKey)
Definition STM32LoRaWAN.h:135
bool publicNetwork(bool publicNetwork)
Definition STM32LoRaWAN.cpp:293
void maintainUntilIdle()
Definition STM32LoRaWAN.cpp:152