Nie wiem czemu ale cały czas zwraca 0x0, nawet kopiuj wklej nie pomaga. Podpowiecie co robię źle?
Code: Select all
/*
Copyright (C) AC SOFTWARE SP. Z O.O
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <DallasTemperature.h>
#include <OneWire.h>
#ifdef ARDUINO_ARCH_AVR
#error "This example is not supported on Arduino AVR"
#endif
#include <SPI.h>
#include "EasyNextionLibrary.h"
#include <SuplaDevice.h>
#include <supla/storage/eeprom.h>
#include <supla/network/esp_wifi.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/control/hvac_base.h>
#include <supla/clock/clock.h>
#include <supla/network/html/time_parameters.h>
#include <supla/network/html/hvac_parameters.h>
#include <supla/control/internal_pin_output.h>
#include <supla/events.h>
#include <supla/actions.h>
#include <supla/sensor/virtual_thermometer.h>
#include <supla/control/button.h>
#include <supla/control/relay.h>
#include <supla/control/action_trigger.h>
#define ONE_WIRE_BUS 14
#define TEMP_SIZE 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
char temperatureCString[TEMP_SIZE];
char previousTemp[TEMP_SIZE] = "init";
// Add include to DS sensor
#include <supla/sensor/DS18B20.h>
#define CFG_BUTTON_GPIO 0
#define STATUS_LED_GPIO 2
#define LED_RED_GPIO 13
#define LED_BLUE_GPIO 12
#define OUTPUT_GPIO 15
#define DS18B20_GPIO 14
Supla::ESPWifi wifi;
Supla::Eeprom eeprom;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;
EasyNex myNex(Serial);
Supla::Control::Relay *filtr = nullptr;
double set ;
void setup() {
// WARNING: using default Clock class. It works only when there is connection
// with Supla server. In real thermostat application, use RTC HW clock,
// which will keep time after ESP power reset
new Supla::Clock;
// HTML www component (they appear in sections according to creation
// sequence)
new Supla::Html::DeviceInfo(&SuplaDevice);
new Supla::Html::WifiParameters;
new Supla::Html::ProtocolParameters;
new Supla::Html::StatusLedParameters;
new Supla::Html::TimeParameters(&SuplaDevice);
new Supla::Device::StatusLed(STATUS_LED_GPIO, true);
eeprom.setStateSavePeriod(5000);
auto output = new Supla::Control::InternalPinOutput(OUTPUT_GPIO);
auto redStatusLed = new Supla::Control::InternalPinOutput(LED_RED_GPIO,
false);
auto blueStatusLed = new Supla::Control::InternalPinOutput(LED_BLUE_GPIO,
false);
// Channel 0
auto hvac = new Supla::Control::HvacBase(output);
// Html page for HVAC
new Supla::Html::HvacParameters(hvac);
// Channel 1-2 - Thermometer DS18B20
// 2 DS18B20 thermometers. DS address can be omitted when there is
// only one device at a pin
DeviceAddress ds1addr = {0x28, 0x7C, 0x02, 0x43, 0xD4, 0xE1, 0x3C, 0x3B};
//DeviceAddress ds2addr = {0x28, 0xFF, 0x54, 0x73, 0x6E, 0x18, 0x01, 0x77};
new Supla::Sensor::DS18B20(DS18B20_GPIO, ds1addr);
//new Supla::Sensor::DS18B20(DS18B20_GPIO, ds2addr);
filtr = new Supla::Control::Relay(4);
hvac->addAction(Supla::TURN_OFF, redStatusLed, Supla::ON_HVAC_STANDBY, true);
hvac->addAction(Supla::TURN_OFF, blueStatusLed, Supla::ON_HVAC_STANDBY, true);
hvac->addAction(Supla::TURN_OFF, redStatusLed, Supla::ON_HVAC_COOLING, true);
hvac->addAction(Supla::TURN_OFF, blueStatusLed, Supla::ON_HVAC_HEATING, true);
hvac->addAction(Supla::TURN_ON, redStatusLed, Supla::ON_HVAC_HEATING, true);
hvac->addAction(Supla::TURN_ON, blueStatusLed, Supla::ON_HVAC_COOLING, true);
// Configure thermostat parameters
hvac->setMainThermometerChannelNo(1); // Main Thermometer DS1
hvac->setAuxThermometerChannelNo(2); // Aux Thermometer DS2
hvac->setAuxThermometerType(SUPLA_HVAC_AUX_THERMOMETER_TYPE_FLOOR);
hvac->setTemperatureHisteresisMin(20); // 0.2 degree
hvac->setTemperatureHisteresisMax(1000); // 10 degree
hvac->setTemperatureAuxMin(500); // 5 degrees
hvac->setTemperatureAuxMax(7500); // 75 degrees
hvac->setTemperatureHisteresis(40);
// To change default function to "cooling", uncomment below line. This setting
// will be applied only on first startup. On following startups, it is restored
// from flash memory
// hvac->getChannel()->setDefault(SUPLA_CHANNELFNC_HVAC_THERMOSTAT_COOL);
Supla::Channel::reg_dev.Flags |= SUPLA_DEVICE_FLAG_DEVICE_CONFIG_SUPPORTED;
auto cfgButton = new Supla::Control::Button(CFG_BUTTON_GPIO, true, true);
cfgButton->configureAsConfigButton(&SuplaDevice);
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.setName("Pompa ciepla");
SuplaDevice.begin(21); // Thermostat requires proto version >= 21
myNex.begin(9600); // Begin the object with a baud rate of 9600
int16_t currentHeatSetpoint = hvac->getTemperatureSetpointHeat();
double liczba_double = (double)currentHeatSetpoint;
set = liczba_double;
}
void getTemperature() {
int tempC;
do {
DS18B20.requestTemperatures();
tempC = DS18B20.getTempCByIndex(0);
dtostrf(tempC, 3, 1, temperatureCString);
if (tempC == (-127)) {
delay(100);
}
} while (tempC == (-127.0));
}
void loop() {
SuplaDevice.iterate();
int act = DS18B20.getTempCByIndex(0);
getTemperature();
myNex.writeNum("x1.val", act);
Serial.println("set");
Serial.print(set);
set = set/10;
myNex.writeNum("x0.val", set);
if(digitalRead(OUTPUT_GPIO)== HIGH){
myNex.writeNum("sleep",0);
myNex.writeNum("t5.pco", 2016); // Set button b0 background color to GREEN (color code: 2016)
}else{
myNex.writeNum("sleep",1);
myNex.writeNum("t5.pco", 0); // Set button b0 background color to GREEN (color code: 2016)
}
if(digitalRead(4)== HIGH){
myNex.writeNum("t4.pco", 2016); // Set button b0 background color to GREEN (color code: 2016)
}else{
myNex.writeNum("t4.pco", 0); // Set button b0 background color to GREEN (color code: 2016)
}
}