|
|
@ -65,9 +65,9 @@ uint32_t lastUpdate = 0; |
|
|
|
uint32_t lastTransmit = 0; |
|
|
|
|
|
|
|
//Variables for the mqtt packages and topics
|
|
|
|
uint16_t statusPacketIdSub = 0; |
|
|
|
String commandTopic; |
|
|
|
String bme280Topic; |
|
|
|
String batteryTopic; |
|
|
|
|
|
|
|
void setup() { |
|
|
|
// gpio configuration
|
|
|
@ -82,6 +82,11 @@ void setup() { |
|
|
|
//Initialize Basecamp
|
|
|
|
iot.begin(); |
|
|
|
|
|
|
|
//Configure the MQTT topics
|
|
|
|
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play"; |
|
|
|
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280"; |
|
|
|
batteryTopic = "esp32-node/stat/" + iot.hostname + "/battery"; |
|
|
|
|
|
|
|
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); |
|
|
|
switch(wakeup_reason) { |
|
|
|
case ESP_SLEEP_WAKEUP_EXT0: |
|
|
@ -122,6 +127,9 @@ void setup() { |
|
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { |
|
|
|
for (int i=0; i<5 && iot.wifi.status() != WL_CONNECTED; i++) delay(500); |
|
|
|
if (iot.wifi.status() == WL_CONNECTED) transmitStatus(); |
|
|
|
|
|
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
|
Serial.printf("alarm in %f seconds\n", seconds); |
|
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
@ -141,10 +149,6 @@ void setup() { |
|
|
|
bme280.begin(); |
|
|
|
bme280.printValues(); |
|
|
|
|
|
|
|
//Configure the MQTT topics
|
|
|
|
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play"; |
|
|
|
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280"; |
|
|
|
|
|
|
|
//Set up the Callbacks for the MQTT instance. Refer to the Async MQTT Client documentation
|
|
|
|
// TODO: We should do this actually _before_ connecting the mqtt client...
|
|
|
|
iot.mqtt.onConnect(onMqttConnect); |
|
|
@ -198,8 +202,12 @@ void transmitStatus() { |
|
|
|
|
|
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
|
root.printTo(sensorBuf, sizeof(sensorBuf)); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 0, false, sensorBuf); |
|
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 0, false, sensorBuf); |
|
|
|
// statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 1, true, sensorBuf);
|
|
|
|
int voltage = rom_phy_get_vdd33(); |
|
|
|
char batteryBuf[9]; |
|
|
|
sprintf(batteryBuf, "%d", voltage); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(batteryTopic.c_str(), 0, false, batteryBuf); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -239,12 +247,13 @@ void suspend(uint32_t secondsToSleep) { |
|
|
|
|
|
|
|
if (!displaySleep) { |
|
|
|
u8g2.begin(); |
|
|
|
u8g2.setPowerSave(0); |
|
|
|
u8g2.clearBuffer(); |
|
|
|
u8g2.sendBuffer(); |
|
|
|
u8g2.setFont(u8g2_font_inb19_mf); |
|
|
|
u8g2.drawStr(0, 20, timeStr); |
|
|
|
// ToDo: set rtc gpio resistors
|
|
|
|
rtc_gpio_hold_en((gpio_num_t)16); |
|
|
|
//rtc_gpio_hold_en((gpio_num_t)16);
|
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * 60); |
|
|
|
} |
|
|
|
|
|
|
|