#include <algorithm>
#include "LoRaMacKR920SKT.hpp"
#include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
#define OVER_THE_AIR_ACTIVATION 1
#define I2C_ADDR 0x48
SparkFun_Ambient_Light light(I2C_ADDR);
#if (OVER_THE_AIR_ACTIVATION == 1)
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\x00";
static const uint8_t appKey[] = "\xaa\xe1\x20\xe3\x36\x03\xcd\x09\xd9\xda\x4a\x61\x84\xc6\xf5\x19";
#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
static void taskPeriodicSend(void *) {
printf("* Out of memory\n");
return;
}
strcpy((char *) f->buf, "Test");
f->
len = strlen((
char *) f->buf);
error_t err = LoRaWAN.
send(f);
printf("* Sending periodic report (%p:%s (%u byte)): %d\n", f, f->buf, f->len, err);
delete f;
}
}
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
) {
#if (OVER_THE_AIR_ACTIVATION == 1)
if (joined) {
if (joinedNwkSKey && joinedAppSKey) {
printf("* Joined to the network!\n");
} else {
printf("* PseudoAppKey joining done!\n");
}
} else {
printf("* Join failed. Retry to join\n");
}
#endif
}
printf(
"* Send done(%d): [%p] destined for port[%u], Freq:%lu Hz, Power:%d dBm, # of Tx:%u, ", frame->
result, frame, frame->
port, frame->
freq, frame->
power, frame->
numTrials);
const char *strBW[] = { "Unknown", "125kHz", "250kHz", "500kHz", "Unexpected value" };
}
printf("FSK, ");
} else {
printf("Unkndown modulation, ");
}
printf("UNCONFIRMED");
printf("CONFIRMED");
printf("MULTICAST (error)");
printf("PROPRIETARY");
} else {
printf("unknown type");
}
printf(" frame\n");
delete frame;
}
printf("* Received:");
for (uint8_t i = 0; i < frame->len; i++) {
printf(" %02X", frame->buf[i]);
}
printf(" (");
printf(")\n");
if (
) {
if (emptyFrame) {
error_t err = LoRaWAN.
send(emptyFrame);
delete emptyFrame;
}
}
}
}
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 eventLoRaWANLinkADRReqReceived(
LoRaMac &l,
const uint8_t *payload) {
printf("* LoRaWAN LinkADRReq received: [");
for (uint8_t i = 0; i < 4; i++) {
printf(" %02X", payload[i]);
}
printf(" ]\n");
}
static void printChannelInformation(
LoRaMac &lw) {
if (p) {
printf(
" - [%u] Frequency:%lu Hz\n", i, p->
Frequency);
} else {
printf(" - [%u] disabled\n", i);
}
}
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", lw.
getNumRepetitions());
}
static void eventLoRaWANLinkADRAnsSent(
LoRaMac &l, uint8_t status) {
printf("* LoRaWAN LinkADRAns sent with status 0x%02X.\n", status);
printChannelInformation(l);
}
static void eventLoRaWANDutyCycleReqReceived(
LoRaMac &lw,
const uint8_t *payload) {
printf("* LoRaWAN DutyCycleReq received: [");
for (uint8_t i = 0; i < 1; i++) {
printf(" %02X", payload[i]);
}
printf(" ]\n");
}
static void eventLoRaWANDutyCycleAnsSent(
LoRaMac &lw) {
printf(
"* LoRaWAN DutyCycleAns sent. Current MaxDCycle is %u.\n", lw.
getMaxDutyCycle());
}
static void eventLoRaWANRxParamSetupReqReceived(
LoRaMac &lw,
const uint8_t *payload) {
printf("* LoRaWAN RxParamSetupReq received: [");
for (uint8_t i = 0; i < 4; i++) {
printf(" %02X", payload[i]);
}
printf(" ]\n");
}
static void eventLoRaWANRxParamSetupAnsSent(
LoRaMac &lw, uint8_t status) {
}
static void eventLoRaWANDevStatusReqReceived(
LoRaMac &lw) {
printf("* LoRaWAN DevStatusReq received.\n");
}
static void eventLoRaWANDevStatusAnsSent(
LoRaMac &lw, uint8_t bat, uint8_t margin) {
printf("* LoRaWAN DevStatusAns sent. (");
if (bat == 0) {
printf("Powered by external power source. ");
} else if (bat == 255) {
printf("Battery level cannot be measured. ");
} else {
printf(
"Battery: %lu %%. ",
map(bat, 1, 254, 0, 100));
}
}
printf(" SNR: %d)\n", (int8_t) margin);
}
static void eventLoRaWANNewChannelReqReceived(
LoRaMac &lw,
const uint8_t *payload) {
printf("* LoRaWAN NewChannelReq received [");
for (uint8_t i = 0; i < 5; i++) {
printf(" %02X", payload[i]);
}
printf(" ]\n");
}
static void eventLoRaWANNewChannelAnsSent(
LoRaMac &lw, uint8_t status) {
printf(
"* LoRaWAN NewChannelAns sent with (Datarate range %s and channel frequency %s).\n", (
bitRead(status, 1) == 1) ?
"OK" :
"NOT OK", (
bitRead(status, 0) == 1) ?
"OK" :
"NOT OK");
if (p) {
printf(
" - [%u] Frequency:%lu Hz\n", i, p->
Frequency);
} else {
printf(" - [%u] disabled\n", i);
}
}
}
static void eventLoRaWANRxTimingSetupReqReceived(
LoRaMac &lw,
const uint8_t *payload) {
printf("* LoRaWAN RxTimingSetupReq received: [");
for (uint8_t i = 0; i < 1; i++) {
printf(" %02X", payload[i]);
}
printf(" ]\n");
}
static void eventLoRaWANRxTimingSetupAnsSent(
LoRaMac &lw) {
printf(
"* LoRaWAN RxTimingSetupAns sent. Current Rx1 delay is %u msec, and Rx2 delay is %u msec.\n", lw.
getRx1Delay(), lw.
getRx2Delay());
}
float gain = .125;
int integration_time = 100;
long luxVal = 0;
static void basicfunc(void*){
luxVal = light.readLight();
Serial.print("Ambient Light Reading: ");
Serial.print(luxVal);
Serial.println(" Lux");
}
static void findI2C(void*){
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error =
Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
}
void setup() {
Serial.begin(115200);
Serial.printf("\n*** [PLM100S] LoRaWAN Class A Example ***\n");
Serial.printf("* Last reset reason:0x%02X\n", System.getResetReason());
timerSend.
onFired(taskPeriodicSend, NULL);
LoRaWAN.
onJoin(eventLoRaWANJoin);
printChannelInformation(LoRaWAN);
printf("START LIGHT");
if(light.begin())
Serial.println("Ready to sense some light!");
else
Serial.println("Could not communicate with the sensor!");
light.setGain(gain);
light.setIntegTime(integration_time);
Serial.println("Reading settings...");
Serial.print("Gain: ");
float gainVal = light.readGain();
Serial.print(gainVal, 3);
Serial.print(" Integration Time: ");
int timeVal = light.readIntegTime();
Serial.println(timeVal);
#if (OVER_THE_AIR_ACTIVATION == 0)
printf("ABP!\n");
LoRaWAN.
setABP(NwkSKey, AppSKey, DevAddr);
LoRaWAN.setNetworkJoined(true);
#else
#endif
}
LoRaWAN frame.
Definition LoRaMac.hpp:88
FrameType_t type
Frame type.
Definition LoRaMac.hpp:102
Radio::LoRaSF_t sf
송신시 사용할, 또는 수신시 사용된 spreading factor
Definition LoRaMac.hpp:189
int16_t power
송신시 사용할 Tx power table index (LoRaMac::MaxTxPower ~ LoRaMac::MinTxPower), 송신 완료 콜백시 출력 세기(단위: dBm) 또는...
Definition LoRaMac.hpp:146
Radio::LoRaBW_t bw
송신시 사용할, 또는 수신시 사용된 bandwidth
Definition LoRaMac.hpp:206
struct LoRaMacFrame::@024007217170142272131231362111253110374345035353::@215311014042340047327077224045033277162306213223 LoRa
modulation 이 Radio::MOD_LORA 인 경우 사용되는 변수
uint8_t numTrials
전송 횟수
Definition LoRaMac.hpp:116
union LoRaMacFrame::@024007217170142272131231362111253110374345035353 meta
변복조 방식에 대한 속성
@ MULTICAST
Definition LoRaMac.hpp:95
@ PROPRIETARY
Definition LoRaMac.hpp:96
@ UNCONFIRMED
Definition LoRaMac.hpp:93
@ CONFIRMED
Definition LoRaMac.hpp:94
uint8_t port
Port number.
Definition LoRaMac.hpp:107
대한민국 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
uint32_t getRx2Frequency()
Rx2에서 사용할 주파수를 가져옵니다.
Definition LoRaMac.hpp:1270
void onRxTimingSetupAnsSent(void(*func)(LoRaMac &))
RxTimingSetupReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
void onNewChannelAnsSent(void(*func)(LoRaMac &, uint8_t status))
NewChannelAns MAC command를 송신시 호출될 콜백함수를 지정합니다.
virtual void setABP(const uint8_t *nwkSKey, const uint8_t *appSKey, uint32_t devAddr)
ABP를 사용하도록 설정합니다.
uint8_t getRx1DrOffset()
Rx1에 적용될 DR offset을 가져옵니다.
Definition LoRaMac.hpp:1286
bool useADR
ADR 사용여부를 설정합니다.
Definition LoRaMac.hpp:442
void onDevStatusReqReceived(void(*func)(LoRaMac &))
DevStatusReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
void onRxTimingSetupReqReceived(void(*func)(LoRaMac &, const uint8_t *))
RxTimingSetupReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
void onRxParamSetupReqReceived(void(*func)(LoRaMac &, const uint8_t *))
RxParamSetupReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
bool framePending
Frame pending.
Definition LoRaMac.hpp:464
virtual error_t begin(uint8_t(*getBatteryLevel)()=NULL)
LoRaMAC layer initialization.
uint8_t getCurrentDatarateIndex()
현재 설정된 기본 datarate 인덱스를 가져옵니다.
uint8_t getRx2Datarate()
Rx2에서 사용할 DR을 가져옵니다.
Definition LoRaMac.hpp:1254
void onJoinRequested(void(*func)(LoRaMac &, uint32_t frequencyHz, const DatarateParams_t &))
JoinRequest 메시지를 보낼 때 호출될 콜백함수를 지정합니다.
uint8_t getMaxDutyCycle()
현재의 최대 duty cycle을 가져옵니다.
void onLinkADRReqReceived(void(*func)(LoRaMac &, const uint8_t *))
LinkADRReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
virtual const ChannelParams_t * getChannel(uint8_t index)=0
채널 정보를 가져옵니다.
uint8_t getNumRepetitions()
현재 설정된 unconfirmed uplink frame에 적용되는 반복 전송 횟수를 가져옵니다.
void onRxParamSetupAnsSent(void(*func)(LoRaMac &, uint8_t status))
RxParamSetupAns MAC command를 송신시 호출될 콜백함수를 지정합니다.
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 onDevStatusAnsSent(void(*func)(LoRaMac &, uint8_t bat, uint8_t margin))
DevStatusAns MAC command를 송신시 호출될 콜백함수를 지정합니다.
void onDutyCycleReqReceived(void(*func)(LoRaMac &, const uint8_t *))
DutyCycleReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
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 onSendDone(void(*sendDoneHandler)(LoRaMac &, LoRaMacFrame *))
전송이 완료될 때 호출될 함수를 지정합니다.
void onLinkADRAnsSent(void(*func)(LoRaMac &, uint8_t status))
LinkADRAns MAC command를 송신시 호출될 콜백함수를 지정합니다.
uint16_t getRx1Delay()
Tx 종료 후 Rx1 window가 열릴 때까지의 지연 시간(단위: 밀리초)을 가져옵니다.
void onDutyCycleAnsSent(void(*func)(LoRaMac &))
DutyCycleAns MAC command를 송신시 호출될 콜백함수를 지정합니다.
void onNewChannelReqReceived(void(*func)(LoRaMac &, const uint8_t *))
NewChannelReq MAC command를 수신시 호출될 콜백함수를 지정합니다.
void setPublicNetwork(bool enable)
공용 LoRaWAN 네트워크를 사용할지 설정합니다.
void onReceive(void(*receiveHandler)(LoRaMac &radio, const LoRaMacFrame *frame))
수신이 완료될 때 호출될 함수를 지정합니다.
const DatarateParams_t * getDatarate(uint8_t index) const
Datarate 정보를 가져옵니다.
uint16_t getRx2Delay()
Tx 종료 후 Rx2 window가 열릴 때까지의 지연 시간(단위: 밀리초)을 가져옵니다.
error_t send(LoRaMacFrame *frame)
frame 을 전송합니다.
uint8_t getNumPendingSendFrames()
전송 대기 중인 프레임 갯수를 구합니다.
무선 패킷
Definition RadioPacket.hpp:59
Radio::Modulation_t modulation
송신시 사용할, 또는 수신시 사용된 변복조 방식
Definition RadioPacket.hpp:160
uint32_t freq
송신시 사용할, 또는 수신시 사용된 주파수 (단위: Hz)
Definition RadioPacket.hpp:143
Result_t result
송신 또는 수신 패킷 처리 결과
Definition RadioPacket.hpp:131
Timer는 일정 시간 이후에 1회 실행될 작업, 매 일정 시간마다 실행될 작업 등을 위한 기능입니다.
Definition Timer.hpp:61
bool startOneShot(uint32_t millis, bool interrupt=false)
작업함수를 millis 밀리초 이후 1회 실행합니다.
bool startPeriodic(uint32_t millis, bool interrupt=false)
작업함수를 매 millis 밀리초 주기로 반복하여 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
#define bitRead(v, n)
수의 한 비트를 읽습니다.
Definition nola-common.h:339
#define bit(n)
특정 비트를 구합니다.
Definition nola-common.h:330
long map(long x, long in_min, long in_max, long out_min, long out_max)
수를 어떤 범위에서 다른 범위로 매핑시킵니다.
@ ERROR_SUCCESS
Definition nola-common.h:119
bool postTask(void(*func)(void *), void *args)
작업을 나중에 실행되도록 게시합니다.
LoRaBW_t
LoRa Bandwidth Type.
Definition Radio.hpp:107
@ 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
@ SF7
Definition Radio.hpp:82
Definition LoRaMac.hpp:359