diff --git a/ESPClock.ino b/ESPClock.ino index 09f6916..6ae961b 100644 --- a/ESPClock.ino +++ b/ESPClock.ino @@ -5,11 +5,14 @@ #include #include #include +#include #include "secrets.h" const char* ssid = STASSID; const char* password = STAPSK; +const char* mqttserver = MQTTSERVER; + const int pinCS = D8; const int numberOfHorizontalDisplays = 8; const int numberOfVerticalDisplays = 1; @@ -20,10 +23,21 @@ Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVe #define DHTTYPE DHTesp::DHT22 // DHT 22 (AM2302) float temperature; +float humidity; long dhttimer; DHTesp dht; +WiFiClient espClient; +PubSubClient MQTTclient(espClient); + +long mqtttimer; +char MQTTclientName[32]; +long mqttlastsent=0; +const long mqttinterval=60000l; + +IPAddress ip; + void setup() { // Init Matrix Panel matrix.setIntensity(0); // Use a value between 0 and 15 for brightness @@ -90,6 +104,12 @@ void setup() { // Init OTA ArduinoOTA.begin(); + // Setup MQTT + sprintf(MQTTclientName, "esp8266-%06X", ESP.getChipId()); + MQTTclient.setServer(MQTTSERVER, 1883); + mqtttimer=0l; + + // Setup DHT Sensor dht.setup(DHTPIN,DHTTYPE); dhttimer=millis()+dht.getMinimumSamplingPeriod(); } @@ -97,10 +117,14 @@ void setup() { void loop() { struct tm *timeinfo; int temp; + + char topic[64]; + char payload[64]; // get DHT readings if (dhttimer