sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

sinricpro temperature #51

Closed antoniomorsello closed 4 years ago

antoniomorsello commented 4 years ago

hello, I can't read the temperature in the sinric pro dashboard of my sinricpro device, I have used this code. the device is online.this is the code://#define ENABLE_DEBUG

ifdef ENABLE_DEBUG

   #define DEBUG_ESP_PORT Serial
   #define NODEBUG_WEBSOCKETS
   #define NDEBUG

endif

include

ifdef ESP8266

   #include <ESP8266WiFi.h>

endif

ifdef ESP32

   #include <WiFi.h>

endif

include "SinricPro.h"

include "SinricProThermostat.h"

define WIFI_SSID "w"

define WIFI_PASS "a"

define APP_KEY "b" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"

define APP_SECRET "4" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"

define THERMOSTAT_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"

define BAUD_RATE 9600 // Change baudrate to your need

define DHTTYPE DHT11

include

   #define THERMOSTAT_PIN    17

float globalTemperature; bool globalPowerState;

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; }

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() { 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 setup() { Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); pinMode(THERMOSTAT_PIN, INPUT); setupWiFi(); setupSinricPro(); }

void loop() { SinricPro.handle();

}

sivar2311 commented 4 years ago

Please enable serial monitor log and post it here.

kakopappa commented 4 years ago

Which line of code read the sensor and send it to server ?

On Wed, 25 Mar 2020 at 6:02 PM Boris Jäger notifications@github.com wrote:

Please enable serial monitor log and post it here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/51#issuecomment-603777639, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZTVQJ4CXPLGPXGBDU3RJHQFZANCNFSM4LTLIJEQ .

antoniomorsello commented 4 years ago

13:11:28.484 -> 85$8⸮⸮⸮⸮D%0bG⸮ 13:11:28.859 -> 13:11:28.859 -> 13:11:28.859 -> [Wifi]: Connecting..connected! 13:11:29.475 -> [WiFi]: IP-Address is 192.168.0.104 13:11:29.507 -> Status Humidity (%) Temperature (C) (F) 13:11:30.356 -> Connected to SinricPro

sivar2311 commented 4 years ago

"5e76594f13b0d2499e311553 " -------------------------^ There is a space between the last 3 and " !

antoniomorsello commented 4 years ago

I have corrected the space but I am not comparing the temperature on the dashboard

antoniomorsello commented 4 years ago

Which line of code read the sensor and send it to server ?

I took the code in the sinric temperature examples, maybe that's not enough? I'm sorry but I'm not very practical

kakopappa commented 4 years ago

Start with the temperature sensor example

On Wed, 25 Mar 2020 at 8:03 PM antoniomorsello notifications@github.com wrote:

Which line of code read the sensor and send it to server ?

I took the code in the sinric temperature examples, maybe that's not enough? I'm sorry but I'm not very practical

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/51#issuecomment-603826142, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZRY6D2SA44AU7BUZSLRJH6JHANCNFSM4LTLIJEQ .

sivar2311 commented 4 years ago

As kakopappa wrote, please use the temperature example. https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/temperaturesensor

You have used the thermostat example, which is to control a thermostat.

antoniomorsello commented 4 years ago

Arduino:1.8.12 (Windows 8.1), Scheda:"ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 921600, None"

sinricprotempv7:58:5: error: no matching function for call to 'DHT::DHT()'

DHT dht; // DHT sensor

 ^

In file included from C:\Users\wilson\Documents\Arduino\sinricprotempv7\sinricprotempv7.ino:40:0:

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:49:4: note: candidate: DHT::DHT(uint8_t, uint8_t, uint8_t)

DHT(uint8_t pin, uint8_t type, uint8_t count=6);

^

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:49:4: note: candidate expects 3 arguments, 0 provided

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:47:7: note: candidate: constexpr DHT::DHT(const DHT&)

class DHT {

   ^

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:47:7: note: candidate expects 1 argument, 0 provided

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:47:7: note: candidate: constexpr DHT::DHT(DHT&&)

C:\Users\wilson\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:47:7: note: candidate expects 1 argument, 0 provided

C:\Users\wilson\Documents\Arduino\sinricprotempv7\sinricprotempv7.ino: In function 'void handleTemperaturesensor()':

sinricprotempv7:99:21: error: 'class DHT' has no member named 'getTemperature'

temperature = dht.getTemperature(); // get actual temperature in °C

                 ^

sinricprotempv7:101:18: error: 'class DHT' has no member named 'getHumidity'

humidity = dht.getHumidity(); // get actual humidity

              ^

C:\Users\wilson\Documents\Arduino\sinricprotempv7\sinricprotempv7.ino: In function 'void setup()':

sinricprotempv7:153:7: error: 'class DHT' has no member named 'setup'

dht.setup(DHT_PIN);

   ^

Più di una libreria trovata per "WiFi.h" Usata: C:\Users\wilson\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi exit status 1 no matching function for call to 'DHT::DHT()'

Questo report potrebbe essere più ricco di informazioni abilitando l'opzione "Mostra un output dettagliato durante la compilazione" in "File -> Impostazioni"

antoniomorsello commented 4 years ago

/*

// 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

ifdef ESP8266

   #include <ESP8266WiFi.h>

endif

ifdef ESP32

   #include <WiFi.h>

endif

include "SinricPro.h"

include "SinricProTemperaturesensor.h"

include "DHT.h" // https://github.com/markruys/arduino-DHT

define WIFI_SSID ""

define WIFI_PASS ""

define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"

define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"

define TEMP_SENSOR_ID "5e76594f13b0d2499e311553" // Should look like "5dc1564130xxxxxxxxxxxxxx"

define BAUD_RATE 9600 // Change baudrate to your need (used for serial monitor)

define EVENT_WAIT_TIME 60000 // send event every 60 seconds

ifdef ESP8266

   #define DHT_PIN    D5

endif

ifdef ESP32

   #define DHT_PIN    17

endif

DHT dht; // DHT sensor

bool deviceIsOn; // Temeprature sensor on/off state 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(String deviceId, bool &state)

/* handleTemperatatureSensor()

// setup function for WiFi connection 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]); }

// setup function for SinricPro void setupSinricPro() { // add device to SinricPro SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID]; mySensor.onPowerState(onPowerState);

// 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); SinricPro.restoreDeviceStates(true); // get latest known deviceState from server (is device turned on?) }

// main setup function void setup() { Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); dht.setup(DHT_PIN);

setupWiFi(); setupSinricPro(); }

void loop() { SinricPro.handle(); handleTemperaturesensor(); }

antoniomorsello commented 4 years ago

thanks to Kakopappa and Sivar2311 I solved it by changing the dht library to dht master