Compare commits
4 Commits
23d4f8d2ec
...
MQTT-Testa
| Author | SHA1 | Date | |
|---|---|---|---|
| 66953310ad | |||
|
|
5316dba469 | ||
| b6e43131a6 | |||
| 2623b3c97c |
@@ -4,15 +4,21 @@
|
|||||||
* For project specific settings. Copy to config.h and place your settings there.
|
* For project specific settings. Copy to config.h and place your settings there.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
// MQTT-Configuration
|
||||||
const char *MQTT_BROKER = "192.168.178.74";
|
const char *MQTT_BROKER = "192.168.178.74";
|
||||||
const char *MQTT_SENSOR_TOPIC = "living/sensor2";
|
const char *MQTT_CLIENT_USER = "NULL";
|
||||||
|
const char *MQTT_CLIENT_PW = "NULL";
|
||||||
const char *MQTT_CLIENT_ID = "living_mobile_sensor";
|
const char *MQTT_CLIENT_ID = "living_mobile_sensor";
|
||||||
|
|
||||||
|
const char *MQTT_SENSOR_TOPIC = "living/sensor2";
|
||||||
const char *MQTT_LAST_WILL_TOPIC = "living/sensor2/status";
|
const char *MQTT_LAST_WILL_TOPIC = "living/sensor2/status";
|
||||||
const char *MQTT_LAST_WILL_MSG = "offline";
|
const char *MQTT_LAST_WILL_MSG = "offline";
|
||||||
const char *MQTT_CLIENT_USER = "NULL"; // if NULL, no username or password is used
|
uint8_t MQTT_WILL_QOS = 1; // 0, 1 or 2
|
||||||
const char *MQTT_CLIENT_PW = "NULL"; // if NULL, no password is used
|
boolean MQTT_WILL_RETAIN = true;
|
||||||
|
|
||||||
const int AirValue = 800; //replace the value with value when placed in air
|
|
||||||
const int WaterValue = 345; //replace the value with value when placed in water
|
// Configuration for Soil-Sensor
|
||||||
|
const int AirValue = 700; //replace the value with value when placed in air (800)
|
||||||
|
const int WaterValue = 150; //replace the value with value when placed in water (345)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -225,9 +225,10 @@ void reconnect()
|
|||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
|
|
||||||
// Should work without authentication, if credentials are NULL
|
// Should work without authentication, if credentials are NULL
|
||||||
if (mqttClient.connect(MQTT_CLIENT_ID, MQTT_CLIENT_USER, MQTT_CLIENT_PW))
|
if (mqttClient.connect(MQTT_CLIENT_ID, MQTT_CLIENT_USER, MQTT_CLIENT_PW, MQTT_WILL_TOPIC, MQTT_WILL_QOS, MQTT_WILL_RETAIN, MQTT_WILL_MSG))
|
||||||
{
|
{
|
||||||
Serial.println("INFO: connected");
|
Serial.println("INFO: connected");
|
||||||
|
mqttClient.publish(MQTT_WILL_TOPIC, "online", true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -284,6 +285,7 @@ void publishData(float temp, float humid, float soil, long battery)
|
|||||||
char data[200];
|
char data[200];
|
||||||
serializeJson(doc, data);
|
serializeJson(doc, data);
|
||||||
mqttClient.publish(MQTT_SENSOR_TOPIC, data, true);
|
mqttClient.publish(MQTT_SENSOR_TOPIC, data, true);
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,6 @@
|
|||||||
#define WATCHDOG_SLEEP_FURTHER 8
|
#define WATCHDOG_SLEEP_FURTHER 8
|
||||||
|
|
||||||
// define wether to use a DHT-Sensor or not
|
// define wether to use a DHT-Sensor or not
|
||||||
bool USE_DHT_SENSOR = true;
|
#define USE_DHT_SENSOR true
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -68,7 +68,7 @@ void setup()
|
|||||||
pinMode(SOIL_PIN, INPUT);
|
pinMode(SOIL_PIN, INPUT);
|
||||||
|
|
||||||
// init the DHT22
|
// init the DHT22
|
||||||
if (USE_DHT_SENSOR == 1)
|
if (USE_DHT_SENSOR)
|
||||||
{
|
{
|
||||||
dht_init(&dht, DHT_PIN);
|
dht_init(&dht, DHT_PIN);
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ void loop()
|
|||||||
memcpy(&rh_buf[1], &battery, 4);
|
memcpy(&rh_buf[1], &battery, 4);
|
||||||
rh_send(rh_buf,RH_BUF_LEN);
|
rh_send(rh_buf,RH_BUF_LEN);
|
||||||
}
|
}
|
||||||
else if (USE_DHT_SENSOR == 1)
|
else if (USE_DHT_SENSOR)
|
||||||
{
|
{
|
||||||
if (dht_read_data(&dht, &t, &h) == 1)
|
if (dht_read_data(&dht, &t, &h) == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user