Browse Source

tweaks

main
Hendrik Langer 7 years ago
parent
commit
ec07056e1b
  1. BIN
      316920__rudmer-rotteveel__chicken-single-alarm-call.wav
  2. BIN
      alarm.wav
  3. BIN
      space_debris.mod
  4. 40
      src/BME280.cpp
  5. 2
      src/BME280.h
  6. 8
      src/hardware.h
  7. 43
      src/main.cpp
  8. 2
      src/mp3.cpp

BIN
316920__rudmer-rotteveel__chicken-single-alarm-call.wav

Binary file not shown.

BIN
alarm.wav

Binary file not shown.

BIN
space_debris.mod

Binary file not shown.

40
src/BME280.cpp

@ -13,17 +13,12 @@ bool BME280::begin(void) {
// SPI.begin(BME_SCK, BME_MISO, BME_MOSI, BME_CS);
pinMode(18, OUTPUT);
digitalWrite(18, HIGH); // disable LoRa_CS
pinMode(23, OUTPUT);
digitalWrite(23, HIGH); // enable bme280 CS
delay(50);
pinMode(BME_CS, OUTPUT);
digitalWrite(BME_CS, LOW); // enable bme280 CS
delay(100);
bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
int retries = 0;
while (!(valid = bme->begin())) {
if (retries > 5) break;
retries++;
Serial.println("Could not find a valid BME280 sensor, check wiring!");
delay(500);
}
valid = bme->begin();
if (!valid) bme->init();
if (!valid) return false;
bme->setSampling(Adafruit_BME280::sensor_mode::MODE_NORMAL,
@ -45,8 +40,29 @@ void BME280::sleep() {
Adafruit_BME280::standby_duration::STANDBY_MS_1000);
}
void BME280::init() {
bme->init();
bool BME280::reinit() {
pinMode(18, OUTPUT);
digitalWrite(18, HIGH); // disable LoRa_CS
pinMode(BME_CS, OUTPUT);
digitalWrite(BME_CS, LOW); // enable bme280 CS
int retries = 0; valid = false;
while (!valid) {
if (retries > 9) break;
valid = bme->init();
retries++;
delay(100);
float p = bme->readPressure() / 100.0F;
if (p < 300 || p > 1100) valid = false;
// constexpr byte BME280_REGISTER_SOFTRESET = 0xE0;
// bme->write8(BME280_REGISTER_SOFTRESET, 0xB6);
}
if (!valid) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
return false;
}
}
void BME280::printValues() {

2
src/BME280.h

@ -18,7 +18,7 @@ class BME280 {
public:
BME280();
bool begin(void);
void init(void);
bool reinit(void);
void printValues(void);
float readTemperature(void);
float readPressure(void);

8
src/hardware.h

@ -19,6 +19,14 @@ static constexpr uint8_t ext_wakeup_pin_2 = 0;
static constexpr uint32_t secondsToSleep = 15*60;
static constexpr int batteryLimit = 2800;
#define SX1276_SCK 5
#define SX1276_MISO 19
#define SX1276_MOSI 27
#define SX1276_CS 18
#define SX1276_RST 14
#define SX1276_IRQ 26
#define SX1276_BAND 868
/* Wiring (Heltec OLED Lora)
* GND O O GND

43
src/main.cpp

@ -26,6 +26,8 @@
#include <sys/time.h>
#include "apps/sntp/sntp.h"
//#include <LoRa.h>
#include "driver/rtc_io.h"
#include "main.h"
@ -38,6 +40,8 @@
extern "C" {
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);
@ -126,12 +130,23 @@ void setup() {
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
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.printValues();
// bme280.printValues();
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) {
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));
Serial.printf("alarm in %f seconds\n", seconds);
@ -149,6 +164,7 @@ void setup() {
menuChange = eMainScreen;
u8g2.setContrast(127);
//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);
@ -172,6 +188,9 @@ void setup() {
time(&now);
}
if (timeinfo.tm_hour < 7 || timeinfo.tm_hour > 23) u8g2.setContrast(1);
else u8g2.setContrast(127);
mp3.begin();
led.setup();
@ -199,8 +218,11 @@ void transmitStatus() {
float humi = bme280.readHumidity();
float pres = bme280.readPressure();
float internal_temp = temperatureRead();
int internal_hall = hallRead();
for (int retry=0; retry<3 && !bme280.valid; retry++) {
bme280.init();
bme280.reinit();
delay(250);
humi = bme280.readHumidity();
bme280.readPressure();
@ -209,14 +231,18 @@ void transmitStatus() {
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["temperature"] = bme280.readTemperature();
root["humidity"] = bme280.readHumidity();
root["pressure"] = bme280.readPressure();
if (bme280.valid) {
root["temperature"] = bme280.readTemperature();
root["humidity"] = bme280.readHumidity();
root["pressure"] = bme280.readPressure();
} else {
root["temperature"] = internal_temp;
}
char sensorBuf[root.measureLength()+1];
root.printTo(sensorBuf, sizeof(sensorBuf));
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);
int voltage = rom_phy_get_vdd33();
char batteryBuf[9];
@ -267,8 +293,7 @@ void suspend(uint32_t secondsToSleep) {
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); // 16 not connected to ulp processor :(
esp_sleep_enable_timer_wakeup(1000000LL * 60);
}

2
src/mp3.cpp

@ -19,6 +19,8 @@
char titleStr[64];
// convert mp3 files with `xxd -i alarm.wav > alarmsound.h`
MP3::MP3() {
strncpy_P(URL, "http://streaming.shoutcast.com/80sPlanet?lang=en-US", sizeof(URL));
//const char *URL="http://swr-swr1-bw.cast.addradio.de/swr/swr1/bw/mp3/64/stream.mp3";

Loading…
Cancel
Save