-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- Revised BSD License --- | ||
Copyright (c) 2013, SEMTECH S.A. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Semtech corporation nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-Class1'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-Class1" > | ||
<ApplicationBuild Header="LoRaMac-Class1" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="98" Config="Bleeper" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-ClassA'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-ClassA" > | ||
<ApplicationBuild Header="LoRaMac-ClassA" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="98" Config="Bleeper" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-ClassB'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-ClassB" > | ||
<ApplicationBuild Header="LoRaMac-ClassB" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="98" Config="Bleeper" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'Ping-Pong'" Path=".\Ping-Pong.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="ping-pong" > | ||
<ApplicationBuild Header="ping-pong" Extern=".\Ping-Pong.rapp" Path=".\Ping-Pong.rapp" OutputFile=".\obj\Ping-Pong.elf" sate="96" Config="Bleeper" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'Ping-Pong'" Path=".\Ping-Pong.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="ping-pong" > | ||
<ApplicationBuild Header="ping-pong" Extern=".\Ping-Pong.rapp" Path=".\Ping-Pong.rapp" OutputFile=".\obj\Ping-Pong.elf" sate="96" Config="Bleeper" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-Class1'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-Class1" > | ||
<ApplicationBuild Header="LoRaMac-Class1" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="96" Config="LoRaMote" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-ClassA'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-ClassA" > | ||
<ApplicationBuild Header="LoRaMac-ClassA" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="96" Config="LoRaMote" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'LoRaMac-ClassB'" Path=".\LoRaMac.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="LoRaMac-ClassB" > | ||
<ApplicationBuild Header="LoRaMac-ClassB" Extern=".\LoRaMac.rapp" Path=".\LoRaMac.rapp" OutputFile=".\obj\LoRaMac.elf" sate="96" Config="LoRaMote" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'Ping-Pong'" Path=".\Ping-Pong.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="ping-pong" > | ||
<ApplicationBuild Header="ping-pong" Extern=".\Ping-Pong.rapp" Path=".\Ping-Pong.rapp" OutputFile=".\obj\Ping-Pong.elf" sate="98" Config="LoRaMote" /> | ||
</Project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<Project Header="Project 'Ping-Pong'" Path=".\Ping-Pong.rprj" Project="Yes" OutputFile="" sate="96" ActiveApp="ping-pong" > | ||
<ApplicationBuild Header="ping-pong" Extern=".\Ping-Pong.rapp" Path=".\Ping-Pong.rapp" OutputFile=".\obj\Ping-Pong.elf" sate="98" Config="LoRaMote" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
/* | ||
/ _____) _ | | | ||
( (____ _____ ____ _| |_ _____ ____| |__ | ||
\____ \| ___ | (_ _) ___ |/ ___) _ \ | ||
_____) ) ____| | | || |_| ____( (___| | | | | ||
(______/|_____)_|_|_| \__)_____)\____)_| |_| | ||
©2013 Semtech | ||
Description: LoRaMac class1 device implementation | ||
License: Revised BSD License, see LICENSE.TXT file include in the project | ||
Maintainer: Miguel Luis and Gregory Cristian | ||
*/ | ||
#include <string.h> | ||
#include <math.h> | ||
#include "board.h" | ||
#include "radio.h" | ||
|
||
#include "LoRaMac.h" | ||
|
||
/*! | ||
* When set to 1 the application uses the Over-the-Air activation procedure | ||
* When set to 0 the application uses the Personalization activation procedure | ||
*/ | ||
#define OVER_THE_AIR_ACTIVATION 0 | ||
|
||
/*! | ||
* Mote device IEEE EUI | ||
*/ | ||
static uint8_t DevEui[] = | ||
{ | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}; | ||
|
||
#if( OVER_THE_AIR_ACTIVATION != 0 ) | ||
|
||
#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE 10000000 // 10 [s] value in us | ||
|
||
/*! | ||
* Application IEEE EUI | ||
*/ | ||
static uint8_t AppEui[] = | ||
{ | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}; | ||
|
||
/*! | ||
* AES encryption/decryption cipher application key | ||
*/ | ||
static uint8_t AppKey[] = | ||
{ | ||
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, | ||
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C | ||
}; | ||
|
||
#else | ||
|
||
/*! | ||
* AES encryption/decryption cipher network session key | ||
*/ | ||
static uint8_t NwkSKey[] = | ||
{ | ||
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, | ||
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C | ||
}; | ||
|
||
/*! | ||
* AES encryption/decryption cipher application session key | ||
*/ | ||
static uint8_t AppSKey[] = | ||
{ | ||
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, | ||
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C | ||
}; | ||
|
||
/*! | ||
* Device address | ||
*/ | ||
static uint32_t DevAddr; | ||
|
||
#endif | ||
|
||
/*! | ||
* Indicates if the MAC layer has already joined a network. | ||
*/ | ||
static bool IsNetworkJoined = false; | ||
|
||
/*! | ||
* Defines the application data transmission duty cycle | ||
*/ | ||
#define APP_TX_DUTYCYCLE 5000000 // 5 [s] value in us | ||
#define APP_TX_DUTYCYCLE_RND 1000000 // 1 [s] value in us | ||
|
||
/*! | ||
* User application data buffer size | ||
*/ | ||
#define APP_DATA_SIZE 8 | ||
|
||
/*! | ||
* User application data | ||
*/ | ||
static uint8_t AppData[APP_DATA_SIZE]; | ||
|
||
/*! | ||
* Defines the application data transmission duty cycle | ||
*/ | ||
static uint32_t TxDutyCycleTime; | ||
|
||
static TimerEvent_t TxNextPacketTimer; | ||
|
||
#if( OVER_THE_AIR_ACTIVATION != 0 ) | ||
|
||
/*! | ||
* Defines the join request timer | ||
*/ | ||
static TimerEvent_t JoinReqTimer; | ||
|
||
#endif | ||
|
||
/*! | ||
* Indicates if a new packet can be sent | ||
*/ | ||
static bool TxNextPacket = true; | ||
static bool TxDone = false; | ||
|
||
static LoRaMacEvent_t LoRaMacEvents; | ||
|
||
static TimerEvent_t Led1Timer; | ||
volatile bool Led1TimerEvent = false; | ||
|
||
#if( OVER_THE_AIR_ACTIVATION != 0 ) | ||
|
||
/*! | ||
* \brief Function executed on Led 1 Timeout event | ||
*/ | ||
void OnJoinReqTimerEvent( void ) | ||
{ | ||
TxNextPacket = true; | ||
} | ||
|
||
#endif | ||
|
||
/*! | ||
* \brief Function executed on Led 1 Timeout event | ||
*/ | ||
void OnTxNextPacketTimerEvent( void ) | ||
{ | ||
TxNextPacket = true; | ||
} | ||
|
||
/*! | ||
* \brief Function executed on Led 1 Timeout event | ||
*/ | ||
void OnLed1TimerEvent( void ) | ||
{ | ||
Led1TimerEvent = true; | ||
} | ||
|
||
/*! | ||
* \brief Function to be executed on MAC layer event | ||
*/ | ||
void OnMacEvent( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info ) | ||
{ | ||
if( flags->Bits.JoinAccept == 1 ) | ||
{ | ||
#if( OVER_THE_AIR_ACTIVATION != 0 ) | ||
TimerStop( &JoinReqTimer ); | ||
#endif | ||
IsNetworkJoined = true; | ||
} | ||
|
||
if( flags->Bits.Tx == 1 ) | ||
{ | ||
TxDone = true; | ||
} | ||
} | ||
|
||
/** | ||
* Main application entry point. | ||
*/ | ||
int main( void ) | ||
{ | ||
uint16_t pressure = 0; | ||
uint16_t altitudeBar = 0; | ||
int16_t temperature = 0; | ||
uint8_t batteryLevel = 0; | ||
|
||
BoardInitMcu( ); | ||
BoardInitPeriph( ); | ||
|
||
// Initialize LoRaMac device unique ID | ||
BoardGetUniqueId( DevEui ); | ||
|
||
LoRaMacEvents.MacEvent = OnMacEvent; | ||
LoRaMacInit( &LoRaMacEvents ); | ||
|
||
IsNetworkJoined = false; | ||
|
||
#if( OVER_THE_AIR_ACTIVATION == 0 ) | ||
// Random seed initialization | ||
srand( RAND_SEED ); | ||
// Choose a random device address | ||
DevAddr = randr( 0, 0x0FFFFFFF ); | ||
|
||
LoRaMacInitNwkIds( DevAddr, NwkSKey, AppSKey ); | ||
|
||
IsNetworkJoined = true; | ||
#else | ||
// Sends a JoinReq Command every 5 seconds until the network is joined | ||
TimerInit( &JoinReqTimer, OnJoinReqTimerEvent ); | ||
TimerSetValue( &JoinReqTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE ); | ||
TimerStart( &JoinReqTimer ); | ||
#endif | ||
|
||
TxNextPacket = true; | ||
TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); | ||
|
||
TimerInit( &Led1Timer, OnLed1TimerEvent ); | ||
TimerSetValue( &Led1Timer, 25000 ); | ||
|
||
while( 1 ) | ||
{ | ||
while( IsNetworkJoined == false ) | ||
{ | ||
#if( OVER_THE_AIR_ACTIVATION != 0 ) | ||
if( TxNextPacket == true ) | ||
{ | ||
TxNextPacket = false; | ||
|
||
LoRaMacJoinReq( DevEui, AppEui, AppKey ); | ||
|
||
// Relaunch timer for next trial | ||
TimerStart( &JoinReqTimer ); | ||
} | ||
TimerHandleEvent( ); | ||
#endif | ||
} | ||
if( Led1TimerEvent == true ) | ||
{ | ||
Led1TimerEvent = false; | ||
|
||
// Switch LED 1 OFF | ||
GpioWrite( &Led1, 1 ); | ||
} | ||
|
||
if( TxDone == true ) | ||
{ | ||
TxDone = false; | ||
|
||
// Schedule next packet transmission | ||
TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); | ||
TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); | ||
TimerStart( &TxNextPacketTimer ); | ||
} | ||
|
||
if( TxNextPacket == true ) | ||
{ | ||
TxNextPacket = false; | ||
|
||
pressure = ( uint16_t )( mpl3115ReadPressure( ) / 10 ); // in hPa / 10 | ||
temperature = ( int16_t )( mpl3115ReadTemperature( ) * 100 ); // in °C * 100 | ||
altitudeBar = ( uint16_t )( mpl3115ReadAltitude( ) * 10 ); // in m * 10 | ||
batteryLevel = BoardMeasureBatterieLevel( ); // 1 (very low) to 254 (fully charged) | ||
|
||
// Switch LED 1 ON | ||
GpioWrite( &Led1, 0 ); | ||
TimerStart( &Led1Timer ); | ||
|
||
AppData[0] = 0x00; | ||
AppData[1] = ( pressure >> 8 ) & 0xFF; | ||
AppData[2] = pressure & 0xFF; | ||
AppData[3] = ( temperature >> 8 ) & 0xFF; | ||
AppData[4] = temperature & 0xFF; | ||
AppData[5] = ( altitudeBar >> 8 ) & 0xFF; | ||
AppData[6] = altitudeBar & 0xFF; | ||
AppData[7] = batteryLevel; | ||
|
||
LoRaMacSendFrame( 1, AppData, APP_DATA_SIZE ); | ||
} | ||
|
||
TimerHandleEvent( ); | ||
} | ||
} | ||
|