kopia lustrzana https://github.com/helium/longfi-arduino
add Platformio sample
rodzic
f363895057
commit
0a4447b185
|
@ -0,0 +1,5 @@
|
||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:cubecell_board_plus]
|
||||||
|
platform = asrmicro650x
|
||||||
|
board = cubecell_board_plus
|
||||||
|
;board = cubecell_board_plus ; GPS Version AB02S
|
||||||
|
framework = arduino
|
||||||
|
build_flags = -Wl,-Map,output.map
|
||||||
|
monitor_speed = 115200
|
||||||
|
board_build.arduino.lorawan.region = US915
|
||||||
|
board_build.arduino.lorawan.class = CLASS_A
|
||||||
|
board_build.arduino.lorawan.netmode = OTAA
|
||||||
|
board_build.arduino.lorawan.uplinkmode = UNCONFIRMED
|
||||||
|
board_build.arduino.lorawan.rgb = DEACTIVE
|
||||||
|
board_build.arduino.lorawan.debug_level = FREQ_AND_DIO
|
||||||
|
; debug_level can be NONE, FREQ, FREQ_AND_DIO
|
||||||
|
board_build.arduino.lorawan.adr = OFF
|
||||||
|
board_build.arduino.lorawan.at_support = OFF
|
||||||
|
board_build.arduino.lorawan.net_reserve = OFF
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
|
||||||
|
#include "LoRaWan_APP.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set LoraWan_RGB to Active,the RGB active in loraWan
|
||||||
|
* RGB red means sending;
|
||||||
|
* RGB purple means joined done;
|
||||||
|
* RGB blue means RxWindow1;
|
||||||
|
* RGB yellow means RxWindow2;
|
||||||
|
* RGB green means received done;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* OTAA para*/
|
||||||
|
uint8_t devEui[] = { FILL_ME_IN };
|
||||||
|
uint8_t appEui[] = { FILL_ME_IN };
|
||||||
|
uint8_t appKey[] = { FILL_ME_IN };
|
||||||
|
|
||||||
|
/* ABP para*/
|
||||||
|
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
|
||||||
|
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
|
||||||
|
uint32_t devAddr = ( uint32_t )0x007e6ae1;
|
||||||
|
|
||||||
|
/*LoraWan channelsmask, default channels 0-7*/
|
||||||
|
uint16_t userChannelsMask[6]={ 0xFF00,0x0000,0x0000,0x0000,0x0000,0x0000 };
|
||||||
|
|
||||||
|
/* NOTE: It is very important that these variables be defined correctly in the Arduino IDE Tools->Board options */
|
||||||
|
|
||||||
|
/*LoraWan region, select in arduino IDE tools*/
|
||||||
|
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
|
||||||
|
|
||||||
|
/*LoraWan Class, Class A and Class C are supported*/
|
||||||
|
DeviceClass_t loraWanClass = LORAWAN_CLASS;
|
||||||
|
|
||||||
|
/*OTAA or ABP*/
|
||||||
|
bool overTheAirActivation = LORAWAN_NETMODE;
|
||||||
|
|
||||||
|
/*ADR enable*/
|
||||||
|
bool loraWanAdr = LORAWAN_ADR;
|
||||||
|
|
||||||
|
/* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
|
||||||
|
bool keepNet = LORAWAN_NET_RESERVE;
|
||||||
|
|
||||||
|
/* Indicates if the node is sending confirmed or unconfirmed messages */
|
||||||
|
bool isTxConfirmed = LORAWAN_UPLINKMODE;
|
||||||
|
|
||||||
|
/*the application data transmission duty cycle. value in [ms].*/
|
||||||
|
uint32_t appTxDutyCycle = 15000;
|
||||||
|
|
||||||
|
/* Application port */
|
||||||
|
uint8_t appPort = 2;
|
||||||
|
/*!
|
||||||
|
* Number of trials to transmit the frame, if the LoRaMAC layer did not
|
||||||
|
* receive an acknowledgment. The MAC performs a datarate adaptation,
|
||||||
|
* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
|
||||||
|
* to the following table:
|
||||||
|
*
|
||||||
|
* Transmission nb | Data Rate
|
||||||
|
* ----------------|-----------
|
||||||
|
* 1 (first) | DR
|
||||||
|
* 2 | DR
|
||||||
|
* 3 | max(DR-1,0)
|
||||||
|
* 4 | max(DR-1,0)
|
||||||
|
* 5 | max(DR-2,0)
|
||||||
|
* 6 | max(DR-2,0)
|
||||||
|
* 7 | max(DR-3,0)
|
||||||
|
* 8 | max(DR-3,0)
|
||||||
|
*
|
||||||
|
* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
|
||||||
|
* the datarate, in case the LoRaMAC layer did not receive an acknowledgment
|
||||||
|
*/
|
||||||
|
uint8_t confirmedNbTrials = 4;
|
||||||
|
|
||||||
|
// This variable, defined in the runtime, tracks the number of uplinks sent.
|
||||||
|
// When this count reaches 65,535 the connection must be re-established.
|
||||||
|
// If you do not the device will continue to send data to the network but
|
||||||
|
// it will not make it to the Helium console.
|
||||||
|
// The value is tested below and a reconnection is forced if the counter
|
||||||
|
// equals 65534.
|
||||||
|
// refer to FCnt on this documentation page:
|
||||||
|
// https://developer.helium.com/longfi/mac-commands-fopts-adr
|
||||||
|
extern uint32_t UpLinkCounter;
|
||||||
|
|
||||||
|
/* Prepares the payload of the frame */
|
||||||
|
static void prepareTxFrame( uint8_t port )
|
||||||
|
{
|
||||||
|
/*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
|
||||||
|
*appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
|
||||||
|
*if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
|
||||||
|
*if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
|
||||||
|
*for example, if use REGION_CN470,
|
||||||
|
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
|
||||||
|
*/
|
||||||
|
appDataSize = 4;
|
||||||
|
appData[0] = 0x00;
|
||||||
|
appData[1] = 0x01;
|
||||||
|
appData[2] = 0x02;
|
||||||
|
appData[3] = 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
boardInitMcu();
|
||||||
|
Serial.begin(115200);
|
||||||
|
#if(AT_SUPPORT)
|
||||||
|
enableAt();
|
||||||
|
#endif
|
||||||
|
deviceState = DEVICE_STATE_INIT;
|
||||||
|
LoRaWAN.ifskipjoin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
switch( deviceState )
|
||||||
|
{
|
||||||
|
case DEVICE_STATE_INIT:
|
||||||
|
{
|
||||||
|
#if(AT_SUPPORT)
|
||||||
|
getDevParam();
|
||||||
|
#endif
|
||||||
|
printDevParam();
|
||||||
|
LoRaWAN.init(loraWanClass,loraWanRegion);
|
||||||
|
deviceState = DEVICE_STATE_JOIN;
|
||||||
|
|
||||||
|
// This is a runtime API that is in the Heltec github
|
||||||
|
// but has not yet made it to the Arduino install
|
||||||
|
// version. (1.0.0) It's here for future reference
|
||||||
|
// LoRaWAN.setDataRateForNoADR(DR_3);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEVICE_STATE_JOIN:
|
||||||
|
{
|
||||||
|
LoRaWAN.join();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEVICE_STATE_SEND:
|
||||||
|
{
|
||||||
|
// Comment out this warning if you "really" do want
|
||||||
|
// to enable ADR
|
||||||
|
if (loraWanAdr == true)
|
||||||
|
{
|
||||||
|
Serial.println(">>>> WARNING: ADR is enabled.\n\tThis may reduce the datarate/Spreading Factor after about 100 uplinks");
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareTxFrame( appPort );
|
||||||
|
LoRaWAN.send();
|
||||||
|
deviceState = DEVICE_STATE_CYCLE;
|
||||||
|
// the following is experimental but does seem to
|
||||||
|
// re-initialize the connection correctly. See the note
|
||||||
|
// at extern UpLinkCounter above
|
||||||
|
if (UpLinkCounter == 65534)
|
||||||
|
{
|
||||||
|
// force a rejoin
|
||||||
|
deviceState = DEVICE_STATE_INIT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEVICE_STATE_CYCLE:
|
||||||
|
{
|
||||||
|
// Schedule next packet transmission
|
||||||
|
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
|
||||||
|
LoRaWAN.cycle(txDutyCycleTime);
|
||||||
|
deviceState = DEVICE_STATE_SLEEP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEVICE_STATE_SLEEP:
|
||||||
|
{
|
||||||
|
LoRaWAN.sleep();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
deviceState = DEVICE_STATE_INIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||||
|
|
Ładowanie…
Reference in New Issue