hello using wemos d1r2 board to read status of door contact sensor with sinric pro got is working using sketch but notifications to my android device are reversed closed displays open and open displays closed tried changing values in sketch but nothing changes
could someone help me please
thanking your in advance
Please read and use this topic: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum
sorry dont know how to use forum
I flagged this because of double posting.
You should have spent a few minutes reading the forum guidelines. Please read the advice in the topic "How to get the best from this forum". How to get the best out of this forum
[
hello using wemos d1r2 board to read status of door contact sensor with sinric pro got is working using sketch but notifications to my android device are reversed closed displays open and open displays closed tried changing values in sketch but nothing changes
could someone help me please
thanking your in advance
Not unless you post your full sketch, using code tags when you do
You need to make some minor changes. OOPS I cannot see your sketch, did you forget to post it?
I flagged this because of double posting.
You should have spent a few minutes reading the forum guidelines. Please read the advice in the topic "How to get the best from this forum". How to get the best out of this forum
/*
- Example for SinricPro Contactsensor device:
-
- Setup contactsensor device
-
- Support onPowerState to turn on / turn off contactsensor
-
- Checks a contact sensor connected to CONTACT_PIN and send event if state changed
- If you encounter any issues:
-
- check the readme.md at esp8266-esp32-sdk/README.md at master · sinricpro/esp8266-esp32-sdk · GitHub
-
- ensure all dependent libraries are installed
-
- open serial monitor and check whats happening
-
- check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
-
- visit Issues · sinricpro/esp8266-esp32-sdk · GitHub and check for existing issues or open a new one
*/
- visit Issues · sinricpro/esp8266-esp32-sdk · GitHub and check for existing issues or open a new one
//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 "SinricProContactsensor.h"
#define WIFI_SSID ""
#define WIFI_PASS "4"
#define APP_KEY "933ff7aa0" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "b4b6" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define CONTACT_ID "63" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define CONTACT_PIN D5 // PIN where contactsensor is connected to
// LOW = contact is closed
// HIGH = contact is open
bool myPowerState = true; // assume device is turned on
bool lastContactState = false;
unsigned long lastChange = 0;
/**
- @brief Checks contactsensor connected to CONTACT_PIN
- If contactsensor state has changed, send event to SinricPro Server
- state from digitalRead():
-
LOW = doorsensor is open -
HIGH = contactsensor is closed
*/
void handleContactsensor() {
// if (!myPowerState) return; // if device switched off...do nothing
unsigned long actualMillis = millis();
if (actualMillis - lastChange < 250) return; // debounce contact state transitions (same as debouncing a pushbutton)
bool actualContactState = digitalRead(CONTACT_PIN); // read actual state of contactsensor
if (actualContactState != lastContactState) { // if state has changed
Serial.printf("Contactsensor is %s now\r\n", actualContactState?"open":"closed");
lastContactState = actualContactState; // update last known state
lastChange = actualMillis; // update debounce time
SinricProContactsensor &myContact = SinricPro[CONTACT_ID]; // get contact sensor device
myContact.sendContactEvent(actualContactState); // send event with actual state
}
}
/**
- @brief Callback for setPowerState request
- @param deviceId String containing deviceId (useful if this callback used by multiple devices)
- @param[in] state bool true=turn on device / false=turn off device
- @param[out] state bool true=device turned on / false=device turned off
- @return true request handled properly
- @return false request can't be handled because some kind of error happened
*/
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
myPowerState = state;
return true; // request handled properly
}
// 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
SinricProContactsensor& myContact = SinricPro[CONTACT_ID];
// set callback function to device
myContact.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);
}
// main setup function
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
pinMode(CONTACT_PIN, INPUT_PULLUP
Why are you not following the forum guidelines, maybe you did not take the time to read them. I will not take the time to check your code either. Post your code in code tags.
ecause i dont know how this works
i was told i posted in wrong place and i did not include code im a newbie
i posted code tanks i am new so please be patient with me
Then you obviously did not read the advice linked to
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use [color = red]code tags[/color] (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.