具有Web GUI的智能调节器管理系统,可控制设备周围的空气温度并提高风扇速度。控制单元连接到Wi-Fi网络,可以通过其中的任何设备进行管理。此外,未来还计划在几个控制单元之间提供某种类型的网状网络通信。系统基于ESP8266 SoC。软件完全模块化结构。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机程序源码:
- /*
- * AirConditioner.cpp
- */
- #include "AirConditioner.h"
- /* AirConditioner */
- bool AirConditioner::power;
- bool AirConditioner::mode;
- byte AirConditioner::speed;
- byte AirConditioner::set_temp;
- byte AirConditioner::delta_temp;
- float AirConditioner::cur_temp;
- byte AirConditioner::PowerPin;
- byte AirConditioner::LowSpeedPin;
- byte AirConditioner::MedSpeedPin;
- byte AirConditioner::HiSpeedPin;
- Thermometer* AirConditioner::sensor;
- AirConditioner::AirConditioner(byte PowerPin, byte LowSpeedPin, byte MedSpeedPin, byte HiSpeedPin, byte SensorPin, byte SensorResolution) {
- this->PowerPin = PowerPin;
- this->LowSpeedPin = LowSpeedPin;
- this->MedSpeedPin = MedSpeedPin;
- this->HiSpeedPin = HiSpeedPin;
- this->initGPIO();
- this->sensor = new Thermometer(SensorPin, SensorResolution);
- this->power = PowerOff;
- this->mode = Cooling;
- this->speed = LowSpeed;
- this->set_temp = set_temp_def;
- this->delta_temp = delta_temp_def;
- this->cur_temp = 0;
- }
- void AirConditioner::initGPIO() {
- pinMode(this->PowerPin, OUTPUT);
- noPullup(this->PowerPin);
- digitalWrite(this->PowerPin, Off);
- pinMode(this->LowSpeedPin, OUTPUT);
- noPullup(this->LowSpeedPin);
- digitalWrite(this->LowSpeedPin, Off);
- pinMode(this->MedSpeedPin, OUTPUT);
- noPullup(this->MedSpeedPin);
- digitalWrite(this->MedSpeedPin, Off);
- pinMode(this->HiSpeedPin, OUTPUT);
- noPullup(this->HiSpeedPin);
- digitalWrite(this->HiSpeedPin, Off);
- }
- void AirConditioner::start() {
- this->executeConditioner.initializeMs(1000, AirConditioner::execConditioner).start();
- }
- void AirConditioner::setPower(bool power) {
- digitalWrite(AirConditioner::PowerPin, power);
- }
- void AirConditioner::setSpeed(byte speed) {
- switch (speed) {
- case 0x01:
- digitalWrite(AirConditioner::LowSpeedPin, On);
- digitalWrite(AirConditioner::MedSpeedPin, Off);
- digitalWrite(AirConditioner::HiSpeedPin, Off);
- break;
- case 0x02:
- digitalWrite(AirConditioner::LowSpeedPin, Off);
- digitalWrite(AirConditioner::MedSpeedPin, On);
- digitalWrite(AirConditioner::HiSpeedPin, Off);
- break;
- case 0x03:
- digitalWrite(AirConditioner::LowSpeedPin, Off);
- digitalWrite(AirConditioner::MedSpeedPin, Off);
- digitalWrite(AirConditioner::HiSpeedPin, On);
- break;
- default:
- digitalWrite(AirConditioner::LowSpeedPin, Off);
- digitalWrite(AirConditioner::MedSpeedPin, Off);
- digitalWrite(AirConditioner::HiSpeedPin, Off);
- break;
- }
- }
- void AirConditioner::updateTemp() {
- AirConditioner::cur_temp = AirConditioner::sensor->getTemp();
- }
- void AirConditioner::execThermostat() {
- bool enabled_by_scheduler = getSchedulerStatus();
- if(enabled_by_scheduler) {
- if(AirConditioner::power == PowerOn && !AirConditioner::sensor->sensor_error) {
- if(AirConditioner::mode == Cooling){
- if(AirConditioner::cur_temp >= (AirConditioner::set_temp + AirConditioner::delta_temp))
- AirConditioner::setSpeed(AirConditioner::speed);
- else
- AirConditioner::setSpeed(Stopped);
- }
- if(AirConditioner::mode == Heating) {
- if(AirConditioner::cur_temp <= (AirConditioner::set_temp - AirConditioner::delta_temp))
- AirConditioner::setSpeed(AirConditioner::speed);
- else
- AirConditioner::setSpeed(Stopped);
- }
- }
- else if(AirConditioner::power == PowerOn && AirConditioner::sensor->sensor_error) {
- AirConditioner::setSpeed(Stopped);
- AirConditioner::setPower(Off);
- }
- else
- AirConditioner::setSpeed(Stopped);
- }
- else
- AirConditioner::setSpeed(Stopped);
- }
- void AirConditioner::execConditioner() {
- AirConditioner::updateTemp();
- AirConditioner::execThermostat();
- }
- float AirConditioner::getTemp() {
- return AirConditioner::cur_temp;
- }
- String AirConditioner::getSettings() {
- DynamicJsonBuffer jsonBuffer;
- JsonObject& root = jsonBuffer.createObject();
- JsonObject& settings = jsonBuffer.createObject();
- root["settings"] = settings;
- settings["power"] = (bool) this->power;
- settings["mode"] = (bool) this->mode;
- settings["speed"] = this->speed;
- settings["set_temp"] = this->set_temp;
- settings["set_temp_min"] = set_temp_min;
- settings["set_temp_max"] = set_temp_max;
- settings["set_temp_def"] = set_temp_def;
- settings["delta_temp"] = this->delta_temp;
- settings["delta_temp_min"] = delta_temp_min;
- settings["delta_temp_max"] = delta_temp_max;
- settings["delta_temp_def"] = delta_temp_def;
- String jsonString;
- root.printTo(jsonString);
- return jsonString;
- }
- void AirConditioner::setSettings(String jsonString) {
- if(jsonString.length() != 0) {
- DynamicJsonBuffer jsonBuffer;
- JsonObject& root = jsonBuffer.parseObject(jsonString);
- JsonObject& settings = root["settings"];
- this->power = settings["power"];
- this->setPower(this->power);
- this->mode = settings["mode"];
- if((settings["speed"] >= Stopped) && (settings["speed"] <= HiSpeed))
- this->speed = settings["speed"];
- else
- this->speed = Stopped;
- if((settings["set_temp"] >= set_temp_min) && (settings["set_temp"] <= set_temp_max))
- this->set_temp = settings["set_temp"];
- else
- this->set_temp = set_temp_def;
- if((settings["delta_temp"] >= delta_temp_min) && (settings["delta_temp"] <= delta_temp_max))
- this->delta_temp = settings["delta_temp"];
- else
- this->delta_temp = delta_temp_def;
- Settings.save(this->getSettings(), DEV_SETTINGS);
- }
- }
- String AirConditioner::getState() {
- DynamicJsonBuffer jsonBuffer;
- JsonObject& root = jsonBuffer.createObject();
- byte speed = 0x00;
- if(digitalRead(LowSpeedPin))
- speed = 0x01;
- if(digitalRead(MedSpeedPin))
- speed = 0x02;
- if(digitalRead(HiSpeedPin))
- speed = 0x03;
- JsonObject& status = jsonBuffer.createObject();
- root["status"] = status;
- status["power"] = (bool) digitalRead(PowerPin);
- status["mode"] = (bool) this->mode;
- status["speed"] = speed;
- status["set_temp"] = this->set_temp;
- JsonObject& info = jsonBuffer.createObject();
- root["info"] = info;
- info["cur_temp"] = (float) this->cur_temp;
- info["err_sensor"] = (bool) this->sensor->sensor_error;
- String jsonString;
- root.printTo(jsonString);
- return jsonString;
- }
- void AirConditioner::stopModule() {
- if(this->executeConditioner.isStarted())
- this->executeConditioner.stop();
- this->setSpeed(Stopped);
- this->setPower(PowerOff);
- }
- void AirConditioner::saveConfig() {
- Settings.save(this->getSettings(), DEV_SETTINGS);
- }
- void AirConditioner::onSystemRestart() {
- this->stopModule();
- this->saveConfig();
- }
复制代码
全部资料51hei下载地址:
Smart-Air-master.zip
(7.39 MB, 下载次数: 5)
|