Browse Source

pir status

main
Hendrik Langer 6 years ago
parent
commit
ae496d4497
  1. 4
      src/hardware.h
  2. 25
      src/main.cpp

4
src/hardware.h

@ -5,7 +5,7 @@
// LED_BUILTIN = 2
// KEY_BUILTIN = 0
static constexpr uint8_t buttonPin = 0;
static constexpr uint8_t sensorPin = 36;
static constexpr uint8_t sensorPin = 37;
static constexpr uint8_t rotaryPinA = 35;
static constexpr uint8_t rotaryPinB = 34;
static constexpr uint8_t rotaryPinButton = 2;
@ -32,7 +32,7 @@ static constexpr int batteryLimit = 2800;
* GND O O GND
* 5V O O 5V
* 3V3 O O 3V3
* GND O < 36 only input, no pullups
* GND O ? < 36 only input, no pullups
* RX * (3) < 37 only input, no pullups
* TX * (1) < 38 only input, no pullups
* RST * BUTTON hall < 39 only input, no pullups

25
src/main.cpp

@ -79,8 +79,10 @@ String sensorTopic;
void setup() {
// gpio configuration
// rtc_gpio_deinit((gpio_num_t)buttonPin);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(sensorPin, INPUT_PULLDOWN);
// rtc_gpio_deinit((gpio_num_t)sensorPin);
pinMode(sensorPin, INPUT);
pinMode(18, OUTPUT);
digitalWrite(18, HIGH); // disable LoRa_CS
@ -307,13 +309,10 @@ void suspend(uint32_t secondsToSleep) {
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep);
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);
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
@ -434,17 +433,21 @@ void loop()
Serial.print("Free Heap: ");
Serial.println(ESP.getFreeHeap());
if (digitalRead(sensorPin) == HIGH) {
lastActive = millis();
}
if (sensorON && digitalRead(sensorPin)) {
if (sensorON && digitalRead(sensorPin) == LOW) {
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, "OFF");
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) {
lastTransmit = millis();
transmitStatus();

Loading…
Cancel
Save