Closed rajnish1959 closed 5 years ago
are you using Sinric or SinricPro ? Pro is still not ready for public
GOIP pins are defined by the user. In the pro example GPIO pin is defined here https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/src/switch.cpp#L25
I am using sinric (not pro) . How to know which Esp output gets on ? I can see the blue light with every tap on the test button which shows reception. But both GPIO0 and GPIO 2 do not respond.
On Friday, October 11, 2019, Aruna Tennakoon notifications@github.com wrote:
are you using Sinric or SinricPro ? Pro is still not ready for public
GOIP pins are defined by the user. In the pro example GPIO pin is defined here
https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/src/switch.cpp#L25
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.< https://ci3.googleusercontent.com/proxy/13ykD4Jzt8FIsTxKwHyq9un9EGrHrZBztHWITDNu4CXoDWPBxVG-DJLl7_jTRIBxvDufbDL_x-5_Bwe_rHOTvPuVhhgnXIK1y_IZbvPP0L31hGNJKtxNvSZI8jXKu1D4yKTOL4iic7S9vo6mAQbMWKTaTTrapfgmRIRqxS4LYKqUEMwzxA1wXmLB1XW3jfMMQOcUeD3-X2ZVJLqESO-0uRLFUoTSVwJB24OM1a_cQg=s0-d-e1-ft#https://github.com/notifications/beacon/ALR2HUPZZSWMODGLD6MLAU3QOBA4NA5CNFSM4I7XB4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA7NNCQ.gif>
I am not a computer engg but an old generation elecctronics engg. So trying to learn some arduino skills.However when I saw the problem with xml etc and your sinric suggestion I got on to try that. However I have a small (may be idiotic) idea that I would like to give. Practically we will need mobile touch app as well as alexa type voice app both in common life.And all the smart home apps already have the touch buttons for operation. So is it not possible to simply integrate the touch button in the app with alexa? Rest will be done by the app as if the button is actuaaly touched. This would limit the problem to only Alexa and mobile app (I am using amazon alexa app on mobile) .Secondly on each touch button configuration settings can be provided to take commands from alexa voice app.
On Friday, October 11, 2019, Aruna Tennakoon notifications@github.com wrote:
are you using Sinric or SinricPro ? Pro is still not ready for public
GOIP pins are defined by the user. In the pro example GPIO pin is defined here
https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/src/switch.cpp#L25
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.< https://ci3.googleusercontent.com/proxy/13ykD4Jzt8FIsTxKwHyq9un9EGrHrZBztHWITDNu4CXoDWPBxVG-DJLl7_jTRIBxvDufbDL_x-5_Bwe_rHOTvPuVhhgnXIK1y_IZbvPP0L31hGNJKtxNvSZI8jXKu1D4yKTOL4iic7S9vo6mAQbMWKTaTTrapfgmRIRqxS4LYKqUEMwzxA1wXmLB1XW3jfMMQOcUeD3-X2ZVJLqESO-0uRLFUoTSVwJB24OM1a_cQg=s0-d-e1-ft#https://github.com/notifications/beacon/ALR2HUPZZSWMODGLD6MLAU3QOBA4NA5CNFSM4I7XB4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA7NNCQ.gif>
I just saw the Audio Player example given on developer.amazon https://developer.amazon.com/blogs/alexa/post/62a7cb0c-01b0-4393-888a-7156e8717f3e/how-to-handle-touch-screen-controls-for-audio-skills-on-echo-show-and-echo-spot It uses the same logic of interaction between touch-button and Alexa without sending command to the device.
Hi rajnish! Your device have to know wich GPIO has to be used (you have to define those GPIOs in your code!). Sinric & SinricPro only sends basic commands like "turn on" / "turn off" / "set brightness". Can you share your code? This would be helpful to support you
Hi Boris, I have used the following code -
void prepareIds(); boolean connectWifi(); boolean connectUDP(); void startHttpServer(); void turnOnRelay(); void turnOffRelay(); void sendRelayState();
const char* ssid = "****"; // CHANGE: Wifi name const char* password = "****"; // CHANGE: Wifi password String friendlyName = "tv"; // CHANGE: Alexa device name const int relayPin = 5; // D1 pin. More info: https://github.com/esp8266/Arduino/blob/master/variants/d1_mini/pins_arduino.h#L49-L61
WiFiUDP UDP; IPAddress ipMulti(239, 255, 255, 250); ESP8266WebServer HTTP(80); boolean udpConnected = false; unsigned int portMulti = 1900; // local port to listen on unsigned int localPort = 1900; // local port to listen on boolean wifiConnected = false; boolean relayState = false; char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, String serial; String persistent_uuid; boolean cannotConnectToWifi = false;
void setup() { Serial.begin(115200);
// Setup Relay pinMode(relayPin, OUTPUT);
prepareIds();
// Initialise wifi connection wifiConnected = connectWifi();
// only proceed if wifi connection successful if(wifiConnected){ Serial.println("Ask Alexa to discover devices"); udpConnected = connectUDP();
if (udpConnected){
// initialise pins if needed
startHttpServer();
}
} }
void loop() {
HTTP.handleClient(); delay(1);
// if there's data available, read a packet // check if the WiFi and UDP connections were successful if(wifiConnected){ if(udpConnected){ // if there’s data available, read a packet int packetSize = UDP.parsePacket();
if(packetSize) {
//Serial.println("");
//Serial.print("Received packet of size ");
//Serial.println(packetSize);
//Serial.print("From ");
IPAddress remote = UDP.remoteIP();
for (int i =0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UDP.remotePort());
int len = UDP.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
String request = packetBuffer;
//Serial.println("Request:");
//Serial.println(request);
// Issue
https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/24 fix if(request.indexOf("M-SEARCH") >= 0) { // Issue https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch/issues/22 fix //if(request.indexOf("urn:Belkin:device:") > 0) { if((request.indexOf("urn:Belkin:device:") > 0) || (request.indexOf("ssdp:all") > 0) || (request.indexOf("upnp:rootdevice") > 0)) { Serial.println("Responding to search request ..."); respondToSearch(); } } }
delay(10);
}
} else { Serial.println("Cannot connect to Wifi"); } }
void prepareIds() { uint32_t chipId = ESP.getChipId(); char uuid[64]; sprintf_P(uuid, PSTR("38323636-4558-4dda-9188-cda0e6%02x%02x%02x"), (uint16_t) ((chipId >> 16) & 0xff), (uint16_t) ((chipId >> 8) & 0xff), (uint16_t) chipId & 0xff);
serial = String(uuid); persistent_uuid = "Socket-1_0-" + serial; }
void respondToSearch() { Serial.println(""); Serial.print("Sending response to "); Serial.println(UDP.remoteIP()); Serial.print("Port : "); Serial.println(UDP.remotePort());
IPAddress localIP = WiFi.localIP();
char s[16];
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2],
localIP[3]);
String response =
"HTTP/1.1 200 OK\r\n"
"CACHE-CONTROL: max-age=86400\r\n"
"DATE: Fri, 15 Apr 2016 04:56:29 GMT\r\n"
"EXT:\r\n"
"LOCATION: http://" + String(s) + ":80/setup.xml\r\n"
"OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n"
"01-NLS: b9200ebb-736d-4b93-bf03-835149d13983\r\n"
"SERVER: Unspecified, UPnP/1.0, Unspecified\r\n"
"ST: urn:Belkin:device:**\r\n"
"USN: uuid:" + persistent_uuid + "::urn:Belkin:device:**\r\n"
"X-User-Agent: redsonic\r\n\r\n";
// Try changing to this if you have problems discovering
/*
https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/26 String response = "HTTP/1.1 200 OK\r\n" "CACHE-CONTROL: max-age=86400\r\n" "DATE: Fri, 15 Apr 2016 04:56:29 GMT\r\n" "EXT:\r\n" "LOCATION: http://" + String(s) + ":80/setup.xml\r\n" "OPT: "http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n" "01-NLS: b9200ebb-736d-4b93-bf03-835149d13983\r\n" "SERVER: Unspecified, UPnP/1.0, Unspecified\r\n" "ST: ssdp:all\r\n" "USN: uuid:" + persistent_uuid + "::upnp:rootdevice\r\n" "X-User-Agent: redsonic\r\n\r\n"; */
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(response.c_str());
UDP.endPacket();
/* add yield to fix UDP sending response. For more informations :
https://www.tabsoverspaces.com/233359-udp-packets-not-sent-from-esp-8266-solved */ yield();
Serial.println("Response sent !");
}
void startHttpServer() { HTTP.on("/index.html", HTTP_GET, [](){ Serial.println("Got Request index.html ...\n"); HTTP.send(200, "text/plain", "Hello World!"); });
HTTP.on("/upnp/control/basicevent1", HTTP_POST, []() {
Serial.println("########## Responding to /upnp/control/basicevent1
... ##########");
//for (int x=0; x <= HTTP.args(); x++) {
// Serial.println(HTTP.arg(x));
//}
String request = HTTP.arg(0);
Serial.print("request:");
Serial.println(request);
if(request.indexOf("SetBinaryState") >= 0) {
if(request.indexOf("<BinaryState>1</BinaryState>") >= 0) {
Serial.println("Got Turn on request");
turnOnRelay();
}
if(request.indexOf("<BinaryState>0</BinaryState>") >= 0) {
Serial.println("Got Turn off request");
turnOffRelay();
}
}
if(request.indexOf("GetBinaryState") >= 0) {
Serial.println("Got binary state request");
sendRelayState();
}
HTTP.send(200, "text/plain", "");
});
HTTP.on("/eventservice.xml", HTTP_GET, [](){
Serial.println(" ########## Responding to eventservice.xml ...
########\n");
String eventservice_xml = "<scpd xmlns=\"urn:Belkin:service-1-0\">"
"<actionList>"
"<action>"
"<name>SetBinaryState</name>"
"<argumentList>"
"<argument>"
"<retval/>"
"<name>BinaryState</name>"
"<relatedStateVariable>BinaryState</relatedStateVariable>"
"<direction>in</direction>"
"</argument>"
"</argumentList>"
"</action>"
"<action>"
"<name>GetBinaryState</name>"
"<argumentList>"
"<argument>"
"<retval/>"
"<name>BinaryState</name>"
"<relatedStateVariable>BinaryState</relatedStateVariable>"
"<direction>out</direction>"
"</argument>"
"</argumentList>"
"</action>"
"</actionList>"
"<serviceStateTable>"
"<stateVariable sendEvents=\"yes\">"
"<name>BinaryState</name>"
"<dataType>Boolean</dataType>"
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"<stateVariable sendEvents=\"yes\">"
"<name>level</name>"
"<dataType>string</dataType>"
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"</serviceStateTable>"
"</scpd>\r\n"
"\r\n";
HTTP.send(200, "text/plain", eventservice_xml.c_str());
});
HTTP.on("/setup.xml", HTTP_GET, [](){
Serial.println(" ########## Responding to setup.xml ... ########\n");
IPAddress localIP = WiFi.localIP();
char s[16];
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2],
localIP[3]);
String setup_xml = "<?xml version=\"1.0\"?>"
"<root>"
"<device>"
"<deviceType>urn:Belkin:device:controllee:1</deviceType>"
"<friendlyName>"+ friendlyName +"</friendlyName>"
"<manufacturer>Belkin International Inc.</manufacturer>"
"<modelName>Socket</modelName>"
"<modelNumber>3.1415</modelNumber>"
"<modelDescription>Belkin Plugin Socket
1.0\r\n"
"
"
"
HTTP.send(200, "text/xml", setup_xml.c_str());
Serial.print("Sending :");
Serial.println(setup_xml);
});
// openHAB support
HTTP.on("/on.html", HTTP_GET, [](){
Serial.println("Got Turn on request");
HTTP.send(200, "text/plain", "turned on");
turnOnRelay();
});
HTTP.on("/off.html", HTTP_GET, [](){
Serial.println("Got Turn off request");
HTTP.send(200, "text/plain", "turned off");
turnOffRelay();
});
HTTP.on("/status.html", HTTP_GET, [](){
Serial.println("Got status request");
String statrespone = "0";
if (relayState) {
statrespone = "1";
}
HTTP.send(200, "text/plain", statrespone);
});
HTTP.begin();
Serial.println("HTTP Server started ..");
}
// connect to wifi – returns true if successful or false if not boolean connectWifi(){ boolean state = true; int i = 0;
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); Serial.println("Connecting to WiFi");
// Wait for connection Serial.print("Connecting ..."); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (i > 10){ state = false; break; } i++; }
if (state){ Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println(""); Serial.println("Connection failed."); }
return state; }
boolean connectUDP(){ boolean state = false;
Serial.println(""); Serial.println("Connecting to UDP");
if(UDP.beginMulticast(WiFi.localIP(), ipMulti, portMulti)) { Serial.println("Connection successful"); state = true; } else{ Serial.println("Connection failed"); }
return state; }
void turnOnRelay() { digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH relayState = true;
String body =
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
HTTP.send(200, "text/xml", body.c_str());
Serial.print("Sending :"); Serial.println(body); }
void turnOffRelay() { digitalWrite(relayPin, LOW); // turn off relay with voltage LOW relayState = false;
String body =
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
HTTP.send(200, "text/xml", body.c_str());
Serial.print("Sending :"); Serial.println(body); }
void sendRelayState() {
String body =
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
body += (relayState ? "1" : "0");
body += "\r\n" "</u:GetBinaryStateResponse>\r\n" "</s:Body> </s:Envelope>\r\n";
HTTP.send(200, "text/xml", body.c_str()); }
On Sat, Oct 12, 2019 at 7:29 PM Boris Jäger notifications@github.com wrote:
Hi rajnish! Your device have to know wich GPIO has to be used (you have to define those GPIOs in your code!). Sinric & SinricPro only sends basic commands like "turn on" / "turn off" / "set brightness". Can you share your code? This would be helpful to support you
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sinricpro/language-files/issues/8?email_source=notifications&email_token=ALR2HUKOOC7VGHLDEBXFWQLQOHJ5NA5CNFSM4I7XB4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCABWI#issuecomment-541327577, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALR2HUOXUQPGDFJRA4UKTR3QOHJ5NANCNFSM4I7XB4PA .
As far as i can see, you want to control a relay using wemo-emulation. What we're doing here with SinricPro is completely different (no more wemo emulation)
With SinricPro this could handled very simple! Please have a look to our Switch example: https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/src/switch.cpp
I am using Sinric Pro. How do I define or change which GPIO is controlled with the On/Off command?
#define ...
or const int ...
same way you would define it in any other arduino sketch.
Check the examples. Replace the serial print statements with digital- / analogWrite functions to control whatever GPIO you want.
Hello, I am new to this! I can connect to Sinric and get all the id etc and upload the device on off code to ESP -01. When I test it through sinric test button the blue led on ESP-01 responds also. But I do not know which is the output pin? Which GPIO of the ESP-01 will respond? How do you provide this coding and where? In wemos D1 mini the built in led was coded in the .ino example But when you go through sinric how does the device id and the GPIOs are correlated and where do you provide for that?