-
-
Save newkton1/da8cc2ff020ecdf8c434d513c692ca43 to your computer and use it in GitHub Desktop.
Another Attempt with Elecrow Lora Node v1.0 using Paul's modified First steps with LoRa Radio Node (Arduino) tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
avrdude: Version 6.3-20190619 | |
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ | |
Copyright (c) 2007-2014 Joerg Wunsch | |
System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf" | |
User configuration file is "/Users/roberthancock/.avrduderc" | |
User configuration file does not exist or is not a regular file, skipping | |
Using Port : /dev/cu.usbserial-00000000 | |
Using Programmer : arduino | |
Overriding Baud Rate : 57600 | |
AVR Part : ATmega328P | |
Chip Erase delay : 9000 us | |
PAGEL : PD7 | |
BS2 : PC2 | |
RESET disposition : dedicated | |
RETRY pulse : SCK | |
serial program mode : yes | |
parallel program mode : yes | |
Timeout : 200 | |
StabDelay : 100 | |
CmdexeDelay : 25 | |
SyncLoops : 32 | |
ByteDelay : 0 | |
PollIndex : 3 | |
PollValue : 0x53 | |
Memory Detail : | |
Block Poll Page Polled | |
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack | |
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- | |
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff | |
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff | |
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 | |
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 | |
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 | |
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 | |
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00 | |
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00 | |
Programmer Type : Arduino | |
Description : Arduino | |
Hardware Version: 2 | |
Firmware Version: 1.16 | |
Vtarget : 0.0 V | |
Varef : 0.0 V | |
Oscillator : Off | |
SCK period : 0.1 us | |
avrdude: AVR device initialized and ready to accept instructions | |
Reading | ################################################## | 100% 0.00s | |
avrdude: Device signature = 0x1e950f (probably m328p) | |
avrdude: reading input file "/var/folders/wg/cvn1t_xj5qzdjb0ktl5hfkjm0000gn/T/arduino_build_6295/ttn-otaaLoraNode2.ino.hex" | |
avrdude: writing flash (21486 bytes): | |
Writing | ################################################## | 100% 10.74s | |
avrdude: 21486 bytes of flash written | |
avrdude: verifying flash memory against /var/folders/wg/cvn1t_xj5qzdjb0ktl5hfkjm0000gn/T/arduino_build_6295/ttn-otaaLoraNode2.ino.hex: | |
avrdude: load data flash data from input file /var/folders/wg/cvn1t_xj5qzdjb0ktl5hfkjm0000gn/T/arduino_build_6295/ttn-otaaLoraNode2.ino.hex: | |
avrdude: input file /var/folders/wg/cvn1t_xj5qzdjb0ktl5hfkjm0000gn/T/arduino_build_6295/ttn-otaaLoraNode2.ino.hex contains 21486 bytes | |
avrdude: reading on-chip flash data: | |
Reading | ################################################## | 100% 9.07s | |
avrdude: verifying ... | |
avrdude: 21486 bytes of flash verified | |
avrdude done. Thank you. | |
No files were added to the sketch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2014-2016 IBM Corporation. | |
* Copyright (c) 2016-2017 MCCI Corporation. | |
* 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 <organization> 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 <COPYRIGHT HOLDER> 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. | |
*/ | |
#define LMIC_DR_LEGACY 0 | |
#include "lmic.h" | |
extern const struct lmic_pinmap lmic_pins; | |
// RUNTIME STATE | |
static struct { | |
osjob_t* scheduledjobs; | |
osjob_t* runnablejobs; | |
} OS; | |
int os_init_ex (const void *pintable) { | |
memset(&OS, 0x00, sizeof(OS)); | |
hal_init_ex(pintable); | |
if (! radio_init()) | |
return 0; | |
LMIC_init(); | |
return 1; | |
} | |
void os_init() { | |
if (os_init_ex((const void *)&lmic_pins)) | |
return; | |
ASSERT(0); | |
} | |
ostime_t os_getTime () { | |
return hal_ticks(); | |
} | |
// unlink job from queue, return if removed | |
static int unlinkjob (osjob_t** pnext, osjob_t* job) { | |
for( ; *pnext; pnext = &((*pnext)->next)) { | |
if(*pnext == job) { // unlink | |
*pnext = job->next; | |
return 1; | |
} | |
} | |
return 0; | |
} | |
// clear scheduled job | |
void os_clearCallback (osjob_t* job) { | |
hal_disableIRQs(); | |
// if it's not in the scheduled jobs, look in the runnable... | |
if (! unlinkjob(&OS.scheduledjobs, job)) | |
unlinkjob(&OS.runnablejobs, job); | |
hal_enableIRQs(); | |
} | |
// schedule immediately runnable job | |
void os_setCallback (osjob_t* job, osjobcb_t cb) { | |
osjob_t** pnext; | |
hal_disableIRQs(); | |
// remove if job was already queued | |
unlinkjob(&OS.runnablejobs, job); | |
// fill-in job | |
job->func = cb; | |
job->next = NULL; | |
// add to end of run queue | |
for(pnext=&OS.runnablejobs; *pnext; pnext=&((*pnext)->next)); | |
*pnext = job; | |
hal_enableIRQs(); | |
} | |
// schedule timed job | |
void os_setTimedCallback (osjob_t* job, ostime_t time, osjobcb_t cb) { | |
osjob_t** pnext; | |
hal_disableIRQs(); | |
// remove if job was already queued | |
unlinkjob(&OS.scheduledjobs, job); | |
// fill-in job | |
job->deadline = time; | |
job->func = cb; | |
job->next = NULL; | |
// insert into schedule | |
for(pnext=&OS.scheduledjobs; *pnext; pnext=&((*pnext)->next)) { | |
if((*pnext)->deadline - time > 0) { // (cmp diff, not abs!) | |
// enqueue before next element and stop | |
job->next = *pnext; | |
break; | |
} | |
} | |
*pnext = job; | |
hal_enableIRQs(); | |
} | |
// execute jobs from timer and from run queue | |
void os_runloop () { | |
while(1) { | |
os_runloop_once(); | |
} | |
} | |
void os_runloop_once() { | |
osjob_t* j = NULL; | |
hal_disableIRQs(); | |
// check for runnable jobs | |
if(OS.runnablejobs) { | |
j = OS.runnablejobs; | |
OS.runnablejobs = j->next; | |
} else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs | |
j = OS.scheduledjobs; | |
OS.scheduledjobs = j->next; | |
} else { // nothing pending | |
hal_sleep(); // wake by irq (timer already restarted) | |
} | |
hal_enableIRQs(); | |
if(j) { // run job callback | |
j->func(j); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
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. | |
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 <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 FILLMEIN 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 format, so least-significant-byte | |
// first. When copying an EUI from ttnctl output, this means to reverse | |
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, | |
// 0x70. | |
static const u1_t PROGMEM APPEUI[8] = { 0x89, 0x0B, 0x02, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 }; | |
void os_getArtEui (u1_t* buf) { | |
memcpy_P(buf, APPEUI, 8); | |
} | |
// This should also be in little endian format, see above. | |
static const u1_t PROGMEM DEVEUI[8] = { 0x1F, 0xF1, 0xCB, 0x43, 0x42, 0x7E, 0x3A, 0x00 }; | |
void os_getDevEui (u1_t* buf) { | |
memcpy_P(buf, DEVEUI, 8); | |
} | |
// This key should be in big endian format (or, since it is not really a | |
// number but a block of memory, endianness does not really apply). In | |
// practice, a key taken from ttnctl can be copied as-is. | |
static const u1_t PROGMEM APPKEY[16] = { 0xD8, 0x6E, 0x6B, 0x83, 0x8A, 0x6E, 0xA5, 0xA5, 0x03, 0xEE, 0x5A, 0xE9, 0x6A, 0xF2, 0xD8, 0xFE }; | |
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 | |
const lmic_pinmap lmic_pins = { | |
.nss = 10, | |
.rxtx = LMIC_UNUSED_PIN, | |
.rst = 9, | |
.dio = {2, 5, LMIC_UNUSED_PIN}, | |
}; | |
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_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 (unsigned int i = 0; i < sizeof(artKey); ++i) { | |
Serial.print(artKey[i], HEX); | |
} | |
Serial.println(""); | |
Serial.print("nwkKey: "); | |
for (unsigned int i = 0; i < sizeof(nwkKey); ++i) { | |
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; | |
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.print(F("Received ")); | |
Serial.print(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() { | |
Serial.begin(9600); | |
Serial.println(F("Starting")); | |
// LMIC init | |
os_init(); | |
// Reset the MAC state. Session and pending data transfers will be discarded. | |
LMIC_reset(); | |
LMIC_setClockError(MAX_CLOCK_ERROR * 2 / 100); | |
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band | |
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band | |
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band | |
LMIC_setLinkCheckMode(0); | |
LMIC.dn2Dr = SF9; | |
LMIC_setDrTxpow(DR_SF7,14); | |
// Start job (sending automatically starts OTAA too) | |
do_send(&sendjob); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Sketch compiles and uploads OK to an Elecrow LoraNode board but the Serial Monitor result is as shown in attached screenshot. The Elecrow board has an RFM95 mounted on an Arduino board with Pro/Pro Mini bootloader. Paul's tutorial, which I followed is here:
https://www.disk91.com/2019/technology/lora/first-steps-with-lora-radio-node-arduino/
Obviously still doing something wrong.