Comments (3)
SinricProThermostat
-Class supports the sendTemperatureEvent
-Function.
Please see full documentation: https://sinricpro.github.io/esp8266-esp32-sdk/class_sinric_pro_thermostat.html#a9545808dacd9efc40a05f16e09d79b4e
from esp8266-esp32-sdk.
Closed because of inactivity
from esp8266-esp32-sdk.
Because the example code has nothing in it to handle the temp sensor. Below I have harshly added the code to allow reading a dht sensor connected on pin D1.
// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProThermostat.h"
#include "DHT.h" // https://github.com/markruys/arduino-DHT
#include "DHTesp.h"
#define WIFI_SSID "8888888"
#define WIFI_PASS "88888888"
#define APP_KEY "8888888" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "888888888" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define THERMOSTAT_ID "888888888" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 115200 // Change baudrate to your need
#define EVENT_WAIT_TIME 60000 // send event every 60 seconds
#define DHT_PIN 5
DHT dht; // DHT sensor
float globalTemperature;
bool globalPowerState;
float temperature; // actual temperature
float humidity; // actual humidity
float lastTemperature; // last known temperature (for compare)
float lastHumidity; // last known humidity (for compare)
unsigned long lastEvent = (-EVENT_WAIT_TIME); // last time event has been sent
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Thermostat %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
globalPowerState = state;
return true; // request handled properly
}
bool onTargetTemperature(const String &deviceId, float &temperature) {
Serial.printf("Thermostat %s set temperature to %f\r\n", deviceId.c_str(), temperature);
globalTemperature = temperature;
return true;
}
bool onAdjustTargetTemperature(const String & deviceId, float &temperatureDelta) {
globalTemperature += temperatureDelta; // calculate absolut temperature
Serial.printf("Thermostat %s changed temperature about %f to %f", deviceId.c_str(), temperatureDelta, globalTemperature);
temperatureDelta = globalTemperature; // return absolut temperature
return true;
}
bool onThermostatMode(const String &deviceId, String &mode) {
Serial.printf("Thermostat %s set to mode %s\r\n", deviceId.c_str(), mode.c_str());
return true;
}
bool sendTemperatureEvent ( float temperature,float humidity = -1, String cause = "PERIODIC_POLL" );
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}
IPAddress localIP = WiFi.localIP();
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
}
void setupSinricPro() {
// SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID];
SinricProThermostat &myThermostat = SinricPro[THERMOSTAT_ID];
myThermostat.onPowerState(onPowerState);
myThermostat.onTargetTemperature(onTargetTemperature);
myThermostat.onAdjustTargetTemperature(onAdjustTargetTemperature);
myThermostat.onThermostatMode(onThermostatMode);
// setup SinricPro
SinricPro.onConnected({ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected({ Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}
void handleTemperaturesensor() {
// if (deviceIsOn == false) return; // device is off...do nothing
unsigned long actualMillis = millis();
if (actualMillis - lastEvent < EVENT_WAIT_TIME) return; //only check every EVENT_WAIT_TIME milliseconds
//temperature = dht.getTemperature(); // get actual temperature in °C
temperature = dht.getTemperature() * 1.8f + 32; // get actual temperature in °F
humidity = dht.getHumidity(); // get actual humidity
if (isnan(temperature) || isnan(humidity)) { // reading failed...
Serial.printf("DHT reading failed!\r\n"); // print error message
return; // try again next time
}
SinricProThermostat &myThermostat = SinricPro[THERMOSTAT_ID];
bool success = myThermostat.sendTemperatureEvent(temperature, humidity); // send event
if (success) { // if event was sent successfuly, print temperature and humidity to serial
Serial.printf("Temperature: %2.1f Celsius\tHumidity: %2.1f%%\r\n", temperature, humidity);
} else { // if sending event failed, print error message
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}
lastTemperature = temperature; // save actual temperature for next compare
lastHumidity = humidity; // save actual humidity for next compare
lastEvent = actualMillis; // save actual time for next compare
}
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
dht.setup(DHT_PIN);
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
handleTemperaturesensor();
}
from esp8266-esp32-sdk.
Related Issues (20)
- Emulating a momentary switch with Sinric Pro HOT 2
- I'm stuck coding for multiple devices. (ESP8266) HOT 10
- missing capability on AC Unit HOT 3
- Manual Push switch not working when disconnected from internet. HOT 8
- Connection rest by peer HOT 12
- Compilation error: invalid user-defined conversion from 'SINRICPRO_3_0_1::SinricProClass::Proxy' to 'SinricProDoorbell&&' {aka 'SINRICPRO_3_0_1::SinricProDoorbell&&'} [-fpermissive] HOT 5
- Error compiling code - probably upon recent update to ArduinoJSON HOT 2
- sinric app somtimes unresponsive app and serial different values HOT 27
- Sinric Pro With ESP8266 and OLED SSD1306 Display HOT 5
- Enable and Disable A4988 stepper driver with ESP8266 digital pin HOT 3
- Issues with Sending Sensor Data to Sinric Pro from ESP32 HOT 3
- Error compiling code - vtable undefined HOT 14
- OTA with non-local network HOT 4
- Temperature Sensor Type and Alexa HOT 3
- Arduino uno r4 wifi HOT 4
- Adding device through the app HOT 3
- Button to turn on a RGB strip light HOT 2
- AC Unit HOT 7
- help dear HOT 2
- Switch state change time out. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp8266-esp32-sdk.