Hendrik Langer
5 years ago
16 changed files with 350 additions and 159 deletions
@ -1,46 +0,0 @@ |
|||||
#ifndef _XD0MQTT_H |
|
||||
#define _XD0MQTT_H |
|
||||
|
|
||||
#include <Arduino.h> |
|
||||
|
|
||||
class XD0MQTT { |
|
||||
public: |
|
||||
XD0MQTT(void); |
|
||||
bool begin(void); |
|
||||
private: |
|
||||
// openssl s_client -showcerts -connect home.xd0.de:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >mqtt_xd0.de.pem
|
|
||||
const char* rootCACertificate = \ |
|
||||
"-----BEGIN CERTIFICATE-----\n" \ |
|
||||
"MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\n" \ |
|
||||
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n" \ |
|
||||
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\n" \ |
|
||||
"WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu\n" \ |
|
||||
"ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY\n" \ |
|
||||
"MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc\n" \ |
|
||||
"h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+\n" \ |
|
||||
"0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U\n" \ |
|
||||
"A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW\n" \ |
|
||||
"T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7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FaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\n" \ |
|
||||
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\n" \ |
|
||||
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq\n" \ |
|
||||
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA\n" \ |
|
||||
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\n" \ |
|
||||
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n" \ |
|
||||
"-----END CERTIFICATE-----\n"; |
|
||||
}; |
|
||||
|
|
||||
#endif /* _XD0MQTT_H */ |
|
@ -0,0 +1,16 @@ |
|||||
|
#include "Display.h" |
||||
|
|
||||
|
#include "esp_log.h" |
||||
|
|
||||
|
static const char *TAG = "Display"; |
||||
|
|
||||
|
|
||||
|
Display::Display() {} |
||||
|
|
||||
|
bool Display::begin(void) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void Display::helloWorld(void) { |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
#ifndef _DISPLAY_H |
||||
|
#define _DISPLAY_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
class Display { |
||||
|
public: |
||||
|
Display(void); |
||||
|
virtual bool begin(void); |
||||
|
virtual void helloWorld(void); |
||||
|
private: |
||||
|
}; |
||||
|
|
||||
|
#endif /* _DISPLAY_H */ |
@ -0,0 +1,57 @@ |
|||||
|
#include "Display.h" |
||||
|
#include "Display_D32_EPD.h" |
||||
|
|
||||
|
#include <GxEPD2_BW.h> |
||||
|
#include <Fonts/FreeMonoBold9pt7b.h> |
||||
|
#include "bitmaps/Bitmaps128x250.h" |
||||
|
#include <Adafruit_GFX.h> |
||||
|
|
||||
|
#include "../hardware.h" |
||||
|
|
||||
|
#include "esp_log.h" |
||||
|
static const char *TAG = "Display"; |
||||
|
|
||||
|
namespace { |
||||
|
|
||||
|
GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=SS*/ TFT_CS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
Display_D32_EPD::Display_D32_EPD(void) {} |
||||
|
|
||||
|
bool Display_D32_EPD::begin(void) { |
||||
|
// initialize e-paper display
|
||||
|
SPI.begin(18, 19, 23, TFT_CS); |
||||
|
display.init(); |
||||
|
Serial.println("display init done"); Serial.flush(); |
||||
|
|
||||
|
display.clearScreen(); |
||||
|
display.refresh(); |
||||
|
|
||||
|
helloWorld(); |
||||
|
display.powerOff(); |
||||
|
} |
||||
|
|
||||
|
void Display_D32_EPD::helloWorld() |
||||
|
{ |
||||
|
const char HelloWorld[] = "Hello World!"; |
||||
|
//Serial.println("helloWorld");
|
||||
|
display.setRotation(1); |
||||
|
display.setFont(&FreeMonoBold9pt7b); |
||||
|
display.setTextColor(GxEPD_BLACK); |
||||
|
int16_t tbx, tby; uint16_t tbw, tbh; |
||||
|
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh); |
||||
|
// center bounding box by transposition of origin:
|
||||
|
uint16_t x = ((display.width() - tbw) / 2) - tbx; |
||||
|
uint16_t y = ((display.height() - tbh) / 2) - tby; |
||||
|
display.setFullWindow(); |
||||
|
display.firstPage(); |
||||
|
do |
||||
|
{ |
||||
|
display.fillScreen(GxEPD_WHITE); |
||||
|
display.setCursor(x, y); |
||||
|
display.print(HelloWorld); |
||||
|
} |
||||
|
while (display.nextPage()); |
||||
|
//Serial.println("helloWorld done");
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#ifndef _DISPLAY_D32_EPD_H |
||||
|
#define _DISPLAY_D32_EPD_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#include "Display.h" |
||||
|
|
||||
|
class Display_D32_EPD : public Display { |
||||
|
public: |
||||
|
Display_D32_EPD(); |
||||
|
bool begin(void); |
||||
|
void helloWorld(void); |
||||
|
private: |
||||
|
}; |
||||
|
|
||||
|
#endif /* _DISPLAY_D32_EPD_H */ |
@ -0,0 +1,20 @@ |
|||||
|
#ifndef _HARDWARE_H |
||||
|
#define _HARDWARE_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
static constexpr uint8_t BME_SDA = 21; |
||||
|
static constexpr uint8_t BME_SCL = 22; |
||||
|
|
||||
|
/* defined in arduino-esp32/variants/d32_pro/pins_arduino.h */ |
||||
|
//static const uint8_t LED_BUILTIN = 5;
|
||||
|
//static const uint8_t _VBAT = 35; // battery voltage
|
||||
|
//#define TF_CS 4 // TF (Micro SD Card) CS pin
|
||||
|
//#define TS_CS 12 // Touch Screen CS pin
|
||||
|
//#define TFT_CS 14 // TFT CS pin
|
||||
|
//#define TFT_LED 32 // TFT backlight control pin
|
||||
|
//#define TFT_RST 33 // TFT reset pin
|
||||
|
//#define TFT_DC 27 // TFT DC pin
|
||||
|
//#define SS TF_CS
|
||||
|
|
||||
|
#endif /* _HARDWARE_H */ |
@ -0,0 +1,39 @@ |
|||||
|
#ifndef _XD0MQTT_H |
||||
|
#define _XD0MQTT_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#include "mqtt_client.h" |
||||
|
|
||||
|
class XD0MQTT { |
||||
|
public: |
||||
|
XD0MQTT(void); |
||||
|
bool begin(void); |
||||
|
bool publish(const char* topic, const char* data, int len, int qos, int retain); |
||||
|
private: |
||||
|
// openssl s_client -showcerts -connect home.xd0.de:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >mqtt_xd0.de.pem
|
||||
|
const char* rootCACertificate = \ |
||||
|
"-----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faXbauX+5v3gTt23ADq1cEmv8uXr\n" \ |
||||
|
"AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" \ |
||||
|
"R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" \ |
||||
|
"JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" \ |
||||
|
"Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" \ |
||||
|
"-----END CERTIFICATE-----\n"; |
||||
|
esp_mqtt_client_handle_t client; |
||||
|
}; |
||||
|
|
||||
|
#endif /* _XD0MQTT_H */ |
@ -0,0 +1,56 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include <Wire.h> |
||||
|
|
||||
|
#include <Adafruit_Sensor.h> |
||||
|
#include "Adafruit_BME280.h" |
||||
|
|
||||
|
#include "BME280.h" |
||||
|
|
||||
|
#include "../hardware.h" |
||||
|
|
||||
|
#include "esp_log.h" |
||||
|
static const char *TAG = "BME280"; |
||||
|
|
||||
|
|
||||
|
BME280::BME280() {} |
||||
|
|
||||
|
bool BME280::begin(void) { |
||||
|
bme = new Adafruit_BME280(); // I2C (also available: hardware SPI
|
||||
|
|
||||
|
// #define BME_SDA 21
|
||||
|
// #define BME_SCL 22
|
||||
|
Wire.begin(BME_SDA, BME_SCL); |
||||
|
if (!bme->begin()) { |
||||
|
ESP_LOGE(TAG, "Could not find a valid BME280 sensor, check wiring!"); |
||||
|
} |
||||
|
/*
|
||||
|
// Set up oversampling and filter initialization
|
||||
|
bme->setTemperatureOversampling(BME680_OS_8X); |
||||
|
bme->setHumidityOversampling(BME680_OS_2X); |
||||
|
bme->setPressureOversampling(BME680_OS_4X); |
||||
|
bme->setIIRFilterSize(BME680_FILTER_SIZE_3); |
||||
|
bme->setGasHeater(320, 150); // 320*C for 150 ms
|
||||
|
*/ |
||||
|
} |
||||
|
|
||||
|
void BME280::read() { |
||||
|
#define SEALEVELPRESSURE_HPA (1013.25) |
||||
|
Serial.print("Temperature = "); |
||||
|
Serial.print(bme->readTemperature()); |
||||
|
Serial.println(" *C"); |
||||
|
|
||||
|
Serial.print("Pressure = "); |
||||
|
|
||||
|
Serial.print(bme->readPressure() / 100.0F); |
||||
|
Serial.println(" hPa"); |
||||
|
|
||||
|
Serial.print("Approx. Altitude = "); |
||||
|
Serial.print(bme->readAltitude(SEALEVELPRESSURE_HPA)); |
||||
|
Serial.println(" m"); |
||||
|
|
||||
|
Serial.print("Humidity = "); |
||||
|
Serial.print(bme->readHumidity()); |
||||
|
Serial.println(" %"); |
||||
|
|
||||
|
Serial.println(); |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
#ifndef _BME280_H |
||||
|
#define _BME280_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include <Wire.h> |
||||
|
|
||||
|
#include <Adafruit_Sensor.h> |
||||
|
#include "Adafruit_BME280.h" |
||||
|
|
||||
|
class BME280 { |
||||
|
public: |
||||
|
BME280(void); |
||||
|
bool begin(void); |
||||
|
void read(void); |
||||
|
private: |
||||
|
Adafruit_BME280 *bme; |
||||
|
}; |
||||
|
|
||||
|
#endif /* _BME280_H */ |
@ -0,0 +1,34 @@ |
|||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#define ARDUINO_SAMD_VARIANT_COMPLIANCE |
||||
|
#include "SdsDustSensor.h" |
||||
|
|
||||
|
#include "SDS011.h" |
||||
|
|
||||
|
#include "esp_log.h" |
||||
|
|
||||
|
static const char *TAG = "SDS011"; |
||||
|
|
||||
|
SDS011::SDS011() {} |
||||
|
|
||||
|
bool SDS011::begin(void) { |
||||
|
//HardwareSerial Serial2(2);
|
||||
|
sds = new SdsDustSensor(Serial2); |
||||
|
sds->begin(); |
||||
|
} |
||||
|
|
||||
|
void SDS011::readPm() { |
||||
|
PmResult pm = sds->readPm(); |
||||
|
if (pm.isOk()) { |
||||
|
Serial.print("PM2.5 = "); |
||||
|
Serial.print(pm.pm25); |
||||
|
Serial.print(", PM10 = "); |
||||
|
Serial.println(pm.pm10); |
||||
|
|
||||
|
// if you want to just print the measured values, you can use toString() method as well
|
||||
|
Serial.println(pm.toString()); |
||||
|
} else { |
||||
|
Serial.print("Could not read values from sensor, reason: "); |
||||
|
Serial.println(pm.statusToString()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#ifndef _SDS011_H |
||||
|
#define _SDS011_H |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#define ARDUINO_SAMD_VARIANT_COMPLIANCE |
||||
|
#include "SdsDustSensor.h" |
||||
|
|
||||
|
class SDS011 { |
||||
|
public: |
||||
|
SDS011(void); |
||||
|
bool begin(void); |
||||
|
void readPm(void); |
||||
|
private: |
||||
|
SdsDustSensor *sds; |
||||
|
}; |
||||
|
|
||||
|
#endif /* _SDS011_H */ |
Loading…
Reference in new issue