From 97e6dd41bb2d4a453a9ac2a2166c351c9b1a3a1d Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 16 Aug 2017 11:17:23 +0200 Subject: [PATCH] ssl connection works --- sketch_aug14a/sketch_aug14a.ino | 44 +++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/sketch_aug14a/sketch_aug14a.ino b/sketch_aug14a/sketch_aug14a.ino index aa6015c..ced2f07 100644 --- a/sketch_aug14a/sketch_aug14a.ino +++ b/sketch_aug14a/sketch_aug14a.ino @@ -1,3 +1,6 @@ +#define ESP8266 + + #include #include @@ -5,11 +8,16 @@ #include -// #define DEBUG +#define DEBUG +#define SLEEP -const char* ssid = "EG-WLAN"; -const char* password = "shae3sheuthai2oluNgiqueiyahyumeiphughi8jequeil6taethooyeik1joh5"; -const char* mqttServer = "172.16.2.15"; +//const char* ssid = "EG-WLAN"; +//const char* password = "shae3sheuthai2oluNgiqueiyahyumeiphughi8jequeil6taethooyeik1joh5"; +//const char* mqttServer = "172.16.2.15"; +const char* ssid = "iPhone"; +const char* password = "wollud123456"; +const char* mqttServer = "broker.hottis.de"; +const uint16 mqttPort = 8883; //const char* ssid = "WLan-KI-Pro"; //const char* password = "sVAPHCmo"; //const char* mqttServer = "10.11.184.91"; @@ -17,7 +25,7 @@ const char* mqttServer = "172.16.2.15"; const uint16_t sleepTime = 300; -WiFiClient espClient; +WiFiClientSecure espClient; PubSubClient client(espClient); @@ -36,7 +44,7 @@ void setup() { #endif setup_wifi(); - client.setServer(mqttServer, 1883); + client.setServer(mqttServer, mqttPort); sensors.begin(); uint8_t num = sensors.getDeviceCount(); @@ -51,13 +59,6 @@ void setup() { Serial.println("Started."); #endif - mqtt_connect(); - read_thermometer(); - -#ifdef DEBUG - Serial.println("Sleeping"); -#endif - ESP.deepSleep(sleepTime * 1000000); } @@ -147,4 +148,21 @@ void read_thermometer() { } void loop() { + static uint32_t lastMillis = 0; + mqtt_connect(); + + uint32_t currentMillis = millis(); + if (currentMillis - lastMillis > 1000) { + lastMillis = currentMillis; + + read_thermometer(); + +#ifdef SLEEP +#ifdef DEBUG + Serial.println("Sleeping"); +#endif + ESP.deepSleep(sleepTime * 1000000); +#endif + } + }