#include #include #include // LORA credentials - replace with yours static const u1_t PROGMEM DEVEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u1_t PROGMEM APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u1_t PROGMEM APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Pin mapping for Arduino const lmic_pinmap lmic_pins = { .nss = 10, .rxtx = LMIC_UNUSED_PIN, .rst = 9, .dio = {2, 3, 4}, }; void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8); } void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8); } void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16); } static uint8_t data[3]; static osjob_t sendjob; // Schedule data transmission const unsigned TX_INTERVAL = 10; void onEvent (ev_t ev) { Serial.print(os_getTime()); Serial.print(": "); switch(ev) { case EV_JOINING: Serial.println(F("EV_JOINING")); break; case EV_JOINED: Serial.println(F("EV_JOINED")); LMIC_setLinkCheckMode(0); break; case EV_TXCOMPLETE: Serial.println(F("EV_TXCOMPLETE")); 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")); } os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send); break; default: Serial.print(F("Unknown event: ")); Serial.println((unsigned) ev); break; } } void do_send(osjob_t* j) { if (LMIC.opmode & OP_TXRXPEND) { Serial.println(F("OP_TXRXPEND, not sending")); return; } // Prepare data int x = 1; int y = 1; data[0] = x; data[1] = y; Serial.println(F("X: ")); Serial.println(x); Serial.println(F("Y: ")); Serial.println(y); // Prepare upstream data transmission at the next possible time LMIC_setTxData2(1, data, sizeof(data), 1); Serial.println(F("Packet queued")); } void setup() { Serial.begin(9600); Serial.println(F("Starting")); // LMIC init os_init(); LMIC_reset(); // Start job do_send(&sendjob); } void loop() { os_runloop_once(); }