Xinyuan-LilyGO / LilyGO-T-HiGrow-LoRaWLAN

11 stars 4 forks source link

How to set upload interval? #5

Open knutek66 opened 3 years ago

knutek66 commented 3 years ago

The Lorawan works, but interval for upload is 30 sec. How to set to 20 min? And is the module in sleep mode to save battery? I tried set TX_INTERVAL to 900 (15 min) but got no update at all.

knutek66 commented 3 years ago

I installed a 18650 battery 2400mAh. Still only last one night. If Lorewan dont get any battery optimiced, its not an alternative to wifi.

knutek66 commented 3 years ago

Still no one that can help. Is there any other prodjects using the TTGO HIgrow with Lorawan? I need a Higrow with TTN integration and Cayenne integration. It is working with this github code: image but the battery drains out to fast and i dont get utdates to be every 30 min.

ro85ac commented 2 years ago

@knutek66

You need to add these pieces of code:

in setup method : esp_sleep_enable_timer_wakeup(900* 1000000 ); in the final method after all readings are done and the message is sent to lora, you need to call the following method:

Serial.println("Going to sleep now");
Serial.flush(); 
esp_deep_sleep_start();

If you cannot handle, put your code here (only the main class) and I will reply you!

knutek66 commented 2 years ago

Thank you for response. Can you show me where to add the code?

knutek66 commented 2 years ago

figured out how to set the code. Now its working with 15 min intervall! Thank you. And with webhook it works in The things network v3

reivis commented 2 years ago

figured out how to set the code. Now its working with 15 min intervall! Thank you. And with webhook it works in The things network v3

Hi Knutek66, can you tell me where to put the code please.

knutek66 commented 2 years ago

put in new code in void onEvent and void setup New code marked: void onEvent (ev_t ev) { Serial.print(os_getTime()); Serial.print(": "); switch (ev) { case EV_TXCOMPLETE: Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));

    if (LMIC.txrxFlags & TXRX_ACK) {
        Serial.println(F("Received ack"));
        lora_msg =  "Received ACK.";
    }

    lora_msg = "rssi:" + String(LMIC.rssi) + " snr: " + String(LMIC.snr);

    if (LMIC.dataLen) {
        // char TTN_response[256];
        // int i = 0;
        // data received in rx slot after tx
        Serial.print(F("Data Received: "));
        // Serial.write(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
        // Serial.println();
        // Serial.println(LMIC.rssi);
    }
    // Schedule next transmission
    os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);

    // new code put in to set sleep mode (2022)
    Serial.println("Going to sleep now");
    Serial.flush(); 
    esp_deep_sleep_start();
    // end of new code

    break;
case EV_JOINING:
    Serial.println(F("EV_JOINING: -> Joining..."));
    lora_msg = "OTAA joining....";
    joinStatus = EV_JOINING;
    break;
case EV_JOIN_FAILED:
    Serial.println(F("EV_JOIN_FAILED: -> Joining failed"));
    lora_msg = "OTAA Joining failed";
    break;
case EV_JOINED:
    Serial.println(F("EV_JOINED"));
    lora_msg = "Joined!";
    joinStatus = EV_JOINED;
    delay(3);
    // Disable link check validation (automatically enabled
    // during join, but not supported by TTN at this time).
    LMIC_setLinkCheckMode(0);

    break;
case EV_RXCOMPLETE:
    // data received in ping slot
    Serial.println(F("EV_RXCOMPLETE"));
    break;
case EV_LINK_DEAD:
    Serial.println(F("EV_LINK_DEAD"));
    break;
case EV_LINK_ALIVE:
    Serial.println(F("EV_LINK_ALIVE"));
    break;
default:
    Serial.println(F("Unknown event"));
    break;
}

}

void setup() { Serial.begin(115200);

Wire.begin(I2C_SDA, I2C_SCL);
//new code 2022. 1190 is sleep time in seconds making 20 min sleep
esp_sleep_enable_timer_wakeup(1190* 1000000 );
// end new code
//! Sensor power control pin , use deteced must set high
pinMode(POWER_CTRL, OUTPUT);
digitalWrite(POWER_CTRL, HIGH);
delay(200);

dht12.begin();

if (!bme.begin()) {
    Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
    bmeSensorDetected = false;
}

if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
    Serial.println(F("Error initialising BH1750"));
    lightSensorDetected = false;
}

loarSetup();

button.attachLongPressStart([] {
    // no use
});
button.attachLongPressStop([] {
    // no use
});

}

edegraaff commented 1 year ago

Does someone have good readings for the nutrient values? imho they are wrong with no soil dry electrode i get a reading of 20% and when there is nothing i expect nothing :)

edegraaff commented 1 year ago

Still no one that can help. Is there any other prodjects using the TTGO HIgrow with Lorawan? I need a Higrow with TTN integration and Cayenne integration. It is working with this github code: image but the battery drains out to fast and i dont get utdates to be every 30 min.

hajhaj,

The value for the salt/nutrient value in your example is also low = 0 seems strange right?

edegraaff commented 1 year ago

Could we link? i want to get it working within the things network, curious how you managed to get this working eelco nl13974