Browse Source

changes loop cnt from ms to cnt loops running (more stable)

master
agr 4 years ago
parent
commit
04a05d7ad3
1 changed files with 26 additions and 23 deletions
  1. +26
    -23
      IAQ2000+DHT11.ino

+ 26
- 23
IAQ2000+DHT11.ino View File

@@ -14,6 +14,8 @@ IAQ2000 iaq;


DHT dht(dht_apin, DHT11); DHT dht(dht_apin, DHT11);


unsigned long loopcnt=0;

// DNS // DNS
DNSClient dnClient; DNSClient dnClient;


@@ -44,7 +46,7 @@ EthernetUDP Udp;


//MQTT //MQTT
const char *MQTT_BROKER = "loxberry"; const char *MQTT_BROKER = "loxberry";
IPAddress mqttbroker(192, 168, 1, 127);
IPAddress mqttbroker(192, 168, 1, 35 );
EthernetClient ethClient; EthernetClient ethClient;
PubSubClient MQTTclient(ethClient); PubSubClient MQTTclient(ethClient);


@@ -53,7 +55,6 @@ PubSubClient MQTTclient(ethClient);
// (port 80 is default for HTTP): // (port 80 is default for HTTP):
EthernetServer server(80); EthernetServer server(80);



void setup() { void setup() {
Wire.begin(); Wire.begin();
Serial.begin(9600); Serial.begin(9600);
@@ -80,9 +81,7 @@ void setup() {
iaq.initialize(); iaq.initialize();


Serial.println( Serial.println(
iaq.testConnection() ?
"iAQ-2000 erfolgreich" :
"iAQ-2000 Fehler");
iaq.testConnection() ? "iAQ-2000 erfolgreich" : "iAQ-2000 Fehler");


dht.begin(); //DHT11 Sensor starten dht.begin(); //DHT11 Sensor starten


@@ -108,6 +107,10 @@ void setup() {
//MQTTclient.setCallback(MQTTcallback); //MQTTclient.setCallback(MQTTcallback);


//Serial.println("setup done"); //Serial.println("setup done");
dht.read();
airQuality = iaq.getIaqpred();
Temperatur = dht.readTemperature();
Humidity = dht.readHumidity();


} }


@@ -117,13 +120,11 @@ void loop() {
String hum = String(Humidity, 2); String hum = String(Humidity, 2);
char buff[20]; char buff[20];


Serial.println("LOOP10");
dht.read(); //read data from pin 5 (DHT11) dht.read(); //read data from pin 5 (DHT11)
Serial.println("LOOP20");
airQuality = iaq.getIaqpred(); airQuality = iaq.getIaqpred();
Temperatur = dht.readTemperature(); Temperatur = dht.readTemperature();
Humidity = dht.readHumidity(); Humidity = dht.readHumidity();
Serial.println("LOOP30");
//MQTT //MQTT
if (!MQTTclient.connected()) { if (!MQTTclient.connected()) {
MQTTclient.connect("Arduino", "loxberry", "OSVL0AMqISFXgr5g"); MQTTclient.connect("Arduino", "loxberry", "OSVL0AMqISFXgr5g");
@@ -133,21 +134,23 @@ void loop() {
//MQTTclient.subscribe("/Stall/arduino1/#"); //MQTTclient.subscribe("/Stall/arduino1/#");
Serial.println("connected to MQTT"); Serial.println("connected to MQTT");
} }
temp.toCharArray(buff, temp.length());
MQTTclient.publish("Arduino/Stall/Temperatur", buff);
aq.toCharArray(buff, aq.length()+1);
MQTTclient.publish("Arduino/Stall/CO2", buff);
Serial.println("CO2 buff");
Serial.println(buff);
Serial.println(aq);
hum.toCharArray(buff, hum.length());
MQTTclient.publish("Arduino/Stall/Humidity", buff);
snprintf(buff, 19, "%ld", millis());
Serial.println("Publish message: ");
Serial.println(buff);
MQTTclient.publish("Arduino/Stall/data/Alive", buff);
Serial.println("MQTT done");
// MQTTclient.loop(); // Schleife für MQTT

if (loopcnt++ % 1000 == 0) {
temp.toCharArray(buff, temp.length());
MQTTclient.publish("Arduino/Stall/Temperatur", buff);
aq.toCharArray(buff, aq.length() + 1);
MQTTclient.publish("Arduino/Stall/CO2", buff);
Serial.println("CO2 buff");
hum.toCharArray(buff, hum.length());
MQTTclient.publish("Arduino/Stall/Humidity", buff);
snprintf(buff, 19, "%ld", millis());
Serial.println("Publish message: ");
Serial.println(buff);
MQTTclient.publish("Arduino/Stall/data/Alive", buff);
Serial.println("MQTT done");
loopcnt = 1;
}
// MQTTclient.loop(); // Schleife für MQTT


// schaut on ein UDP Befehl empfangen wurde // schaut on ein UDP Befehl empfangen wurde
checkUDP(); checkUDP();


Loading…
Cancel
Save