Re: SUPLA Air Conditioner
: sob lip 03, 2021 12:15 pm
Dopisz sobie kanał do obsługi Ds'a - new Supla::Sensor:: ...... i w #include.... bibliotekę ds18b20. Bawiłem się kilka miesięcy temu więc dokładnie nie pamiętam chyba tyle wystarczyło. W każdym razie działał, dla mnie służyło to przede wszystkim jako potwierdzenie że klima się załączyła.
Kod: Zaznacz cały
#include <supla/sensor/DS18B20.h>
.......
.......
void addControls() {
.......
.......
new Supla::Sensor::DS18B20(nr pinu);
Kod: Zaznacz cały
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/events.h>
#include <supla/actions.h>
#include <supla/sensor/DS18B20.h> //=================
#include "thermometer_ex.h"
#include "powerswitch.h"
#include <EEPROM.h>
#include "a_globals.h"
#include "eeprom_funcs.h"
#include "wifi_config.h"
#include "common.h"
#include <IRac.h>
const uint16_t kIrLed = D5;
IRac ac(kIrLed);
struct state {
uint8_t temperature = 22, fan = 0, operation = 0;
bool powerStatus;
};
state acState;
void addControls() {
/* Channel 0*/
new Supla::Control::PowerSwitch(true); /* włącznik on-off */
/* Channel 1*/
new Supla::Control::PowerSwitch(); /* grzenie/chłodzenie */
/* Channel 2*/
new Supla::Control::PowerSwitch(); /* wentylator auto/min */
/* Channel 4*/
new Supla::Control::PowerSwitch(); /* temp -/+ */
/* Channel 5*/
new Supla::Sensor::ThermometerEx(); /* temperatura nastawiona */
/* Channel 6 - Thermometer DS18B20 */
// 4 DS18B20 thermometers at pin 23. DS address can be omitted when there is only one device at a pin
DeviceAddress ds1addr = {0x28, 0xFF, 0xC8, 0xAB, 0x6E, 0x18, 0x01, 0xFC}; //adres należy odczytać z DS18B20
new Supla::Sensor::DS18B20(23, ds1addr);
}
class MyDigitalRead : public Supla::Io {
public:
int customDigitalRead(int channelNumber, uint8_t pin) {
switch (channelNumber) {
case 0: /* power_status */
{
return acState.powerStatus;
} break;
case 1: /* mode */
{
return acState.operation;
} break;
case 2: /* fan */
{
return acState.fan;
} break;
case 4: /* wartosc temperatury */
{
return acState.temperature;
} break;
};
}
void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
bool send = true;
switch (channelNumber) {
case 0: /* power_status */
{
Serial.print("changing power state to: ");
Serial.println(val);
if (val == 0)
ac.next.power = false;
else if (val == 1)
ac.next.power = true;
acState.powerStatus = val;
} break;
case 1: /* mode */
{
Serial.print("changing operating mode to: ");
Serial.println(val);
if (val == 0)
ac.next.mode = stdAc::opmode_t::kCool;
else if (val == 1)
ac.next.mode = stdAc::opmode_t::kHeat;
acState.operation = val;
} break;
case 2: /* fan */
{
Serial.print("changing fan speed to: ");
Serial.println(val);
if (val == 0)
ac.next.fanspeed = stdAc::fanspeed_t::kLow;
else if (val == 1)
ac.next.fanspeed = stdAc::fanspeed_t::kAuto;
acState.fan = val;
} break;
case 3: /* temperature */
{
uint8_t temp = acState.temperature;
if (val == 0)
{
if (temp <= 18) return;
temp--;
} else if (val == 1)
{
if (temp >= 32) return;
temp++;
}
ac.next.degrees = temp;
acState.temperature = temp;
} break;
default: send = false;
};
if (send) {
Serial.println("sending data to device");
ac.sendAc();
}
}
};
MyDigitalRead instanceMyDigitalRead;
int C_W_state = HIGH;
int last_C_W_state = HIGH;
unsigned long time_last_C_W_change = 0;
long C_W_delay = 10000; // config delay 10 seconds
Supla::ESPWifi wifi("", "");
WiFiManager wifiManager;
void setup() {
EEPROM.begin(1024);
Serial.begin(115200);
ac.next.protocol = decode_type_t::ELECTRA_AC;
guid_authkey();
/* brak zapisanego SSID -> włączamy config */
if (WiFi.SSID() == "") {
initialConfig = true;
}
/* niepoprawna wartość w EEPROM -> włączamy config */
if (EEPROM.read(300) != 60) {
initialConfig = true;
}
/* odczytywanie z EEPROM parametrów konfigracyjnych SUPLA */
eeprom_read_string(20, Supla_server, max_cr);
Serial.print("Supla server: ");
Serial.println(Supla_server);
eeprom_read_string(105, Email, max_cr);
Serial.print("Email: ");
Serial.println(Email);
eeprom_read_string(200, Supla_name, max_cr);
Serial.print("Supla name: ");
Serial.println(Supla_name);
wifi_station_set_hostname(Supla_name);
WiFi.mode(WIFI_STA);
/* niestety wemos d1 nie ma wystarczająco duże pamięcie do obsługi SSL i WifiManager*/
wifi.enableSSL(false);
addControls();
SuplaDevice.setName(Supla_name);
SuplaDevice.setStatusFuncImpl( & status_func);
SuplaDevice.begin(GUID, Supla_server, Email, AUTHKEY);
ac.next.model = 1; // Some A/Cs have different models. Try just the first.
ac.next.mode = stdAc::opmode_t::kCool; // Run in cool mode initially.
ac.next.celsius = true; // Use Celsius for temp units. False = Fahrenheit
ac.next.degrees = acState.temperature; // 25 degrees.
ac.next.fanspeed = stdAc::fanspeed_t::kLow; // Start the fan at medium.
ac.next.swingv = stdAc::swingv_t::kOff; // Don't swing the fan up or down.
ac.next.swingh = stdAc::swingh_t::kOff; // Don't swing the fan left or right.
ac.next.light = false; // Turn off any LED/Lights/Display that we can.
ac.next.beep = false; // Turn off any beep from the A/C if we can.
ac.next.econo = false; // Turn off any economy modes if we can.
ac.next.filter = false; // Turn off any Ion/Mold/Health filters if we can.
ac.next.turbo = false; // Don't use any turbo/powerful/etc modes.
ac.next.quiet = false; // Don't use any quiet/silent/etc modes.
ac.next.sleep = -1; // Don't set any sleep time or modes.
ac.next.clean = false; // Turn off any Cleaning options if we can.
ac.next.clock = -1; // Don't set any current time if we can avoid it.
ac.next.power = false; // Initially start with the unit off.
}
void loop() {
// put your main code here, to run repeatedly:
if (initialConfig == true) {
initialConfig = false;
ondemandwifiCallback(false);
}
SuplaDevice.iterate();
yield();
}