From ac60546eabe2dd0dc6d6471e29a676ccf98ff266 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Tue, 6 Apr 2021 20:05:57 +0200 Subject: [PATCH] Enable Remote Calibration --- lib/SENSAIRS8/SENSAIRS8.cpp | 2 +- src/main.cpp | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/SENSAIRS8/SENSAIRS8.cpp b/lib/SENSAIRS8/SENSAIRS8.cpp index db8cb26..e9568f6 100644 --- a/lib/SENSAIRS8/SENSAIRS8.cpp +++ b/lib/SENSAIRS8/SENSAIRS8.cpp @@ -52,7 +52,7 @@ uint8_t SENSAIRS8::getSensorData(char *payload, uint8_t startbyte) { void SENSAIRS8::calibrate(void) { pinMode(calpin, OUTPUT); digitalWrite(calpin, LOW); - delay(5000); + delay(6000); digitalWrite(calpin, HIGH); pinMode(calpin, INPUT_PULLUP); } diff --git a/src/main.cpp b/src/main.cpp index 3632584..fd95d2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,15 +157,32 @@ void onEvent(ev_t ev) { // Check for Downlink DEBUG_PRINTLN("LoRa Packet Sent"); WS2812B_BLINK(1,0,127,0,1000); - if ((int)LMIC.dataLen == 2) { - // We got a Packet with the right size - lets assemble it into a uint16_t - DEBUG_PRINTLN("Received Downlink") - uint16_t tmpslp = (LMIC.frame[LMIC.dataBeg] << 8) | LMIC.frame[LMIC.dataBeg+1]; - DEBUG_PRINT("Setting Sleep Time to: "); - DEBUG_PRINTLN(tmpslp); - sleep_time = tmpslp; - EEPROM.put(ADDR_SLP, tmpslp); - WS2812B_BLINK(1,0,0,127,250); + if ((int)LMIC.dataLen > 0) { + // Check for Downlinks + // Function based in Ports: + // Port 1 + // Set Sending Interval + // Port 2 + // Do Calibration + switch((uint8_t)LMIC.frame[LMIC.dataBeg-1]) { + case 1: + if ((int)LMIC.dataLen == 2) { + // We got a Packet with the right size - lets assemble it into a uint16_t + DEBUG_PRINTLN("Received Downlink") + uint16_t tmpslp = (LMIC.frame[LMIC.dataBeg] << 8) | LMIC.frame[LMIC.dataBeg+1]; + DEBUG_PRINT("Setting Sleep Time to: "); + DEBUG_PRINTLN(tmpslp); + sleep_time = tmpslp; + EEPROM.put(ADDR_SLP, tmpslp); + WS2812B_BLINK(1,0,0,127,250); + } + break; + case 2: + for (uint8_t i=0; icalibrate(); + BLINK_LED(3); + break; + } } // Got to sleep for specified Time