|
@ -65,9 +65,9 @@ uint32_t lastUpdate = 0; |
|
|
uint32_t lastTransmit = 0; |
|
|
uint32_t lastTransmit = 0; |
|
|
|
|
|
|
|
|
//Variables for the mqtt packages and topics
|
|
|
//Variables for the mqtt packages and topics
|
|
|
uint16_t statusPacketIdSub = 0; |
|
|
|
|
|
String commandTopic; |
|
|
String commandTopic; |
|
|
String bme280Topic; |
|
|
String bme280Topic; |
|
|
|
|
|
String batteryTopic; |
|
|
|
|
|
|
|
|
void setup() { |
|
|
void setup() { |
|
|
// gpio configuration
|
|
|
// gpio configuration
|
|
@ -82,6 +82,11 @@ void setup() { |
|
|
//Initialize Basecamp
|
|
|
//Initialize Basecamp
|
|
|
iot.begin(); |
|
|
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(); |
|
|
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); |
|
|
switch(wakeup_reason) { |
|
|
switch(wakeup_reason) { |
|
|
case ESP_SLEEP_WAKEUP_EXT0: |
|
|
case ESP_SLEEP_WAKEUP_EXT0: |
|
@ -122,6 +127,9 @@ void setup() { |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { |
|
|
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)); |
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
Serial.printf("alarm in %f seconds\n", seconds); |
|
|
Serial.printf("alarm in %f seconds\n", seconds); |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
@ -141,10 +149,6 @@ void setup() { |
|
|
bme280.begin(); |
|
|
bme280.begin(); |
|
|
bme280.printValues(); |
|
|
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
|
|
|
//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...
|
|
|
// TODO: We should do this actually _before_ connecting the mqtt client...
|
|
|
iot.mqtt.onConnect(onMqttConnect); |
|
|
iot.mqtt.onConnect(onMqttConnect); |
|
@ -198,8 +202,12 @@ void transmitStatus() { |
|
|
|
|
|
|
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
root.printTo(sensorBuf, sizeof(sensorBuf)); |
|
|
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);
|
|
|
// 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) { |
|
|
if (!displaySleep) { |
|
|
u8g2.begin(); |
|
|
u8g2.begin(); |
|
|
|
|
|
u8g2.setPowerSave(0); |
|
|
u8g2.clearBuffer(); |
|
|
u8g2.clearBuffer(); |
|
|
u8g2.sendBuffer(); |
|
|
u8g2.sendBuffer(); |
|
|
u8g2.setFont(u8g2_font_inb19_mf); |
|
|
u8g2.setFont(u8g2_font_inb19_mf); |
|
|
u8g2.drawStr(0, 20, timeStr); |
|
|
u8g2.drawStr(0, 20, timeStr); |
|
|
// ToDo: set rtc gpio resistors
|
|
|
// 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); |
|
|
esp_sleep_enable_timer_wakeup(1000000LL * 60); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|