ssl connection works

This commit is contained in:
Wolfgang Hottgenroth
2017-08-16 11:17:23 +02:00
parent 598fc2b81f
commit 97e6dd41bb

View File

@ -1,3 +1,6 @@
#define ESP8266
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
@ -5,11 +8,16 @@
#include <DallasTemperature.h>
// #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
}
}