Dear forum participants,
Currently I am testing with an
Arduino UNO, Dragino Shield v1.4,
to transfer the distance values of a radar sensor into the TTN.
The radar sensor is connected via Pin3 and Pin4 (at the plugged Dragino Shield).
(3,4 pin selection was made because these are not occupied by Dragino Lora Shield and the sensor data can be displayed in the serial monitor).
To test the Dragino/Uno connection to TTN,I used a “HelloWorld”-Sketch ->Works!
To test the sensor and display the distance values in the Serial Monitor I used another test script. ->Works!
Now I would have to combine the two sketches to send the distance values to TTN.
Can you give me a few tips in this regard?
Lora-TTN-HelloWorld:
#include <lmic.h>
#include <hal/hal.h>
#ifdef CREDENTIALS
static const u1_t NWKSKEY[16] = NWKSKEY1;
static const u1_t APPSKEY[16] = APPSKEY1;
static const u4_t DEVADDR = DEVADDR1;
#else
static const u1_t NWKSKEY[16] = { 0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,};
static const u1_t APPSKEY[16] = { 0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,0xXX, 0xXX, 0xXX, 0xXX,};
static const u4_t DEVADDR = 0x12345678;
#endif
// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
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 Dragino Shield
const lmic_pinmap lmic_pins = {
.nss = 10,
.rxtx = LMIC_UNUSED_PIN,
.rst = 9,
.dio = {2, 6, 7},
};
void onEvent (ev_t ev) {
if (ev == EV_TXCOMPLETE) {
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
}
}
void do_send(osjob_t* j){
// Payload to send (uplink)
static uint8_t message[] = "HelloWorldDragino";
// 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, message, sizeof(message)-1, 0);
Serial.println(F("Sending uplink packet..."));
}
// Next TX is scheduled after TX_COMPLETE event.
}
void setup() {
Serial.begin(115200);
Serial.println(F("Starting..."));
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// Set static session parameters.
LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
// Disable link check validation
LMIC_setLinkCheckMode(0);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF12,14);
// Start job
do_send(&sendjob);
}
void loop() {
os_runloop_once();
}
Radar-Sensor SoftSerial-Test:
#include <SoftwareSerial.h>
SoftwareSerial RadarSerial(4, 3);
void setup() {
Serial.begin(19200);
// set the data rate for the SoftwareSerial port
RadarSerial.begin(19200);
}
void loop() { // run over and over
if (RadarSerial.available()) {
Serial.write(RadarSerial.read());
}
if (Serial.available()) {
RadarSerial.write(Serial.read());
}
}
Thank you very much in advance