kopia lustrzana https://github.com/helium/longfi-arduino
initial commit
commit
150c02e73a
|
@ -0,0 +1,41 @@
|
|||
<!--
|
||||
M.m.p (YYYY-MM-DD)
|
||||
==================
|
||||
Add a summary of this release.
|
||||
|
||||
**BREAKING CHANGES**:
|
||||
|
||||
* Some change which breaks API or ABI compatiblity with.
|
||||
|
||||
|
||||
Feature enhancements:
|
||||
|
||||
* [Link to github PR]():
|
||||
A new feature.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
* [Link to github PR]():
|
||||
A bugfix.
|
||||
-->
|
||||
|
||||
0.3.0 (2020-01-30)
|
||||
==================
|
||||
|
||||
**BREAKING CHANGES**:
|
||||
|
||||
* Repo reset for LoRaWAN on Helium Network
|
||||
|
||||
0.2.0 (2019-12-06)
|
||||
==================
|
||||
Feature enhancements:
|
||||
|
||||
* [#32](https://github.com/helium/longfi-arduino/pull/32):
|
||||
Update TransmitPacket Example with Latest Packed Payload
|
||||
|
||||
* [#31](https://github.com/helium/longfi-arduino/pull/31):
|
||||
Update ButtonTransmit Example with Compact Data Payload
|
||||
|
||||
0.1.0 (2019-10-31)
|
||||
==================
|
||||
Initial release.
|
|
@ -0,0 +1,22 @@
|
|||
# How to Contribute to this repository #
|
||||
|
||||
We value contributions from the community and will do everything we
|
||||
can go get them reviewed in a timely fashion. If you have code to send
|
||||
our way or a bug to report:
|
||||
|
||||
* **Contributing Code**: If you have new code or a bug fix, fork this
|
||||
repo, create a logically-named branch, and [submit a PR against this
|
||||
repo](https://github.com/helium/longfi-arduino). Include a
|
||||
write up of the PR with details on what it does.
|
||||
|
||||
* **Reporting Bugs**: Open an issue [against this
|
||||
repo](https://github.com/helium/longfi-arduino/issues) with as much
|
||||
detail as you can. At the very least you'll include steps to
|
||||
reproduce the problem.
|
||||
|
||||
This project is intended to be a safe, welcoming space for
|
||||
collaboration, and contributors are expected to adhere to the
|
||||
[Contributor Covenant Code of
|
||||
Conduct](http://contributor-covenant.org/).
|
||||
|
||||
Above all, thank you for taking the time to be a part of the Helium community.
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,63 @@
|
|||
# LongFi Arduino
|
||||
|
||||
## Installing the MCCI LMIC Library
|
||||
|
||||
From the Arduino IDE, open the Library Manager (Sketch->Include Library->Manage Libraries). In the search box, type MCCI and select the MCCI LoRaWAN LMIC library should be the first result.
|
||||
|
||||
![](https://cdn-learn.adafruit.com/assets/assets/000/062/526/medium800/feather_Library_Manager_MCCI.png?1537882799)
|
||||
|
||||
## Board Support
|
||||
|
||||
### B-L072Z-LRWAN1 - ST STM32L0 Discovery kit
|
||||
Install board support package, find instructions [here](https://github.com/stm32duino/Arduino_Core_STM32#getting-started).
|
||||
|
||||
Arduino IDE:
|
||||
1. Select Tools -> Board: -> Discovery
|
||||
2. Select Tools -> Board part number: -> Discovery L072Z-LRWAN1
|
||||
|
||||
[B-L072Z-LRWAN1 Product Page](https://www.st.com/en/evaluation-tools/b-l072z-lrwan1.html)
|
||||
[B-L072Z-LRWAN1 User Manual](https://www.st.com/content/ccc/resource/technical/document/user_manual/group0/ac/62/15/c7/60/ac/4e/9c/DM00329995/files/DM00329995.pdf/jcr:content/translations/en.DM00329995.pdf)
|
||||
|
||||
### Catena 4610 - MCCI
|
||||
Install board support package, find instructions [here](https://github.com/mcci-catena/Arduino_Core_STM32#getting-started).
|
||||
|
||||
Arduino IDE:
|
||||
Select Tools -> Board: -> MCCI Catena 4610.
|
||||
|
||||
[Catena 4610 Product Page](https://store.mcci.com/collections/iot-building-blocks/products/mcci-catena-4610-integrated-node-for-lorawan-technology)
|
||||
[Catena 4610 Pin Mapping Diagram](https://github.com/mcci-catena/HW-Designs/blob/master/Boards/Catena-4610/Catena-4610-Pinmapping.png)
|
||||
|
||||
### Feather M0 RFM96 - Adafruit
|
||||
|
||||
1. Add Adafruit package index, instructions [here](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/setup).
|
||||
2. Install both Arduino and Adafruit SAMD board support, instructions [here](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-with-arduino-ide#install-samd-support-6-5).
|
||||
3. (Windows Only) Install drivers, instructions [here](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-with-arduino-ide#install-drivers-windows-7-and-8-only-6-11)
|
||||
|
||||
[Adafruit Feather M0 with RFM95 Product Page](https://www.adafruit.com/product/3178)
|
||||
[Adafruit Feather M0 with RFM95 Datasheets & Files](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/downloads)
|
||||
|
||||
## Programming(Upload Method):
|
||||
|
||||
### B-L072Z-LRWAN1 - ST STM32L0 Discovery kit
|
||||
|
||||
#### STM32CubeProgrammer(SWD)
|
||||
Will use onboard ST-Link(Flasher/Debugger) to upload sketch.
|
||||
Download and Install required utility from ST [here](https://www.st.com/en/development-tools/stm32cubeprog.html).
|
||||
|
||||
Arduino IDE:
|
||||
Select Tools -> Upload Method -> STM32CubeProgrammer(SWD)
|
||||
|
||||
|
||||
### Catena 4610 - MCCI
|
||||
|
||||
#### DFU
|
||||
Arduino IDE:
|
||||
Select Tools -> Upload Method -> DFU
|
||||
|
||||
To put the board in DFU mode, hold down the boot button while pressing and releasing the reset button.
|
||||
|
||||
#### ST-Link
|
||||
Arduino IDE:
|
||||
Select Tools -> Upload Method -> STLink
|
||||
|
||||
Requires an ST-Link debugger connected to SWCLK, SWDIO, Vref, and GND, refer to pin mapping diagram.
|
|
@ -0,0 +1,345 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
|
||||
* Copyright (c) 2018 Terry Moore, MCCI
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to anyone
|
||||
* obtaining a copy of this document and accompanying files,
|
||||
* to do whatever they want with them without any restriction,
|
||||
* including, but not limited to, copying, modification and redistribution.
|
||||
* NO WARRANTY OF ANY KIND IS PROVIDED.
|
||||
*
|
||||
* This example sends a valid LoRaWAN packet with payload "Hello,
|
||||
* world!", using frequency and encryption settings matching those of
|
||||
* the The Things Network. It's pre-configured for the Adafruit
|
||||
* Feather M0 LoRa.
|
||||
*
|
||||
* This uses OTAA (Over-the-air activation), where where a DevEUI and
|
||||
* application key is configured, which are used in an over-the-air
|
||||
* activation procedure where a DevAddr and session keys are
|
||||
* assigned/generated for use with all further communication.
|
||||
*
|
||||
* Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in
|
||||
* g1, 0.1% in g2), but not the TTN fair usage policy (which is probably
|
||||
* violated by this sketch when left running for longer)!
|
||||
|
||||
* To use this sketch, first register your application and device with
|
||||
* the things network, to set or generate an AppEUI, DevEUI and AppKey.
|
||||
* Multiple devices can use the same AppEUI, but each device has its own
|
||||
* DevEUI and AppKey.
|
||||
*
|
||||
* Do not forget to define the radio type correctly in
|
||||
* arduino-lmic/project_config/lmic_project_config.h or from your BOARDS.txt.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <lmic.h>
|
||||
#include <arduino_lmic_hal_configuration.h>
|
||||
#include <arduino_lmic_hal_boards.h>
|
||||
#include <arduino_lmic_lorawan_compliance.h>
|
||||
#include <arduino_lmic_user_configuration.h>
|
||||
#include <arduino_lmic.h>
|
||||
#include <hal/hal.h>
|
||||
#include <SPI.h>
|
||||
|
||||
//
|
||||
// For normal use, we require that you edit the sketch to replace FILLMEIN
|
||||
// with values assigned by the TTN console. However, for regression tests,
|
||||
// we want to be able to compile these scripts. The regression tests define
|
||||
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
|
||||
// working but innocuous value.
|
||||
//
|
||||
#ifdef COMPILE_REGRESSION_TEST
|
||||
# define FILL_ME_IN 0
|
||||
#else
|
||||
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
|
||||
#endif
|
||||
|
||||
// This EUI must be in little-endian (LSB) format, so least-significant-byte
|
||||
// first. When copying an EUI from Helium console output, this means
|
||||
// you want to display the AppEUI as comma seperated bytes in "lsb" mode
|
||||
static const u1_t PROGMEM APPEUI[8]= { FILL_ME_IN };
|
||||
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
|
||||
|
||||
// This should also be in little endian format
|
||||
// These are user configurable values and Helium console permits anything
|
||||
static const u1_t PROGMEM DEVEUI[8]= { FILL_ME_IN };
|
||||
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
|
||||
|
||||
// This key should be in big endian (MSB) format (or, since it is not really a
|
||||
// number but a block of memory, endianness does not really apply). When copying
|
||||
// an AppKey from Helium console output, this means you want to display the AppKey
|
||||
// as comma seperated bytes in "msb" mode
|
||||
static const u1_t PROGMEM APPKEY[16] = { FILL_ME_IN };
|
||||
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
|
||||
|
||||
static uint8_t mydata[] = "Hello, world!";
|
||||
static osjob_t sendjob;
|
||||
|
||||
// Schedule TX every this many seconds (might become longer due to duty
|
||||
// cycle limitations).
|
||||
const unsigned TX_INTERVAL = 60;
|
||||
|
||||
// Pin mapping
|
||||
//
|
||||
// Adafruit BSPs are not consistent -- m0 express defs ARDUINO_SAMD_FEATHER_M0,
|
||||
// m0 defs ADAFRUIT_FEATHER_M0
|
||||
//
|
||||
#if defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0)
|
||||
// Pin mapping for Adafruit Feather M0 LoRa, etc.
|
||||
const lmic_pinmap lmic_pins = {
|
||||
.nss = 8,
|
||||
.rxtx = LMIC_UNUSED_PIN,
|
||||
.rst = 4,
|
||||
.dio = {3, 6, LMIC_UNUSED_PIN},
|
||||
.rxtx_rx_active = 0,
|
||||
.rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB
|
||||
.spi_freq = 8000000,
|
||||
};
|
||||
#elif defined(ARDUINO_AVR_FEATHER32U4)
|
||||
// Pin mapping for Adafruit Feather 32u4 LoRa, etc.
|
||||
// Just like Feather M0 LoRa, but uses SPI at 1MHz; and that's only
|
||||
// because MCCI doesn't have a test board; probably higher frequencies
|
||||
// will work.
|
||||
const lmic_pinmap lmic_pins = {
|
||||
.nss = 8,
|
||||
.rxtx = LMIC_UNUSED_PIN,
|
||||
.rst = 4,
|
||||
.dio = {7, 6, LMIC_UNUSED_PIN},
|
||||
.rxtx_rx_active = 0,
|
||||
.rssi_cal = 8, // LBT cal for the Adafruit Feather 32U4 LoRa, in dB
|
||||
.spi_freq = 1000000,
|
||||
};
|
||||
#elif defined(ARDUINO_CATENA_4551)
|
||||
// Pin mapping for Murata module / Catena 4551
|
||||
const lmic_pinmap lmic_pins = {
|
||||
.nss = 7,
|
||||
.rxtx = 29,
|
||||
.rst = 8,
|
||||
.dio = { 25, // DIO0 (IRQ) is D25
|
||||
26, // DIO1 is D26
|
||||
27, // DIO2 is D27
|
||||
},
|
||||
.rxtx_rx_active = 1,
|
||||
.rssi_cal = 10,
|
||||
.spi_freq = 8000000 // 8MHz
|
||||
};
|
||||
#elif defined(MCCI_CATENA_4610)
|
||||
#include "arduino_lmic_hal_boards.h"
|
||||
const lmic_pinmap lmic_pins = *Arduino_LMIC::GetPinmap_Catena4610();
|
||||
#elif defined(ARDUINO_DISCO_L072CZ_LRWAN1)
|
||||
namespace Arduino_LMIC {
|
||||
const HalPinmap_t GetPinmap_Disco_L072cz_Lrwan1();
|
||||
}
|
||||
const lmic_pinmap lmic_pins = Arduino_LMIC::GetPinmap_Disco_L072cz_Lrwan1();
|
||||
#else
|
||||
# error "Unknown target"
|
||||
#endif
|
||||
|
||||
void onEvent (ev_t ev) {
|
||||
Serial.print(os_getTime());
|
||||
Serial.print(": ");
|
||||
switch(ev) {
|
||||
case EV_SCAN_TIMEOUT:
|
||||
Serial.println(F("EV_SCAN_TIMEOUT"));
|
||||
break;
|
||||
case EV_BEACON_FOUND:
|
||||
Serial.println(F("EV_BEACON_FOUND"));
|
||||
break;
|
||||
case EV_BEACON_MISSED:
|
||||
Serial.println(F("EV_BEACON_MISSED"));
|
||||
break;
|
||||
case EV_BEACON_TRACKED:
|
||||
Serial.println(F("EV_BEACON_TRACKED"));
|
||||
break;
|
||||
case EV_JOINING:
|
||||
Serial.println(F("EV_JOINING"));
|
||||
break;
|
||||
case EV_JOIN_TXCOMPLETE:
|
||||
Serial.println(F("EV_JOIN_TXCOMPLETE"));
|
||||
break;
|
||||
case EV_JOINED:
|
||||
Serial.println(F("EV_JOINED"));
|
||||
{
|
||||
u4_t netid = 0;
|
||||
devaddr_t devaddr = 0;
|
||||
u1_t nwkKey[16];
|
||||
u1_t artKey[16];
|
||||
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
|
||||
Serial.print("netid: ");
|
||||
Serial.println(netid, DEC);
|
||||
Serial.print("devaddr: ");
|
||||
Serial.println(devaddr, HEX);
|
||||
Serial.print("artKey: ");
|
||||
for (size_t i=0; i<sizeof(artKey); ++i) {
|
||||
if (i != 0)
|
||||
Serial.print("-");
|
||||
Serial.print(artKey[i], HEX);
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.print("nwkKey: ");
|
||||
for (size_t i=0; i<sizeof(nwkKey); ++i) {
|
||||
if (i != 0)
|
||||
Serial.print("-");
|
||||
Serial.print(nwkKey[i], HEX);
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
// Disable link check validation (automatically enabled
|
||||
// during join, but because slow data rates change max TX
|
||||
// size, we don't use it in this example.
|
||||
LMIC_setLinkCheckMode(0);
|
||||
break;
|
||||
/*
|
||||
|| This event is defined but not used in the code. No
|
||||
|| point in wasting codespace on it.
|
||||
||
|
||||
|| case EV_RFU1:
|
||||
|| Serial.println(F("EV_RFU1"));
|
||||
|| break;
|
||||
*/
|
||||
case EV_JOIN_FAILED:
|
||||
Serial.println(F("EV_JOIN_FAILED"));
|
||||
break;
|
||||
case EV_REJOIN_FAILED:
|
||||
Serial.println(F("EV_REJOIN_FAILED"));
|
||||
break;
|
||||
break;
|
||||
case EV_TXCOMPLETE:
|
||||
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
|
||||
if (LMIC.txrxFlags & TXRX_ACK)
|
||||
Serial.println(F("Received ack"));
|
||||
if (LMIC.dataLen) {
|
||||
Serial.println(F("Received "));
|
||||
Serial.println(LMIC.dataLen);
|
||||
Serial.println(F(" bytes of payload"));
|
||||
}
|
||||
// Schedule next transmission
|
||||
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
|
||||
break;
|
||||
case EV_LOST_TSYNC:
|
||||
Serial.println(F("EV_LOST_TSYNC"));
|
||||
break;
|
||||
case EV_RESET:
|
||||
Serial.println(F("EV_RESET"));
|
||||
break;
|
||||
case EV_RXCOMPLETE:
|
||||
// data received in ping slot
|
||||
Serial.println(F("EV_RXCOMPLETE"));
|
||||
break;
|
||||
case EV_LINK_DEAD:
|
||||
Serial.println(F("EV_LINK_DEAD"));
|
||||
break;
|
||||
case EV_LINK_ALIVE:
|
||||
Serial.println(F("EV_LINK_ALIVE"));
|
||||
break;
|
||||
/*
|
||||
|| This event is defined but not used in the code. No
|
||||
|| point in wasting codespace on it.
|
||||
||
|
||||
|| case EV_SCAN_FOUND:
|
||||
|| Serial.println(F("EV_SCAN_FOUND"));
|
||||
|| break;
|
||||
*/
|
||||
case EV_TXSTART:
|
||||
Serial.println(F("EV_TXSTART"));
|
||||
break;
|
||||
default:
|
||||
Serial.print(F("Unknown event: "));
|
||||
Serial.println((unsigned) ev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void do_send(osjob_t* j){
|
||||
// Check if there is not a current TX/RX job running
|
||||
if (LMIC.opmode & OP_TXRXPEND) {
|
||||
Serial.println(F("OP_TXRXPEND, not sending"));
|
||||
} else {
|
||||
// Prepare upstream data transmission at the next possible time.
|
||||
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
|
||||
Serial.println(F("Packet queued"));
|
||||
}
|
||||
// Next TX is scheduled after TX_COMPLETE event.
|
||||
}
|
||||
|
||||
void setup() {
|
||||
delay(5000);
|
||||
while (! Serial)
|
||||
;
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("Starting"));
|
||||
|
||||
#if defined(ARDUINO_DISCO_L072CZ_LRWAN1)
|
||||
SPI.setMOSI(RADIO_MOSI_PORT);
|
||||
SPI.setMISO(RADIO_MISO_PORT);
|
||||
SPI.setSCLK(RADIO_SCLK_PORT);
|
||||
SPI.setSSEL(RADIO_NSS_PORT);
|
||||
// SPI.begin();
|
||||
#endif
|
||||
|
||||
#ifdef VCC_ENABLE
|
||||
// For Pinoccio Scout boards
|
||||
pinMode(VCC_ENABLE, OUTPUT);
|
||||
digitalWrite(VCC_ENABLE, HIGH);
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
// LMIC init
|
||||
os_init();
|
||||
// Reset the MAC state. Session and pending data transfers will be discarded.
|
||||
LMIC_reset();
|
||||
|
||||
LMIC_setLinkCheckMode(0);
|
||||
LMIC_setDrTxpow(DR_SF8, 20);
|
||||
LMIC_selectSubBand(6);
|
||||
|
||||
// Start job (sending automatically starts OTAA too)
|
||||
do_send(&sendjob);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
os_runloop_once();
|
||||
}
|
||||
|
||||
namespace Arduino_LMIC {
|
||||
|
||||
class HalConfiguration_Disco_L072cz_Lrwan1_t : public HalConfiguration_t
|
||||
{
|
||||
public:
|
||||
enum DIGITAL_PINS : uint8_t
|
||||
{
|
||||
PIN_SX1276_NSS = 37,
|
||||
PIN_SX1276_NRESET = 33,
|
||||
PIN_SX1276_DIO0 = 38,
|
||||
PIN_SX1276_DIO1 = 39,
|
||||
PIN_SX1276_DIO2 = 40,
|
||||
PIN_SX1276_RXTX = 21,
|
||||
};
|
||||
|
||||
virtual bool queryUsingTcxo(void) override { return false; };
|
||||
};
|
||||
// save some typing by bringing the pin numbers into scope
|
||||
static HalConfiguration_Disco_L072cz_Lrwan1_t myConfig;
|
||||
|
||||
static const HalPinmap_t myPinmap =
|
||||
{
|
||||
.nss = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_NSS,
|
||||
.rxtx = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_RXTX,
|
||||
.rst = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_NRESET,
|
||||
|
||||
.dio = {HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO0,
|
||||
HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO1,
|
||||
HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO2,
|
||||
},
|
||||
.rxtx_rx_active = 1,
|
||||
.rssi_cal = 10,
|
||||
.spi_freq = 8000000, /* 8MHz */
|
||||
.pConfig = &myConfig
|
||||
};
|
||||
|
||||
const HalPinmap_t GetPinmap_Disco_L072cz_Lrwan1(void)
|
||||
{
|
||||
return myPinmap;
|
||||
}
|
||||
|
||||
}; // end namespace Arduino_LMIC
|
Ładowanie…
Reference in New Issue