|
@ -26,6 +26,8 @@ |
|
|
#include <sys/time.h> |
|
|
#include <sys/time.h> |
|
|
#include "apps/sntp/sntp.h" |
|
|
#include "apps/sntp/sntp.h" |
|
|
|
|
|
|
|
|
|
|
|
//#include <LoRa.h>
|
|
|
|
|
|
|
|
|
#include "driver/rtc_io.h" |
|
|
#include "driver/rtc_io.h" |
|
|
|
|
|
|
|
|
#include "main.h" |
|
|
#include "main.h" |
|
@ -38,6 +40,8 @@ |
|
|
|
|
|
|
|
|
extern "C" { |
|
|
extern "C" { |
|
|
int rom_phy_get_vdd33(); |
|
|
int rom_phy_get_vdd33(); |
|
|
|
|
|
//uint8_t temprature_sens_read();
|
|
|
|
|
|
//uint32_t hall_sens_read();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); |
|
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); |
|
@ -126,12 +130,23 @@ void setup() { |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
|
|
|
|
|
/* SPI.begin(SX1276_SCK, SX1276_MISO, SX1276_MOSI, SX1276_CS);
|
|
|
|
|
|
LoRa.setPins(SX1276_CS, SX1276_RST, SX1276_IRQ);// set CS, reset, IRQ pin
|
|
|
|
|
|
|
|
|
|
|
|
if (!LoRa.begin(SX1276_BAND)) { // initialize ratio at 915 MHz
|
|
|
|
|
|
Serial.println("LoRa init failed. Check your connections."); |
|
|
|
|
|
while (true); // if failed, do nothing
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
bme280.begin(); |
|
|
bme280.begin(); |
|
|
bme280.printValues(); |
|
|
// bme280.printValues();
|
|
|
|
|
|
|
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { |
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { |
|
|
for (int i=0; i<15 && iot.wifi.status() != WL_CONNECTED; i++) delay(500); |
|
|
for (int i=0; i<15 && iot.wifi.status() != WL_CONNECTED; i++) delay(500); |
|
|
if (iot.wifi.status() == WL_CONNECTED) transmitStatus(); |
|
|
if (iot.wifi.status() == WL_CONNECTED) { |
|
|
|
|
|
transmitStatus(); |
|
|
|
|
|
obtain_time(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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); |
|
@ -149,6 +164,7 @@ void setup() { |
|
|
menuChange = eMainScreen; |
|
|
menuChange = eMainScreen; |
|
|
u8g2.setContrast(127); |
|
|
u8g2.setContrast(127); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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); |
|
@ -172,6 +188,9 @@ void setup() { |
|
|
time(&now); |
|
|
time(&now); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (timeinfo.tm_hour < 7 || timeinfo.tm_hour > 23) u8g2.setContrast(1); |
|
|
|
|
|
else u8g2.setContrast(127); |
|
|
|
|
|
|
|
|
mp3.begin(); |
|
|
mp3.begin(); |
|
|
led.setup(); |
|
|
led.setup(); |
|
|
|
|
|
|
|
@ -199,8 +218,11 @@ void transmitStatus() { |
|
|
float humi = bme280.readHumidity(); |
|
|
float humi = bme280.readHumidity(); |
|
|
float pres = bme280.readPressure(); |
|
|
float pres = bme280.readPressure(); |
|
|
|
|
|
|
|
|
|
|
|
float internal_temp = temperatureRead(); |
|
|
|
|
|
int internal_hall = hallRead(); |
|
|
|
|
|
|
|
|
for (int retry=0; retry<3 && !bme280.valid; retry++) { |
|
|
for (int retry=0; retry<3 && !bme280.valid; retry++) { |
|
|
bme280.init(); |
|
|
bme280.reinit(); |
|
|
delay(250); |
|
|
delay(250); |
|
|
humi = bme280.readHumidity(); |
|
|
humi = bme280.readHumidity(); |
|
|
bme280.readPressure(); |
|
|
bme280.readPressure(); |
|
@ -209,14 +231,18 @@ void transmitStatus() { |
|
|
|
|
|
|
|
|
StaticJsonBuffer<200> jsonBuffer; |
|
|
StaticJsonBuffer<200> jsonBuffer; |
|
|
JsonObject& root = jsonBuffer.createObject(); |
|
|
JsonObject& root = jsonBuffer.createObject(); |
|
|
|
|
|
if (bme280.valid) { |
|
|
root["temperature"] = bme280.readTemperature(); |
|
|
root["temperature"] = bme280.readTemperature(); |
|
|
root["humidity"] = bme280.readHumidity(); |
|
|
root["humidity"] = bme280.readHumidity(); |
|
|
root["pressure"] = bme280.readPressure(); |
|
|
root["pressure"] = bme280.readPressure(); |
|
|
|
|
|
} else { |
|
|
|
|
|
root["temperature"] = internal_temp; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
root.printTo(sensorBuf, sizeof(sensorBuf)); |
|
|
root.printTo(sensorBuf, sizeof(sensorBuf)); |
|
|
uint16_t statusPacketIdSub; |
|
|
uint16_t statusPacketIdSub; |
|
|
if (bme280.valid) statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 0, false, sensorBuf); |
|
|
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(); |
|
|
int voltage = rom_phy_get_vdd33(); |
|
|
char batteryBuf[9]; |
|
|
char batteryBuf[9]; |
|
@ -267,8 +293,7 @@ void suspend(uint32_t secondsToSleep) { |
|
|
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
|
|
|
rtc_gpio_hold_en((gpio_num_t)16); // 16 not connected to ulp processor :(
|
|
|
//rtc_gpio_hold_en((gpio_num_t)16);
|
|
|
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * 60); |
|
|
esp_sleep_enable_timer_wakeup(1000000LL * 60); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|