From 12f048cc39079522a09fdf27e947880f37cfda14 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sat, 31 Aug 2019 09:14:59 +0200 Subject: [PATCH] do unjoin when started --- mini-beieli-node.ino | 51 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index 8d90192..3974482 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -253,7 +253,7 @@ void setup(void) /* for 4451, we need wider tolerances, it seems */ #if defined(ARDUINO_ARCH_STM32) - LMIC_setClockError(10 * 65536 / 100); + LMIC_setClockError(MAX_CLOCK_ERROR * 10 / 100); #endif setup_flash(); @@ -365,9 +365,10 @@ void setup_platform(void) gCatena.SafePrintf("**** no platform, check provisioning ****\n"); flags = 0; } - // Because of Alarms on Swisscom Network - LMIC_setDrTxpow(DR_SF10, 14); - LMIC_setAdrMode(1); + + // Swisscom temporary fix... + //LMIC_setDrTxpow(DR_SF10,14); + //LMIC_setAdrMode(1); } void setup_bme280(void) @@ -399,9 +400,6 @@ bool setup_scales(void) // - With a gain factor of 32, channel B is selected // By omitting the gain factor parameter, the library // default "128" (Channel A) is used here. -#ifdef DEBUG - gCatena.SafePrintf("Setup Scale 1...\n"); -#endif LoadCell.begin(A1, A0); if (!(LoadCell.wait_ready_timeout(2000))) { @@ -433,6 +431,9 @@ void setup_flash(void) void setup_uplink(void) { + // Do an unjoin, so every reboot will trigger a join + LMIC_unjoin(); + /* trigger a join by sending the first packet */ if (!(gCatena.GetOperatingFlags() & static_cast(gCatena.OPERATING_FLAGS::fManufacturingTest))) { if (!gLoRaWAN.IsProvisioned()) @@ -615,13 +616,13 @@ void ReadSensors(bool firstTime, bool readOnly) fUsbPower = (vBus > 3.0) ? true : false; // Setup Scales - setup_scales(); + //setup_scales(); // Read Scales //if (LoadCell.is_ready()) { if (setup_scales()) { #ifdef DEBUG - Serial.println("HX711 LoadCell is ready."); + gCatena.SafePrintf("HX711 LoadCell is ready.\n"); #endif LoadCell.set_gain(128); long w1 = LoadCell.read_average(5); @@ -639,7 +640,7 @@ void ReadSensors(bool firstTime, bool readOnly) #endif } else { - Serial.println("HX711 LoadCell not ready."); + gCatena.SafePrintf("HX711 LoadCell not ready.\n"); } // Disable Power @@ -724,7 +725,7 @@ void ReadSensors(bool firstTime, bool readOnly) startSendingUplink(firstTime); } else { gCatena.SafePrintf("now going to sleep for 6 minutes...\n"); - Serial.flush(); + //Serial.flush(); gLed.Set(LedPattern::Sleeping); os_setTimedCallback( &sensorJob, @@ -813,6 +814,15 @@ static void settleDoneCb( #ifdef DEBUG gCatena.SafePrintf("settleDoneCb\n"); #endif +// Terry vv + gCatena.SafePrintf("LMIC.rxDelay: %i\n",LMIC.rxDelay); + gCatena.SafePrintf("LMIC.dn2Dr: %i\n",LMIC.dn2Dr); + gCatena.SafePrintf("LMIC.dn2Freq: %i\n",LMIC.dn2Freq); + gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n",LMIC.rx1DrOffset); + +// Terry ^^ + + sleepDoneCb(pSendJob); } @@ -839,6 +849,25 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage #ifdef DEBUG gCatena.SafePrintf("receiveMessage was called!!!\n"); #endif +// Terry vv + if (port == 0) + { + gCatena.SafePrintf("MAC message:"); + for (unsigned i = 0; i < LMIC.dataBeg; ++i) + { + gCatena.SafePrintf(" %02x", LMIC.frame[i]); + } + return; + } + + gCatena.SafePrintf("receiveMessage was called!!!!n"); + gCatena.SafePrintf("Port: %s\n",port); + gCatena.SafePrintf("LMIC.rxDelay: %i\n",LMIC.rxDelay); + gCatena.SafePrintf("LMIC.dn2Dr: %i\n",LMIC.dn2Dr); + gCatena.SafePrintf("LMIC.dn2Freq: %i\n",LMIC.dn2Freq); + gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n",LMIC.rx1DrOffset); + +// Terry ^^ if (! (port == 1 && 2 <= nMessage && nMessage <= 3)) {