|
@ -79,8 +79,10 @@ String sensorTopic; |
|
|
|
|
|
|
|
|
void setup() { |
|
|
void setup() { |
|
|
// gpio configuration
|
|
|
// gpio configuration
|
|
|
|
|
|
// rtc_gpio_deinit((gpio_num_t)buttonPin);
|
|
|
pinMode(buttonPin, INPUT_PULLUP); |
|
|
pinMode(buttonPin, INPUT_PULLUP); |
|
|
pinMode(sensorPin, INPUT_PULLDOWN); |
|
|
// rtc_gpio_deinit((gpio_num_t)sensorPin);
|
|
|
|
|
|
pinMode(sensorPin, INPUT); |
|
|
pinMode(18, OUTPUT); |
|
|
pinMode(18, OUTPUT); |
|
|
digitalWrite(18, HIGH); // disable LoRa_CS
|
|
|
digitalWrite(18, HIGH); // disable LoRa_CS
|
|
|
|
|
|
|
|
@ -307,13 +309,10 @@ void suspend(uint32_t secondsToSleep) { |
|
|
|
|
|
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep); |
|
|
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep); |
|
|
const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton; |
|
|
const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton; |
|
|
esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask, ESP_EXT1_WAKEUP_ANY_HIGH); |
|
|
const uint64_t ext_wakeup_sensor_mask = 1ULL << sensorPin; |
|
|
|
|
|
esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask | ext_wakeup_sensor_mask, ESP_EXT1_WAKEUP_ANY_HIGH); |
|
|
|
|
|
|
|
|
////esp_sleep_enable_ext0_wakeup((gpio_num_t)sensorPin, 0);
|
|
|
////esp_sleep_enable_ext0_wakeup((gpio_num_t)sensorPin, 0);
|
|
|
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1; |
|
|
|
|
|
esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ANY_HIGH); |
|
|
|
|
|
// const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;
|
|
|
|
|
|
//// esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
|
|
|
|
|
|
//
|
|
|
//
|
|
|
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
|
|
|
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
|
|
|
|
|
|
|
|
@ -434,17 +433,21 @@ void loop() |
|
|
Serial.print("Free Heap: "); |
|
|
Serial.print("Free Heap: "); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
|
|
|
|
|
|
if (digitalRead(sensorPin) == HIGH) { |
|
|
if (sensorON && digitalRead(sensorPin) == LOW) { |
|
|
lastActive = millis(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sensorON && digitalRead(sensorPin)) { |
|
|
|
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, "OFF"); |
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, "OFF"); |
|
|
sensorON = false; |
|
|
sensorON = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (digitalRead(sensorPin) == HIGH) { |
|
|
|
|
|
lastActive = millis(); |
|
|
|
|
|
if (sensorON == false && digitalRead(sensorPin) == HIGH) { |
|
|
|
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, timeStr); |
|
|
|
|
|
sensorON = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(millis() - lastTransmit >= 60*1000) { |
|
|
if(millis() - lastTransmit >= 60*1000) { |
|
|
lastTransmit = millis(); |
|
|
lastTransmit = millis(); |
|
|
transmitStatus(); |
|
|
transmitStatus(); |
|
|