|
|
@@ -5,9 +5,11 @@ |
|
|
|
#include <PubSubClient.h> |
|
|
|
#include <Dns.h> |
|
|
|
|
|
|
|
BME280I2C bme; |
|
|
|
|
|
|
|
|
|
|
|
BME280I2C bme; |
|
|
|
unsigned long loopcnt=0; |
|
|
|
|
|
|
|
|
|
|
|
float Temperatur; |
|
|
|
float Humidity; |
|
|
@@ -49,7 +51,7 @@ void MQTTcallback(char*, byte*, unsigned int); |
|
|
|
|
|
|
|
//MQTT |
|
|
|
const char *MQTT_BROKER = "loxberry"; |
|
|
|
IPAddress mqttbroker(192,168,1,128); |
|
|
|
IPAddress mqttbroker(192, 168, 1, 35); |
|
|
|
EthernetClient ethClient; |
|
|
|
PubSubClient MQTTclient(ethClient); |
|
|
|
|
|
|
@@ -71,12 +73,10 @@ void setup() { |
|
|
|
// start the Ethernet connection and the server: |
|
|
|
server.begin(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!bme.begin()) { |
|
|
|
delay(1000); |
|
|
|
Serial.println("No valid BME280 sensor, check wiring! retray"); |
|
|
|
} |
|
|
|
while (!bme.begin()) { |
|
|
|
delay(1000); |
|
|
|
Serial.println("No valid BME280 sensor, check wiring! retray"); |
|
|
|
} |
|
|
|
|
|
|
|
Serial.println("1"); |
|
|
|
|
|
|
@@ -84,13 +84,13 @@ void setup() { |
|
|
|
dnClient.begin(Ethernet.dnsServerIP()); |
|
|
|
Serial.print("dns server is at "); |
|
|
|
Serial.println(Ethernet.dnsServerIP()); |
|
|
|
if (dnClient.getHostByName(MQTT_BROKER, mqttbroker,10) == 1) { |
|
|
|
if (dnClient.getHostByName(MQTT_BROKER, mqttbroker, 10) == 1) { |
|
|
|
Serial.print(F("loxberry = ")); |
|
|
|
Serial.println(mqttbroker); |
|
|
|
} else { |
|
|
|
Serial.println("dns failed "); |
|
|
|
Serial.println( dnClient.getHostByName(MQTT_BROKER, mqttbroker,10)); |
|
|
|
mqttbroker.fromString("192.168.1.128"); |
|
|
|
Serial.println(dnClient.getHostByName(MQTT_BROKER, mqttbroker, 10)); |
|
|
|
mqttbroker.fromString("192.168.1.35"); |
|
|
|
Serial.println(mqttbroker); |
|
|
|
} |
|
|
|
bme.read(Pressure, Temperatur, Humidity); |
|
|
@@ -114,24 +114,27 @@ void loop() { |
|
|
|
bme.read(Pressure, Temperatur, Humidity); |
|
|
|
|
|
|
|
//MQTT |
|
|
|
if (!MQTTclient.connected()) { |
|
|
|
MQTTclient.connect("Arduino","loxberry","OSVL0AMqISFXgr5g"); |
|
|
|
Serial.print("MQTT Client state:"); |
|
|
|
Serial.println(MQTTclient.state()); |
|
|
|
// Abonieren von Nachrichten mit dem angegebenen Topic |
|
|
|
//MQTTclient.subscribe("/Stall/arduino1/#"); |
|
|
|
Serial.println("connected to MQTT"); |
|
|
|
if (loopcnt++ % 1000 == 0) { |
|
|
|
if (!MQTTclient.connected()) { |
|
|
|
MQTTclient.connect("Arduino", "loxberry", "OSVL0AMqISFXgr5g"); |
|
|
|
Serial.print("MQTT Client state:"); |
|
|
|
Serial.println(MQTTclient.state()); |
|
|
|
// Abonieren von Nachrichten mit dem angegebenen Topic |
|
|
|
//MQTTclient.subscribe("/Stall/arduino1/#"); |
|
|
|
Serial.println("connected to MQTT"); |
|
|
|
} |
|
|
|
temp.toCharArray(buff, temp.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Temperatur", buff); |
|
|
|
press.toCharArray(buff, press.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Pressure", buff); |
|
|
|
hum.toCharArray(buff, hum.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Humidity", buff); |
|
|
|
snprintf(msg, 50, "%ld", millis()); |
|
|
|
Serial.println("Publish message: "); |
|
|
|
Serial.println(msg); |
|
|
|
MQTTclient.publish("Arduino/Aussen/data/Alive", msg); |
|
|
|
loopcnt = 1; |
|
|
|
} |
|
|
|
temp.toCharArray(buff,temp.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Temperatur", buff); |
|
|
|
press.toCharArray(buff,press.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Pressure", buff); |
|
|
|
hum.toCharArray(buff,hum.length()); |
|
|
|
MQTTclient.publish("Arduino/Aussen/Humidity", buff); |
|
|
|
snprintf(msg, 50, "%ld", millis()); |
|
|
|
Serial.println("Publish message: "); |
|
|
|
Serial.println(msg); |
|
|
|
MQTTclient.publish("Arduino/Aussen/data/Alive", msg); |
|
|
|
|
|
|
|
// MQTTclient.loop(); // Schleife für MQTT |
|
|
|
|
|
|
@@ -150,8 +153,6 @@ void loop() { |
|
|
|
} |
|
|
|
clearAll(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// listen for incoming clients |
|
|
|
EthernetClient client = server.available(); |
|
|
|
if (client) { |
|
|
@@ -168,7 +169,6 @@ void loop() { |
|
|
|
if (c == '\n' && currentLineIsBlank) { |
|
|
|
// send a standard http response header |
|
|
|
|
|
|
|
|
|
|
|
client.print("Feuchtigkeit = "); //Prints information within qoutation |
|
|
|
client.print(hum); //Prints the Humidity read from the DHT11 on PIN 5 |
|
|
|
client.println(" % "); |
|
|
@@ -197,7 +197,6 @@ void loop() { |
|
|
|
Serial.println("client disonnected"); |
|
|
|
|
|
|
|
} |
|
|
|
delay(1000); |
|
|
|
} |
|
|
|
|
|
|
|
//// Module //// |
|
|
|