Programming the Adafruit Feather
Before we start we have you enable the LMIC library. I used the Library from Matthijs Kooijman, because it need less space on the Adafruit Feather.
Next you should create an TTN application with a device and change the device activation method to ABP. Copy the devices network session key and app session key in msb format an also copy the device address.
Now go to your libraries folder an open the ttn-apb example in arduino-lmic-master/examples/ttn-abp.
Edit the keys:
// LoRaWAN NwkSKey, network session key
// This is the default Semtech key, which is used by the early prototype TTN
// network.
static const PROGMEM u1_t NWKSKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
// LoRaWAN AppSKey, application session key
// This is the default Semtech key, which is used by the early prototype TTN
// network.
static const u1_t PROGMEM APPSKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
// LoRaWAN end-device address (DevAddr)
static const u4_t DEVADDR = 0x03FF0001 ; // <-- Change this address for every node!
Edit the pin mapping:
// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {7, 6, LMIC_UNUSED_PIN},
};
Edit the do_send function:
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.
#define VBATPIN A9
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2; // we divided by 2, so multiply back
measuredvbat *= 3.3; // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage
byte buffer[8];
dtostrf(measuredvbat, 1, 2, buffer);
String res = buffer;
res.getBytes(buffer, res.length() + 1);
Serial.print("VBat: " ); Serial.println(measuredvbat);
LMIC_setTxData2(1, (uint8_t*) buffer, res.length(), 0);
Serial.println(F("Packet queued"));
}
// Next TX is scheduled after TX_COMPLETE event.
}
Ok, we are ready for uploading the program.