#include <CoAPRequest.hpp>
#define OVER_THE_AIR_ACTIVATION 1
#include "LoRaMacKR920.hpp"
static const uint8_t devEui[] = "\x00\x11\x22\x33\x44\x55\x66\x77";
static const uint8_t appEui[] = "\x00\x00\x00\x00\x00\x00\x00\x01";
#if (OVER_THE_AIR_ACTIVATION == 1)
static uint8_t appKey[16];
char keyBuf[128];
#else
static const uint8_t NwkSKey[] = "\xa4\x88\x55\xad\xe9\xf8\xf4\x6f\xa0\x94\xb1\x98\x36\xc3\xc0\x86";
static const uint8_t AppSKey[] = "\x7a\x56\x2a\x75\xd7\xa3\xbd\x89\xa3\xde\x53\xe1\xcf\x7f\x1c\xc7";
static uint32_t DevAddr = 0x06e632e8;
#endif
uint16_t txCnt = 0;
if (response) {
printf(
"* Got something CoAP response (%d.%02d):", response->
code >> 5, response->
code & 0x1F);
for (
size_t i = 0; i < response->
payloadLen; i++) {
printf(
" %02X", response->
payload[i]);
}
printf(
", location:%s\n", response->
location);
}
printf("\n");
} else {
printf("* No response\n");
}
delete &req;
}
static void taskPeriodicSend(void *) {
if (!req) {
printf("* Not enough memory to make a CoAPRequest.\n");
return;
}
error_t err = req->
send();
printf("* Sending a CoAPRequest error:%d\n", err);
delete req;
} else {
printf("* Sending a CoAPRequest success.\n");
}
}
#if (OVER_THE_AIR_ACTIVATION == 1)
static void eventLoRaWANJoin(
bool joined,
const uint8_t *joinedDevEui,
const uint8_t *joinedAppEui,
const uint8_t *joinedAppKey,
const uint8_t *joinedNwkSKey,
const uint8_t *joinedAppSKey,
uint32_t joinedDevAddr,
uint32_t airTime
) {
Serial.printf("* Tx time of JoinRequest: %lu usec.\n", airTime);
if (joined) {
Serial.println("* Joining done!");
} else {
Serial.println("* Joining failed. Retry to join.");
}
}
#endif
static void eventLoRaWANJoinRequested(
) {
printf("* JoinRequested(Frequency: %lu Hz, Modulation: ", frequencyHz);
printf("FSK\n");
const char *strLoRaBW[] = { "UNKNOWN", "125kHz", "250kHz", "500kHz" };
printf(
"LoRa, SF:%u, BW:%s)\n", dr.
param.
LoRa.
sf, strLoRaBW[dr.param.LoRa.
bw]);
}
}
static void printChannelInformation(
LoRaMac &lw) {
printf("* Channel list:");
if (p) {
} else {
printf(" [%u] NA", i);
}
}
printf("\n");
printf("LoRa(SF%u BW:", dr->param.LoRa.sf);
switch (dr->param.LoRa.bw) {
default: printf("(unexpected:%u)\n", dr->param.LoRa.bw); break;
}
printf("FSK\n");
} else {
printf("Unknown modulation\n");
}
printf(
" - # of repetitions of unconfirmed uplink frames: %u\n",
);
}
#if (OVER_THE_AIR_ACTIVATION == 1)
static void taskBeginJoin(void *) {
Serial.stopListening();
Serial.println("* Let's start join!");
}
uint8_t numOctets = strlen(keyBuf);
if (numOctets == 32) {
numOctets /= 2;
char strOctet[3];
for (uint8_t j = 0; j < numOctets; j++) {
strOctet[0] = keyBuf[2 * j];
strOctet[1] = keyBuf[2 * j + 1];
strOctet[2] = '\0';
appKey[j] = strtoul(strOctet, NULL, 16);
}
printf("* New AppKey:");
for (uint8_t j = 0; j < numOctets; j++) {
printf(" %02X", appKey[j]);
}
printf(" (%u byte)\n", numOctets);
ConfigMemory.write(appKey, 0, numOctets);
return;
} else {
printf("* HEX string length MUST be 32-byte.");
}
Serial.inputKeyboard(keyBuf, sizeof(keyBuf) - 1);
}
while (Serial.available() > 0) {
Serial.read();
}
Serial.onReceive(eventAppKeyInput);
Serial.inputKeyboard(keyBuf, sizeof(keyBuf) - 1);
Serial.println(
"* Enter a new appKey as a hexadecimal string "
"[ex. 00112233445566778899aabbccddeeff]"
);
}
#endif
void setup() {
Serial.begin(115200);
Serial.printf("\n*** [Nol.Board] IPv6 over LoRaWAN ***\n");
System.setTimeDiff(9 * 60);
timerSend.
onFired(taskPeriodicSend, NULL);
#if (OVER_THE_AIR_ACTIVATION == 1)
LoRaWAN.
onJoin(eventLoRaWANJoin);
#endif
printChannelInformation(LoRaWAN);
#if (OVER_THE_AIR_ACTIVATION == 0)
printf("ABP!\n");
LoRaWAN.
setABP(NwkSKey, AppSKey, DevAddr);
LoRaWAN.setNetworkJoined(true);
#else
Serial.printf(
"* DevEUI: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
devEui[0], devEui[1], devEui[2], devEui[3],
devEui[4], devEui[5], devEui[6], devEui[7]
);
ConfigMemory.read(appKey, 0, 16);
Serial.printf(
"* AppKey: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
appKey[0], appKey[1], appKey[2], appKey[3],
appKey[4], appKey[5], appKey[6], appKey[7],
appKey[8], appKey[9], appKey[10], appKey[11],
appKey[12], appKey[13], appKey[14], appKey[15]
);
if (memcmp(appKey, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 16) == 0) {
Serial.onReceive(eventAppKeyInput);
Serial.inputKeyboard(keyBuf, sizeof(keyBuf) - 1);
Serial.println(
"* Enter a new appKey as a hexadecimal string "
"[ex. 00112233445566778899aabbccddeeff]"
);
} else {
Serial.println("* Press any key to enter a new appKey in 3 seconds...");
timerKeyInput.
onFired(taskBeginJoin, NULL);
Serial.onReceive(eventKeyInput);
}
Serial.listen();
#endif
ipv6LoRaWAN.begin(devEui, appEui);
}
IPv6 Network Interface - LoRaWAN.
CoAP 서버로 요청을 보내기 위한 클래스
Definition CoAPRequest.hpp:60
error_t open(Method_t method, const char *uri, const char *token, IPv6Interface *interface)
CoAP request의 세부 사항을 지정합니다.
void onResponse(void(*handler)(CoAPRequest &req, const ResponseInfo_t *response))
CoAP request에 대한 response 콜백함수를 지정합니다.
error_t send(Media_t media=MEDIA_TEXT_PLAIN, const uint8_t *payload=NULL, uint16_t payloadLength=0)
CoAP request를 payload와 함께 전송합니다.
@ GET
Definition CoAP.hpp:105
IPv6 over LoRaWAN.
Definition IPv6LoRaWAN.hpp:233
Internet Protocol Version 6 Stack.
Definition IPv6.hpp:67
void begin()
Initialize the IPv6 network layer.
대한민국 920~923MHz 대역을 사용하는 LoRaMac
Definition LoRaMacKR920.hpp:25
Definition LoRaMac.hpp:272
uint32_t Frequency
Frequency in Hz.
Definition LoRaMac.hpp:277
LoRaWAN 단말 장치들을 위한 MAC 프로토콜
Definition LoRaMac.hpp:253
virtual void setABP(const uint8_t *nwkSKey, const uint8_t *appSKey, uint32_t devAddr)
ABP를 사용하도록 설정합니다.
virtual error_t begin(uint8_t(*getBatteryLevel)()=NULL)
LoRaMAC layer initialization.
uint8_t getCurrentDatarateIndex()
현재 설정된 기본 datarate 인덱스를 가져옵니다.
void onJoinRequested(void(*func)(LoRaMac &, uint32_t frequencyHz, const DatarateParams_t &))
JoinRequest 메시지를 보낼 때 호출될 콜백함수를 지정합니다.
virtual const ChannelParams_t * getChannel(uint8_t index)=0
채널 정보를 가져옵니다.
uint8_t getNumRepetitions()
현재 설정된 unconfirmed uplink frame에 적용되는 반복 전송 횟수를 가져옵니다.
uint8_t getCurrentTxPowerIndex()
기본 Tx power index를 가져옵니다.
virtual error_t beginJoining(const uint8_t *devEui, const uint8_t *appEui, const uint8_t *appKey)
Over-the-Air Activation (OTAA) 방식의 join을 시도합니다.
uint8_t const MaxNumChannels
최대 채널 수
Definition LoRaMac.hpp:396
void onJoin(void(*func)(LoRaMac &mac, bool result, const uint8_t *devEui, const uint8_t *appEui, const uint8_t *appKey, const uint8_t *nwkSKey, const uint8_t *appSKey, uint32_t devAddr, const RadioPacket &frame, uint32_t airTime))
Join이 완료되었을 때 호출될 콜백함수를 지정합니다.
void setPublicNetwork(bool enable)
공용 LoRaWAN 네트워크를 사용할지 설정합니다.
const DatarateParams_t * getDatarate(uint8_t index) const
Datarate 정보를 가져옵니다.
무선 패킷
Definition RadioPacket.hpp:59
시리얼 포트를 제어하기 위한 클래스
Definition SerialPort.hpp:76
Timer는 일정 시간 이후에 1회 실행될 작업, 매 일정 시간마다 실행될 작업 등을 위한 기능입니다.
Definition Timer.hpp:61
void stop()
예약된, 혹은 측정 중인 Timer를 중단합니다.
bool startOneShot(uint32_t millis, bool interrupt=false)
작업함수를 millis 밀리초 이후 1회 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
nRF5x MCU 내부 플래시 페이지에 데이터를 읽고 쓰기 위한 클래스
Definition nRF5xFlashPage.hpp:54
@ ERROR_SUCCESS
Definition nola-common.h:119
bool digitalWrite(int8_t pin, int value)
pin 를 HIGH 또는 LOW 로 설정합니다.
bool pinMode(int8_t pin, enum ioDirection direction)
pin 을 direction 방향을 갖는 디지털 핀으로 동작하도록 설정합니다.
@ OUTPUT
Definition nola-common.h:383
bool postTask(void(*func)(void *), void *args)
작업을 나중에 실행되도록 게시합니다.
@ BW_250kHz
Definition Radio.hpp:110
@ BW_125kHz
Definition Radio.hpp:109
@ BW_500kHz
Definition Radio.hpp:111
@ MOD_FSK
Definition Radio.hpp:67
@ MOD_LORA
Definition Radio.hpp:68
@ GPIO1
Definition System.hpp:65
CoAP response 정보
Definition CoAPRequest.hpp:94
uint8_t code
Definition CoAPRequest.hpp:95
uint8_t * payload
Definition CoAPRequest.hpp:96
size_t payloadLen
Definition CoAPRequest.hpp:97
char * location
Definition CoAPRequest.hpp:98
Definition LoRaMac.hpp:359