Compare commits

..
15 Commits
4 changed files with 131 additions and 285 deletions
+19
View File
@@ -31,5 +31,24 @@ Das sind die verwendeten Libraries [1]:
| https://github.com/mcci-catena/SHT1x.git | be7042c | Tue, 20 Sep 2011 13:56:23 +1000 | | https://github.com/mcci-catena/SHT1x.git | be7042c | Tue, 20 Sep 2011 13:56:23 +1000 |
Patch arduino-lmic, so initial SF10 is used initially:
`
[joerg@cinnamon src]$ git diff
diff --git a/src/lmic/lmic_bandplan_eu868.h b/src/lmic/lmic_bandplan_eu868.h
index efff7d5..74efb37 100644
--- a/src/lmic/lmic_bandplan_eu868.h
+++ b/src/lmic/lmic_bandplan_eu868.h
@@ -61,7 +61,7 @@ LMICeu868_isValidBeacon1(const uint8_t *d) {
#undef LMICbandplan_isFSK
#define LMICbandplan_isFSK() (/* RX datarate */LMIC.dndr == EU868_DR_FSK)
-#define LMICbandplan_getInitialDrJoin() (EU868_DR_SF7)
+#define LMICbandplan_getInitialDrJoin() (EU868_DR_SF10)
void LMICeu868_setBcnRxParams(void);
#define LMICbandplan_setBcnRxParams() LMICeu868_setBcnRxParams()
`
`[1]: `[1]:
[joerg@cinnamon libraries]$ for i in Adafruit_BME280_Library Adafruit_Sensor arduino-lmic arduino-lorawan Catena-Arduino-Platform Catena-mcciadk MCCI_FRAM_I2C Q2-HX711-Arduino-Library SparkFun_Qwiic_Scale_NAU7802_Arduino_Library OneWire SHT1x ; do cd $i; echo "| $(git remote -v |grep fetch |awk '{print $2}' |tr '\n' ' ') | $(git log --pretty=format:'%h | %cD ' -n 1) |" ; cd ..; done` [joerg@cinnamon libraries]$ for i in Adafruit_BME280_Library Adafruit_Sensor arduino-lmic arduino-lorawan Catena-Arduino-Platform Catena-mcciadk MCCI_FRAM_I2C Q2-HX711-Arduino-Library SparkFun_Qwiic_Scale_NAU7802_Arduino_Library OneWire SHT1x ; do cd $i; echo "| $(git remote -v |grep fetch |awk '{print $2}' |tr '\n' ' ') | $(git log --pretty=format:'%h | %cD ' -n 1) |" ; cd ..; done`
+101 -279
View File
@@ -143,17 +143,10 @@ bool fFlash;
bool fUsbPower; bool fUsbPower;
// have we printed the sleep info? // have we printed the sleep info?
bool g_fPrintedSleeping = false;
// the job that's used to synchronize us with the LMIC code // the job that's used to synchronize us with the LMIC code
static osjob_t iterationJob; static osjob_t iterationJob;
static osjob_t sendJob; static osjob_t sendJob;
// the cycle time to use
unsigned gTxCycle;
// remaining before we reset to default
unsigned gTxCycleCount;
void setup(void) void setup(void)
{ {
gCatena.begin(); gCatena.begin();
@@ -253,7 +246,6 @@ void setup_platform(void)
} }
gLoRaWAN.SetReceiveBufferBufferCb(receiveMessage); gLoRaWAN.SetReceiveBufferBufferCb(receiveMessage);
setTxCycleTime(CATCFG_T_CYCLE_INITIAL, CATCFG_INTERVAL_COUNT_INITIAL);
gCatena.registerObject(&gLoRaWAN); gCatena.registerObject(&gLoRaWAN);
/* find the platform */ /* find the platform */
@@ -348,6 +340,9 @@ void setup_uplink(void)
LMIC_setClockError(1 * 65536 / 100); LMIC_setClockError(1 * 65536 / 100);
// explicitly enable LinkCheckMode
gLoRaWAN.SetLinkCheckMode(true);
/* figure out when to reboot */ /* figure out when to reboot */
gRebootMs = (CATCFG_T_REBOOT + os_getRndU2() - 32768) * 1000; gRebootMs = (CATCFG_T_REBOOT + os_getRndU2() - 32768) * 1000;
@@ -690,7 +685,7 @@ void StartNewIteration() {
gLed.Set(LedPattern::TwoShort); gLed.Set(LedPattern::TwoShort);
} }
// Loop while sending is in progress, timeout just in case after 300 seconds // Loop sending is in progress, timeout just in case after 300 seconds
long start_time = millis(); long start_time = millis();
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("waiting while send is in progress\n"); gCatena.SafePrintf("waiting while send is in progress\n");
@@ -700,6 +695,22 @@ void StartNewIteration() {
gCatena.poll(); gCatena.poll();
yield(); yield();
} }
// handle timeout...
if (send_in_progress) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("looks like we timed out waiting for sending to finish...\n", wait_time);
}
LMIC_clrTxData();
// we sleep 10 seconds...
start_time = millis();
while ((millis() - start_time) < 10000)
{
gCatena.poll();
yield();
}
send_in_progress = false;
}
wait_time = (uint32_t)((millis() - start_time) / 1000); wait_time = (uint32_t)((millis() - start_time) / 1000);
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("end waiting, wait time was %d seconds\n", wait_time); gCatena.SafePrintf("end waiting, wait time was %d seconds\n", wait_time);
@@ -719,9 +730,9 @@ void StartNewIteration() {
sleep_time_sec = 5; sleep_time_sec = 5;
} }
// for the first <INIT_PACKETS> iterations, we set the sleep time to 10 seconds only... // for the first <INIT_PACKETS> iterations, we set the sleep time to 120 seconds only...
if (iteration <= INIT_PACKETS) { if (iteration <= INIT_PACKETS) {
sleep_time_sec = 10; sleep_time_sec = 120;
} }
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
@@ -737,25 +748,38 @@ void StartNewIteration() {
} }
} }
// if we need to periodically reboot, we can do it now...
if (uint32_t(millis()) > gRebootMs) {
// time to reboot
if (config_data.debug_level > 0) {
gCatena.SafePrintf("Reached threshold to reboot...\n");
Serial.flush();
}
NVIC_SystemReset();
}
if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just before Sleeping: %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
}
if (!fUsbPower) { if (!fUsbPower) {
DoDeepSleep(sleep_time_sec); DoDeepSleep(sleep_time_sec);
if (! stop_iterations) { if (! stop_iterations) {
StartNewIteration(); StartNewIteration();
} }
//os_setTimedCallback(
// &iterationJob,
// os_getTime() + sec2osticks(2),
// startNewIterationCb);
} }
else { else {
if (config_data.debug_level > 0) { if (! stop_iterations) {
gCatena.SafePrintf("light sleep; os_setTimedCallback for startNewIterationCb in %d...seconds\n", sleep_time_sec); if (config_data.debug_level > 0) {
gCatena.SafePrintf("light sleep; os_setTimedCallback for startNewIterationCb in %d...seconds\n", sleep_time_sec);
}
os_setTimedCallback(
&iterationJob,
os_getTime() + sec2osticks(sleep_time_sec),
startNewIterationCb);
} }
os_setTimedCallback(
&iterationJob,
os_getTime() + sec2osticks(sleep_time_sec),
startNewIterationCb);
} }
} }
@@ -787,14 +811,33 @@ void startSendingUplink(bool firstTime)
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("SendBuffer firstTime\n"); gCatena.SafePrintf("SendBuffer firstTime\n");
} }
gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) {
package_counter++; package_counter++;
if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
}
}
else {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
}
} else { } else {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer: %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
gCatena.SafePrintf("SendBuffer not firstTime\n"); gCatena.SafePrintf("SendBuffer not firstTime\n");
} }
gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) {
package_counter++; package_counter++;
if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
}
} else {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail );
}
} }
ClearLoraData(); ClearLoraData();
@@ -808,6 +851,7 @@ static void sendBufferDoneCb(
if (config_data.debug_level > 1) { if (config_data.debug_level > 1) {
gLed.Set(LedPattern::Settling); gLed.Set(LedPattern::Settling);
gCatena.SafePrintf("LMIC.opmode in sendBufferDoneCb: %#x\n", LMIC.opmode);
} }
pFn = settleDoneCb; pFn = settleDoneCb;
@@ -822,7 +866,7 @@ static void sendBufferDoneCb(
gLoRaWAN.Shutdown(); gLoRaWAN.Shutdown();
} }
else if (config_data.debug_level > 0) { else if (config_data.debug_level > 0) {
gCatena.SafePrintf("send buffer failed\n"); gCatena.SafePrintf("send buffer failed, LMIC.opmode: %#x\n", LMIC.opmode);
} }
} }
@@ -846,178 +890,56 @@ static void txNotProvisionedCb(
} }
} }
static void settleDoneCb(
osjob_t* pSendJob)
{
const bool fDeepSleep = checkDeepSleep();
if (config_data.debug_level > 0) {
gCatena.SafePrintf("settleDoneCb\n");
}
if (config_data.debug_level > 2) {
// 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);
gCatena.SafePrintf("LMIC.adrAckReq: %i\n", LMIC.adrAckReq);
gCatena.SafePrintf("LMIC.adrEnabled: %i\n", LMIC.adrEnabled);
// Terry ^^
}
if (uint32_t(millis()) > gRebootMs) {
// time to reboot
NVIC_SystemReset();
}
if (! g_fPrintedSleeping)
doSleepAlert(fDeepSleep);
/* count what we're up to */
updateSleepCounters();
if (fDeepSleep)
doDeepSleep(pSendJob);
else
doLightSleep(pSendJob);
}
bool checkDeepSleep(void) bool checkDeepSleep(void)
{ {
bool const fDeepSleepTest = gCatena.GetOperatingFlags() & return !fUsbPower;
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
bool fDeepSleep;
if (fDeepSleepTest)
{
fDeepSleep = true;
}
#ifdef USBCON
else if (Serial.dtr())
{
fDeepSleep = false;
}
#endif
else if (gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDisableDeepSleep))
{
fDeepSleep = false;
}
else if ((gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fUnattended)) != 0)
{
fDeepSleep = true;
}
else
{
fDeepSleep = false;
}
return fDeepSleep;
} }
void doSleepAlert(const bool fDeepSleep) void doSleepAlert(const bool fDeepSleep)
{ {
g_fPrintedSleeping = true; if (config_data.debug_level > 0) {
gCatena.SafePrintf("We wait until is is safe to go to sleep...\n");
}
if (fDeepSleep) for (int i = 0; i <= 15; i++) {
{ long prevPrint = millis();
bool const fDeepSleepTest = gCatena.GetOperatingFlags() & while (os_queryTimeCriticalJobs(ms2osticks(2000)) != 0)
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
const uint32_t deepSleepDelay = fDeepSleepTest ? 10 : 30;
if (config_data.debug_level > 2) {
gCatena.SafePrintf("using deep sleep in %u secs"
#ifdef USBCON
" (USB will disconnect while asleep)"
#endif
": ",
deepSleepDelay
);
}
// sleep and print
if (config_data.debug_level > 1) {
gLed.Set(LedPattern::TwoShort);
}
for (auto n = deepSleepDelay; n > 0; --n)
{
uint32_t tNow = millis();
while (uint32_t(millis() - tNow) < 1000)
{
gCatena.poll();
yield();
}
if (config_data.debug_level > 2) {
gCatena.SafePrintf(".");
}
}
if (config_data.debug_level > 2) {
gCatena.SafePrintf("\nStarting deep sleep.\n");
}
uint32_t tNow = millis();
while (uint32_t(millis() - tNow) < 100)
{ {
gCatena.poll(); gCatena.poll();
yield(); yield();
if (millis() - prevPrint > 1000) {
prevPrint = millis();
if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode: %#x in loop %d\n", LMIC.opmode, i);
}
}
} }
} }
else if (config_data.debug_level > 2) {
gCatena.SafePrintf("using light sleep\n");
}
}
void updateSleepCounters(void)
{
// update the sleep parameters
if (gTxCycleCount > 1)
{
// values greater than one are decremented and ultimately reset to default.
--gTxCycleCount;
}
else if (gTxCycleCount == 1)
{
// it's now one (otherwise we couldn't be here.)
if (config_data.debug_level > 2) {
gCatena.SafePrintf("resetting tx cycle to default: %u\n", CATCFG_T_CYCLE);
}
gTxCycleCount = 0;
gTxCycle = CATCFG_T_CYCLE;
}
else
{
// it's zero. Leave it alone.
}
}
void doDeepSleep(osjob_t *pJob)
{
bool const fDeepSleepTest = gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
uint32_t const sleepInterval = CATCFG_GetInterval(
fDeepSleepTest ? CATCFG_T_CYCLE_TEST : gTxCycle
);
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("doDeepSleep, sleepInterval: %d...\n", sleepInterval); gCatena.SafePrintf("Now it is safe to go to sleep\n");
} }
/* ok... now it's time for a deep sleep */ }
gLed.Set(LedPattern::Off);
deepSleepPrepare();
/* sleep */ static void settleDoneCb(
gCatena.Sleep(sleepInterval); osjob_t* pSendJob)
{
if (config_data.debug_level > 0) {
gCatena.SafePrintf("settleDoneCb - we are at the end of the callback chain!\n");
}
/* recover from sleep */ const bool fDeepSleep = checkDeepSleep();
deepSleepRecovery();
/* and now... we're awake again. trigger another measurement */ if (uint32_t(millis()) > gRebootMs)
sleepDoneCb(pJob); {
// time to reboot
NVIC_SystemReset();
}
doSleepAlert(fDeepSleep);
send_in_progress = false;
} }
void deepSleepPrepare(void) void deepSleepPrepare(void)
@@ -1039,53 +961,6 @@ void deepSleepRecovery(void)
gSPI2.begin(); gSPI2.begin();
} }
void doLightSleep(osjob_t *pJob)
{
uint32_t interval = sec2osticks(CATCFG_GetInterval(gTxCycle));
if (config_data.debug_level > 1) {
gLed.Set(LedPattern::Sleeping);
gCatena.SafePrintf("doLightSleep\n");
}
if (gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fQuickLightSleep))
{
interval = 1;
}
os_setTimedCallback(
&iterationJob,
os_getTime() + interval,
sleepDoneCb
);
}
static void sleepDoneCb(osjob_t* pJob)
{
if (config_data.debug_level > 1) {
gLed.Set(LedPattern::WarmingUp);
}
if (config_data.debug_level > 0) {
gCatena.SafePrintf("sleepDoneCb\n");
}
os_setTimedCallback(
pJob,
os_getTime() + sec2osticks(CATCFG_T_WARMUP),
warmupDoneCb);
}
static void warmupDoneCb(osjob_t* pJob)
{
if (config_data.debug_level > 0) {
gCatena.SafePrintf("warmupDoneCb\n");
}
send_in_progress = false;
}
static void startNewIterationCb(osjob_t* pJob) static void startNewIterationCb(osjob_t* pJob)
{ {
@@ -1100,8 +975,6 @@ static void startNewIterationCb(osjob_t* pJob)
static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage, size_t nMessage) static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage, size_t nMessage)
{ {
unsigned txCycle;
unsigned txCount;
long cal_w1_0; long cal_w1_0;
long cal_w2_0; long cal_w2_0;
@@ -1217,59 +1090,8 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
} }
} }
if (port == 0)
{
return;
}
else if (! (port == 1 && 2 <= nMessage && nMessage <= 3))
{
if (config_data.debug_level > 0) {
gCatena.SafePrintf("invalid message port(%02x)/length(%x)\n",
port, nMessage
);
}
return;
}
txCycle = (pMessage[0] << 8) | pMessage[1];
if (txCycle < CATCFG_T_MIN || txCycle > CATCFG_T_MAX)
{
if (config_data.debug_level > 0) {
gCatena.SafePrintf("tx cycle time out of range: %u\n", txCycle);
}
return;
}
// byte [2], if present, is the repeat count.
// explicitly sending zero causes it to stick.
txCount = CATCFG_INTERVAL_COUNT;
if (nMessage >= 3)
{
txCount = pMessage[2];
}
setTxCycleTime(txCycle, txCount);
} }
void setTxCycleTime(unsigned txCycle, unsigned txCount)
{
if (txCount > 0) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("message cycle time %u seconds for %u messages\n", txCycle, txCount);
}
}
else if (config_data.debug_level > 0) {
gCatena.SafePrintf("message cycle time %u seconds indefinitely\n", txCycle);
}
gTxCycle = txCycle;
gTxCycleCount = txCount;
}
/* process "application hello" -- args are ignored */ /* process "application hello" -- args are ignored */
// argv[0] is "hello" // argv[0] is "hello"
// argv[1..argc-1] are the (ignored) arguments // argv[1..argc-1] are the (ignored) arguments
+1 -1
View File
@@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200527; static const int32_t fwVersion = 20200604;
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
static const byte MAX_VALUES_TO_SEND = 8; static const byte MAX_VALUES_TO_SEND = 8;
+10 -5
View File
@@ -14,7 +14,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
byte debug_level; byte debug_level;
byte interruptPin = A0; //byte interruptPin = A0;
void SetScalesDebugLevel(byte dbg_level) void SetScalesDebugLevel(byte dbg_level)
{ {
@@ -47,7 +47,7 @@ bool SetupScales(byte dbg_level)
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("SetupScales start\n"); gCatena.SafePrintf("SetupScales start\n");
} }
pinMode(interruptPin, INPUT); // pinMode(interruptPin, INPUT);
if (!myScale.begin(Wire, false)) if (!myScale.begin(Wire, false))
{ {
@@ -96,9 +96,11 @@ long ReadScale(char channel)
long readings[num_scale_readings]; // create arry to hold readings long readings[num_scale_readings]; // create arry to hold readings
for (int i = 0; i < num_scale_readings; i++) { for (int i = 0; i < num_scale_readings; i++) {
//while (digitalRead(interruptPin) == LOW) { //while (digitalRead(interruptPin) == LOW) {
long mytimer = millis();
while (! myScale.available()) { while (! myScale.available()) {
// we set a timeout of 10 seconds for the measurement... // we set a timeout of 10 seconds for the measurement...
if ((millis() - startTime) > 10000) { if ((millis() - mytimer) > 10000) {
// Timeout reading scale...
Wire.endTransmission(true); Wire.endTransmission(true);
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Timeout while reading scale...\n"); gCatena.SafePrintf("Timeout while reading scale...\n");
@@ -107,11 +109,14 @@ long ReadScale(char channel)
} }
delay(1); delay(1);
} }
long reading = myScale.getReading(); long reading;
if (myScale.available()) {
reading = myScale.getReading();
readings[i] = reading;
}
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Reading: %d\n", reading); gCatena.SafePrintf("Reading: %d\n", reading);
} }
readings[i] = reading; // fill the array with instantaneous readings from the scale
delay(10); delay(10);
} }