再附一个代码(虽然可能没什么参考意义...因为真的很简单...)
#include "mcc_generated_files/mcc.h"
uint8_t nwkSKey[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99};
uint8_t appSKey[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87};
uint32_t devAddr = 0x42;
void RxData(uint8_t* pData, uint8_t dataLength, OpStatus_t status){}
void RxJoinResponse(bool status){}
/*
Main application
*/
void main(void)
{
// Initialize the device
SYSTEM_Initialize();
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
LORAWAN_Init(RxData, RxJoinResponse);
LORAWAN_SetNetworkSessionKey(nwkSKey);
LORAWAN_SetApplicationSessionKey(appSKey);
LORAWAN_SetDeviceAddress(devAddr);
LORAWAN_Join(ABP);
while (1)
{
// Add your application code
LORAWAN_Mainloop();
LORAWAN_Send(UNCNF, 2, "LoRa", 4);
}
} |