Final commit - working and deployed
This commit is contained in:
parent
de87f20129
commit
6177d8e4e9
1 changed files with 34 additions and 6 deletions
|
|
@ -32,9 +32,13 @@
|
||||||
|
|
||||||
#include "Zigbee.h"
|
#include "Zigbee.h"
|
||||||
#include <OneWireESP32.h>
|
#include <OneWireESP32.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
|
||||||
#define TEMP_PIN 10
|
#define TEMP_PIN 10
|
||||||
#define PUMP_PIN 13
|
#define PUMP_PIN 13
|
||||||
|
#define LED_PIN 8
|
||||||
|
|
||||||
|
CRGB leds[1];
|
||||||
|
|
||||||
/* Zigbee temperature sensor configuration */
|
/* Zigbee temperature sensor configuration */
|
||||||
#define ANALOG_DEVICE_ENDPOINT_NUMBER 1
|
#define ANALOG_DEVICE_ENDPOINT_NUMBER 1
|
||||||
|
|
@ -60,6 +64,11 @@ static float get_temp(int gpio) {
|
||||||
|
|
||||||
uint8_t devices = ds.search(addr, MaxDevices);
|
uint8_t devices = ds.search(addr, MaxDevices);
|
||||||
|
|
||||||
|
Serial.printf("Number of devices: %d\r\n", devices);
|
||||||
|
|
||||||
|
ds.request();
|
||||||
|
vTaskDelay(800 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
for (int i = 0; i < devices; i++) {
|
for (int i = 0; i < devices; i++) {
|
||||||
uint8_t err = ds.getTemp(addr[i], temp[i]);
|
uint8_t err = ds.getTemp(addr[i], temp[i]);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -67,12 +76,13 @@ static float get_temp(int gpio) {
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
Serial.println(errt[err]);
|
Serial.println(errt[err]);
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
avg += temp[i];
|
avg += temp[i];
|
||||||
num += 1;
|
num += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (num == 0) return -10.0;
|
if (num == 0) return -100.0;
|
||||||
return avg / num;
|
return avg / num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,11 +91,13 @@ static float get_temp(int gpio) {
|
||||||
static void temp_sensor_value_update(void *arg) {
|
static void temp_sensor_value_update(void *arg) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Read temperature sensor value
|
// Read temperature sensor value
|
||||||
float tsens_value = temperatureRead();
|
// float tsens_value = temperatureRead();
|
||||||
// float tsens_value = get_temp(TEMP_PIN);
|
float tsens_value = get_temp(TEMP_PIN);
|
||||||
Serial.printf("Updated temperature sensor value to %.2f°C\r\n", tsens_value);
|
|
||||||
// Update temperature value in Temperature sensor EP
|
// Update temperature value in Temperature sensor EP
|
||||||
zbTempSensor.setTemperature(tsens_value);
|
if(tsens_value > -50.0 && tsens_value < 150.0) {
|
||||||
|
zbTempSensor.setTemperature(tsens_value);
|
||||||
|
}
|
||||||
|
|
||||||
// check temp and control pump
|
// check temp and control pump
|
||||||
if (tsens_value >= zbAnalogTemp.getAnalogOutput() + 5.0 || tsens_value < 0) { // < 0 for safety if value is uninitialized
|
if (tsens_value >= zbAnalogTemp.getAnalogOutput() + 5.0 || tsens_value < 0) { // < 0 for safety if value is uninitialized
|
||||||
|
|
@ -102,11 +114,17 @@ static void temp_sensor_value_update(void *arg) {
|
||||||
|
|
||||||
/********************* Arduino functions **************************/
|
/********************* Arduino functions **************************/
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, 1);
|
||||||
|
leds[0] = CRGB::Red; FastLED.show();
|
||||||
|
|
||||||
// Init button switch
|
// Init button switch
|
||||||
pinMode(button, INPUT_PULLUP);
|
pinMode(button, INPUT_PULLUP);
|
||||||
pinMode(PUMP_PIN, OUTPUT);
|
pinMode(PUMP_PIN, OUTPUT);
|
||||||
|
digitalWrite(PUMP_PIN, HIGH); // default to high just in case
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
// while(!Serial);
|
||||||
|
leds[0] = CRGB::Orange; FastLED.show();
|
||||||
|
|
||||||
// actual temp given by the thermometer
|
// actual temp given by the thermometer
|
||||||
zbTempSensor.setManufacturerAndModel("ESP32H2", "Furnace Pump");
|
zbTempSensor.setManufacturerAndModel("ESP32H2", "Furnace Pump");
|
||||||
|
|
@ -125,6 +143,7 @@ void setup() {
|
||||||
Zigbee.addEndpoint(&zbTempSensor);
|
Zigbee.addEndpoint(&zbTempSensor);
|
||||||
Zigbee.addEndpoint(&zbAnalogTemp);
|
Zigbee.addEndpoint(&zbAnalogTemp);
|
||||||
|
|
||||||
|
leds[0] = CRGB::Yellow; FastLED.show();
|
||||||
|
|
||||||
Serial.println("Starting Zigbee...");
|
Serial.println("Starting Zigbee...");
|
||||||
// When all EPs are registered, start Zigbee in End Device mode
|
// When all EPs are registered, start Zigbee in End Device mode
|
||||||
|
|
@ -135,6 +154,9 @@ void setup() {
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Zigbee started successfully!");
|
Serial.println("Zigbee started successfully!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leds[0] = CRGB::Green; FastLED.show();
|
||||||
|
|
||||||
Serial.println("Connecting to network");
|
Serial.println("Connecting to network");
|
||||||
while (!Zigbee.connected()) {
|
while (!Zigbee.connected()) {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
|
@ -142,6 +164,8 @@ void setup() {
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
|
leds[0] = CRGB::Blue; FastLED.show();
|
||||||
|
|
||||||
// Optional: If time cluster is added, time can be read from the coordinator
|
// Optional: If time cluster is added, time can be read from the coordinator
|
||||||
timeinfo = zbTempSensor.getTime();
|
timeinfo = zbTempSensor.getTime();
|
||||||
timezone = zbTempSensor.getTimezone();
|
timezone = zbTempSensor.getTimezone();
|
||||||
|
|
@ -157,6 +181,7 @@ void setup() {
|
||||||
|
|
||||||
// Start Temperature sensor reading task
|
// Start Temperature sensor reading task
|
||||||
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 3072, NULL, 10, NULL);
|
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 3072, NULL, 10, NULL);
|
||||||
|
leds[0] = CRGB::White; FastLED.show();
|
||||||
|
|
||||||
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
|
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
|
||||||
// min_interval and max_interval in seconds, delta (temp change in 0,1 °C)
|
// min_interval and max_interval in seconds, delta (temp change in 0,1 °C)
|
||||||
|
|
@ -165,6 +190,9 @@ void setup() {
|
||||||
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
|
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
|
||||||
zbTempSensor.setReporting(10, 300, 1);
|
zbTempSensor.setReporting(10, 300, 1);
|
||||||
zbAnalogTemp.setAnalogOutput(60.0); // starting default value
|
zbAnalogTemp.setAnalogOutput(60.0); // starting default value
|
||||||
|
|
||||||
|
leds[0] = CRGB::Black; FastLED.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue