Code Monkey home page Code Monkey logo

Comments (10)

sivar2311 avatar sivar2311 commented on August 17, 2024

Seems, your baudrate is wrong. (I cant see this in screenshot). Please check for correct settings!

"only need state of relay" ... Can you tell more about this? What do you want to achieve, and why do you use a garagedoor device for this?

from esp8266-esp32-sdk.

Hansta98 avatar Hansta98 commented on August 17, 2024

I just tried a round... it's a unfortunate screenshot sorry. To my aim: I switched a relay in parallel to a load (roomlight) which I want monitore. With the contacts of the relay, I want send a HIGH or a LOW signal to SinricPro, so that it knows if it's on or off. Futuremore I will realize something like a cross-switch-relay with two other relays so that I can expand the existing toggle circuit with an additional switch position over my voice. For this, Alexa must know the current state

from esp8266-esp32-sdk.

Hansta98 avatar Hansta98 commented on August 17, 2024

Screenshot_20200302-224828_AutoCAD

from esp8266-esp32-sdk.

sivar2311 avatar sivar2311 commented on August 17, 2024

What's about serial monitor issue? Is this solved? (Even this is not related to SinricPro)

I think you will agree that using a garagedoor device is the the wrong way here ;)
Please take a look at Light example. I think a SinricProLight is what you're looking for.
Since you only want to turn it on and off, you only need to implement onPowerState callback for this.
Remove the print statement, and exchange it with the code, needed to control your cicruit.

from esp8266-esp32-sdk.

Hansta98 avatar Hansta98 commented on August 17, 2024

Yeah, the point was/is that usually I had to know what's the current light state, else if I only toggle my "cross-switch-relay", once I switch one of the two other just existing switches, I had to switch the light inverted (if I want switch on light, I had to tell: "Alexa turn of the roomlight").
For this I would know how to read it, or rather to realize when it changes his state (read the input periodically with a timer or only once when state changed over an interrupt function).
The main problem is that until now I not able to sinchronize any input signal with sinricPro.

from esp8266-esp32-sdk.

sivar2311 avatar sivar2311 commented on August 17, 2024

So, i guess Serial Monitor is not a problem anymore?

To update state on SinricPro Server, use sendPowerStateEvent function (see here)
But please make sure, only send Events when state changed!

To check the current state of the relay, use a simple digitalRead.
You can do this within the loop, or via interrupt.
Are you familar with programming interrupts? This will request to set a flag and handles all other things outside the interrupt function!

If you have to say "turn off" to turn on your device, you have to invert your digitalWrite.

from esp8266-esp32-sdk.

Hansta98 avatar Hansta98 commented on August 17, 2024

In reality I dont need to know usually the current state and when it changed. (thinking) I must know it only when I ask Alexa. So an interrupt would be unnecessary. Always I switch the roomlight manually it doesnt interest Alexa, but when I command her to switch it she have to know it. So, as you told me, idea one (put it within the loop) sould work in practice

from esp8266-esp32-sdk.

sivar2311 avatar sivar2311 commented on August 17, 2024

If you don't update the current state to SinricPro server, the state will shown incorrect in Alexa App. If you have the possibillity to check the current state, you should update (only if there was a change), using the corresponding event function.

Anyways, your sketch have to know the current state (not Alexa) to control the relais correctly.
Btw, the screenshot showing german words: I live near Hamburg ;)

from esp8266-esp32-sdk.

Hansta98 avatar Hansta98 commented on August 17, 2024

Hallo silvar2311,
jetzt melde ich mich doch noch mal. Es geht um das Einlesen eines Eingangs (Pin D4) mittels Interrupt Routine. Wollte eigentlich den benötigen Wert bei Statusänderung auslesen und in eine Variable schreiben. Es scheint jedoch als ob die Interrupt-Routine kontinuierlich abgearbeitet wird. Der Serielle Monitor gibt jedenfalls nur "Mist" aus.
Die Idee dahinter war, dass Func_Roomlight über den Interrupt Pin D4 aufgerufen und dort die Variable RoomlightState überschrieben wird.

kreuzschaltung

`#define Out_Roomlight 0 // GPIO WemosPin D3 für Raumlicht schalten (schalte Relais 1K01+1K02)
#define In_Roomlight 2 // GPIO WemosPin D4 für Raumlicht Status (Relais 1K09)
#define TestPin 5 //GPIO WemosPin D1 für Testzwecke

volatile byte RoomlightState = LOW; //Raumlichtstatus
bool myPowerState = false;

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;
digitalWrite(Out_Roomlight, myPowerState);
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);
}
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}

void setupSinricPro() {
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
mySwitch.onPowerState(onPowerState);
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() {
pinMode(TestPin, OUTPUT);
pinMode(Out_Roomlight, OUTPUT);
pinMode(In_Roomlight, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(In_Roomlight), Func_RoomlightState, CHANGE);

Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}

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

void Func_RoomlightState() {
RoomlightState = digitalRead(In_Roomlight);
if (RoomlightState == HIGH) {
digitalWrite(TestPin, HIGH);
}
if (RoomlightState == LOW) {
digitalWrite(TestPin, LOW);
}
}

//Func_Roomlight wird immer aufgerufen wenn In_Roomlight mit Masse verbunden wird oder von Masse getrennt wird
//Func_Roomlight liest lediglich den aktuellen Raumlichtstatus aus
//RoomlightState == HIGH wenn In_Roomlight NICHT mit Masse verbunden ist (Raumlicht = aus)
//RoomlightState == LOW wenn In_Roomlight mit Masse verbunden ist (Raumlicht = ein)
`

from esp8266-esp32-sdk.

sivar2311 avatar sivar2311 commented on August 17, 2024

Hi! Kannst du mich mal per E-Mail kontaktieren ([email protected]).
Dann können wir mal Daten zu WhatsApp oder Telegramm austauschen und direkt schreiben.
Was hältst Du davon?

from esp8266-esp32-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.