diff --git a/src/main.cpp b/src/main.cpp index e48a60f..03f0c79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,15 +123,15 @@ const lmic_pinmap lmic_pins = { void printHex2(unsigned v) { v &= 0xff; if (v < 16) - Serial.print('0'); - Serial.print(v, HEX); + Serial1.print('0'); + Serial1.print(v, HEX); } void do_send(__attribute__((unused)) 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")); + Serial1.println(F("OP_TXRXPEND, not sending")); } else { // Prepare upstream data transmission at the next possible time. MessenSensoren(); @@ -140,56 +140,56 @@ void do_send(__attribute__((unused)) osjob_t *j) { LMIC_setDrTxpow(DR_SF7, 10); LMIC_setTxData2(1, buffer, size, 0); - Serial.println(F("Packet queued")); + Serial1.println(F("Packet queued")); } // Next TX is scheduled after TX_COMPLETE event. } void onEvent(ev_t ev) { - Serial.print(os_getTime()); - Serial.print(": "); + Serial1.print(os_getTime()); + Serial1.print(": "); switch (ev) { case EV_SCAN_TIMEOUT: - Serial.println(F("EV_SCAN_TIMEOUT")); + Serial1.println(F("EV_SCAN_TIMEOUT")); break; case EV_BEACON_FOUND: - Serial.println(F("EV_BEACON_FOUND")); + Serial1.println(F("EV_BEACON_FOUND")); break; case EV_BEACON_MISSED: - Serial.println(F("EV_BEACON_MISSED")); + Serial1.println(F("EV_BEACON_MISSED")); break; case EV_BEACON_TRACKED: - Serial.println(F("EV_BEACON_TRACKED")); + Serial1.println(F("EV_BEACON_TRACKED")); break; case EV_JOINING: - Serial.println(F("EV_JOINING")); + Serial1.println(F("EV_JOINING")); break; case EV_JOINED: - Serial.println(F("EV_JOINED")); + Serial1.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("AppSKey: "); + Serial1.print("netid: "); + Serial1.println(netid, DEC); + Serial1.print("devaddr: "); + Serial1.println(devaddr, HEX); + Serial1.print("AppSKey: "); for (size_t i = 0; i < sizeof(artKey); ++i) { if (i != 0) - Serial.print("-"); + Serial1.print("-"); printHex2(artKey[i]); } - Serial.println(""); - Serial.print("NwkSKey: "); + Serial1.println(""); + Serial1.print("NwkSKey: "); for (size_t i = 0; i < sizeof(nwkKey); ++i) { if (i != 0) - Serial.print("-"); + Serial1.print("-"); printHex2(nwkKey[i]); } - Serial.println(); + Serial1.println(); } // Disable link check validation (automatically enabled // during join, but because slow data rates change max TX @@ -201,95 +201,99 @@ void onEvent(ev_t ev) { || point in wasting codespace on it. || || case EV_RFU1: - || Serial.println(F("EV_RFU1")); + || Serial1.println(F("EV_RFU1")); || break; */ case EV_JOIN_FAILED: - Serial.println(F("EV_JOIN_FAILED")); + Serial1.println(F("EV_JOIN_FAILED")); break; case EV_REJOIN_FAILED: - Serial.println(F("EV_REJOIN_FAILED")); + Serial1.println(F("EV_REJOIN_FAILED")); break; case EV_TXCOMPLETE: - Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); + Serial1.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); if (LMIC.txrxFlags & TXRX_ACK) - Serial.println(F("Received ack")); + Serial1.println(F("Received ack")); if (LMIC.dataLen) { - Serial.print(F("Received ")); - Serial.print(LMIC.dataLen); - Serial.print(F(" bytes of payload: ")); + Serial1.print(F("Received ")); + Serial1.print(LMIC.dataLen); + Serial1.print(F(" bytes of payload: ")); for (int i = 0; i < LMIC.dataLen; i++) { - if (LMIC.frame[LMIC.dataBeg + i] < 0x10) { Serial.print(F("0")); } - Serial.print(LMIC.frame[LMIC.dataBeg + i], HEX); - Serial.print(F(" ")); + if (LMIC.frame[LMIC.dataBeg + i] < 0x10) { Serial1.print(F("0")); } + Serial1.print(LMIC.frame[LMIC.dataBeg + i], HEX); + Serial1.print(F(" ")); } - Serial.println(F("")); + Serial1.println(F("")); } // Schedule next transmission os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send); - - Serial.println(F("vor sleep")); - Serial.flush(); + /* + Serial1.println(F("vor sleep")); + Serial1.flush(); LowPower.sleep(1000); - Serial.println(F("wieder aufgewacht")); // => er wacht nicht wieder auf - + Serial1.println(F("wieder aufgewacht")); // => er wacht nicht wieder auf +*/ break; case EV_LOST_TSYNC: - Serial.println(F("EV_LOST_TSYNC")); + Serial1.println(F("EV_LOST_TSYNC")); break; case EV_RESET: - Serial.println(F("EV_RESET")); + Serial1.println(F("EV_RESET")); break; case EV_RXCOMPLETE: // data received in ping slot - Serial.println(F("EV_RXCOMPLETE")); + Serial1.println(F("EV_RXCOMPLETE")); break; case EV_LINK_DEAD: - Serial.println(F("EV_LINK_DEAD")); + Serial1.println(F("EV_LINK_DEAD")); break; case EV_LINK_ALIVE: - Serial.println(F("EV_LINK_ALIVE")); + Serial1.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")); + || Serial1.println(F("EV_SCAN_FOUND")); || break; */ case EV_TXSTART: - Serial.println(F("EV_TXSTART")); + Serial1.println(F("EV_TXSTART")); break; case EV_TXCANCELED: - Serial.println(F("EV_TXCANCELED")); + Serial1.println(F("EV_TXCANCELED")); break; case EV_RXSTART: /* do not print anything -- it wrecks timing */ break; case EV_JOIN_TXCOMPLETE: - Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept")); + Serial1.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept")); break; default: - Serial.print(F("Unknown event: ")); - Serial.println((unsigned) ev); + Serial1.print(F("Unknown event: ")); + Serial1.println((unsigned) ev); break; } } void setup() { - delay(5000); + //delay(5000); //while (!Serial); - Serial.begin(19200); - Serial.println(F("Starting 1.04")); + + // usb auschalten + USBDevice.detach(); + + Serial1.begin(19200); + Serial1.println(F("Starting 1.04")); #ifdef __SAMD21G18A__ - Serial.println(F("SAMD21G18A ARM Cortex-M0+ detected")); + Serial1.println(F("SAMD21G18A ARM Cortex-M0+ detected")); #endif #ifdef ARDUINO_SAMD_FEATHER_M0 - Serial.println(F("defined for Feather M0 Board")); + Serial1.println(F("defined for Feather M0 Board")); #endif init_Messen(); @@ -298,7 +302,7 @@ void setup() { #ifdef CFG_eu868 - Serial.println(F("Using EU868")); + Serial1.println(F("Using EU868")); #endif