|
|
@ -27,14 +27,16 @@ |
|
|
|
|
|
|
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); |
|
|
|
|
|
|
|
|
|
|
|
char timeStr[20]; |
|
|
|
char weatherStr[32]; |
|
|
|
RTC_DATA_ATTR static int boot_count = 0; |
|
|
|
|
|
|
|
//Create a new Basecamp instance called iot
|
|
|
|
Basecamp iot; |
|
|
|
|
|
|
|
WiFiUDP ntpUDP; |
|
|
|
NTPClient timeClient(ntpUDP, "de.pool.ntp.org", 3600, 60000); |
|
|
|
char timeStr[20]; |
|
|
|
char weatherStr[32]; |
|
|
|
|
|
|
|
BME280 bme280; |
|
|
|
MP3 mp3; |
|
|
|
Rotary rotary; |
|
|
@ -56,6 +58,37 @@ void setup() { |
|
|
|
pinMode(18, OUTPUT); |
|
|
|
digitalWrite(18, HIGH); // disable LoRa_CS
|
|
|
|
|
|
|
|
boot_count++; |
|
|
|
|
|
|
|
/* time_t now;
|
|
|
|
struct tm timeinfo; |
|
|
|
time(&now); |
|
|
|
setenv("TZ", "GMT+1", 1); |
|
|
|
tzset(); |
|
|
|
localtime_r(&now, &timeinfo);*/ |
|
|
|
|
|
|
|
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); |
|
|
|
switch(wakeup_reason) { |
|
|
|
case ESP_SLEEP_WAKEUP_EXT0: |
|
|
|
Serial.println("wakeup by RTC_IO"); |
|
|
|
break; |
|
|
|
case ESP_SLEEP_WAKEUP_EXT1: |
|
|
|
Serial.println("wakeup by RTC_CNTL"); |
|
|
|
break; |
|
|
|
case ESP_SLEEP_WAKEUP_TIMER: |
|
|
|
Serial.println("wakeup by timer"); |
|
|
|
break; |
|
|
|
case ESP_SLEEP_WAKEUP_TOUCHPAD: |
|
|
|
Serial.println("wakeup by touchpad"); |
|
|
|
break; |
|
|
|
case ESP_SLEEP_WAKEUP_ULP: |
|
|
|
Serial.println("wakeup by ULP"); |
|
|
|
break; |
|
|
|
default: // ESP_SLEEP_WAKEUP_UNDEFINED
|
|
|
|
Serial.println("wakeup not by deep sleep"); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
//Initialize Basecamp
|
|
|
|
iot.begin(); |
|
|
|
|
|
|
@ -139,7 +172,14 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties |
|
|
|
|
|
|
|
void suspend() { |
|
|
|
DEBUG_PRINTLN("Entering deep sleep"); |
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep); |
|
|
|
esp_sleep_enable_ext0_wakeup((gpio_num_t)sensorPin, 0); |
|
|
|
|
|
|
|
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1; |
|
|
|
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
|
|
|
|
//properly disconnect from the MQTT broker
|
|
|
|
iot.mqtt.disconnect(); |
|
|
|
//send the ESP into deep sleep
|
|
|
|