Giter Club home page Giter Club logo

sinric's Introduction

sinric's People

Contributors

fabian57fabian avatar gizmocuz avatar kakopappa avatar mmphego avatar nandyba avatar samueldacostaaraujonunes avatar sivar2311 avatar thegoliathgeek avatar totolook avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sinric's Issues

Web or android app with sinric?

Love your work bro... I have used wemo multiple switches worked well... Upto 4 switches i tried and it worked well...

Now im gonna try sinric this weekend...and before that i ve a question....
Along with alexa is it possible to perform on off dim etc functions using an app??

Any future plans??

New account already has devices?

Hi Kakopappa,
I created a new account on www.sinric.com but when I entered the account it already had several devices in there that look like devices from other folks? Or are those just sample devices I can delete?

Thanks - MacSass
grafik

Also I would need some more explanation how I actually can include code to switch my devices from the ESP (e.g. I want to send RF433 signals when a switch is triggered). I´m not sure where I would add that to the .ino code ... some more help would be appreciated.

Can't control device from Alexa app, can only edit.

So far I love the ease of use of this code!!!
There seems to be a problem with controlling the device in the Alexa app (Android). After discovering the device, when you click on the Icon it takes you to the Device Settings screen. There doesn't appear to be anyway to turn on/off the device from the Smart Home section. It happens for both the Light and Switch type devices. Works fine using voice activation.

Light state issue.

@kakopappa

After testing the light device within the alexa app this is the issues i have found:

  • Brightness:
    if i set the brightness (e.g 65%) of the light, the light state in the alexa app goes to the OFF state, but the physical light stays ON then When i turn the light back "ON" in the alexa app the brightness set goes back to 100% but the slider stays @ (e.g 65%).

  • Set Color:
    If i set a color of the light, the light state in the alexa app goes to the OFF state then When i turn the light back "ON" in the alexa app the color set goes back to white (overwrites color set to white).

Video

Cannot discover devices

Alexa does not discover anything. The ESP does receive test signals from sinric.com, but device discovery by Alexa doesn't work.

I have installed the beta version of the skill.

What would you suggest?

multi_nav_wifi:51: error: 'class WiFiManager' has no member named 'addAP'

Hi

I ve copied the code from "multi_wifi_example.ino"
and added all essential libraries, after compiling im getting this error

`

WARNING: Spurious .github folder in 'WiFiManager' library
G:\003 Projects\ESP8266\arduino\03 sinric\multiwifi_sw\multi_nav_wifi\multi_nav_wifi.ino: In function 'void load(WiFiManager&)':

multi_nav_wifi:51: error: 'class WiFiManager' has no member named 'addAP'

			   wifiManager.addAP(obj["SSID"], obj["Password"]);

						   ^

G:\003 Projects\ESP8266\arduino\03 sinric\multiwifi_sw\multi_nav_wifi\multi_nav_wifi.ino: In function 'void save(WiFiManager&)':

multi_nav_wifi:76: error: 'class WiFiManager' has no member named 'getAP'

	 for (int i = 0; auto ap = wifiManager.getAP(i); i++ ) {

										   ^

exit status 1
'class WiFiManager' has no member named 'addAP'

`

can you tell me what is wrong??

thanks..

Can't register

I try to register, then try to login and the site says "user not found".

Version with WifiManager

It would be great if you had a version that used a WifiManager so the network credentials didn't have to be hard coded. Makes it easier to move the device from location to location. Thanks.

Can't login - User not found

I register, after I return to the main screen, Registration successful at top. But when I try to login, "User not found". I.E. does not show page. Firefox seams to work but cant get logged in.

Device / Light State (Turn on/turn off)

Hi,
I was wondering why my Wemos does not work anymore properly.
For some reason if I use the window shutters option in sinric.com to create a device, I do not get a powerstate anymore, it just sends a percentage to my wemos.
Is that something you changed or is that a problem with amazon?

Possible to Set up a remote button?

I have several ESP-01s set up with sinric. All work terrific! I am wondering if it is possible to set up a separate ESP-01 with momentary N/O pushbuttons connected to the GPIO pins which when pressed will cause it to send an Alexa command to Sinric to toggle a device on an ESP that is programmed with a sinric device. (Essentially, acting like an Amazon Echo sending a command to sinric, but in an area where an Echo is not located.)

Think of it as setting up wireless 3Way switches where the main ESP (device programed) is replacing a standard toggle switch and the remote ESP (the device I'm trying to describe) is acting like the 3Way switch but it does not have access to the hardwired light circuit (like a traditional 3way lighting circuit would) or an echo device.

My thought is that a single ESP-01, using RX, TX, GPIO_0 and GPIO_2 as inputs could act as manual remote control to toggle (on/off depending on current state of the device) up to four sinric devices (programmed to other ESPs) when the (selected) pin is driven low (via pushbutton) and using a pullup resistor.

I haven't any idea what the action code would look like for this, but it seems the schematic would be pretty simple. I would, most preferably, use the WiFi Manager to establish the WiFi, API, and device_id parameters. Also, pressing two buttons at once would trigger a WiFi reset and spiffs format so the device could be reconfigured on demand.

I know this seems like I am trying to replace voice control with pushbutton control and that it is counter intuitive, but in my circumstance, having the flexibility to voice, phone via Alexa app, or manually trigger light switches is necessary as my family is hesitant to transition from old technology.

Any and all help and suggestions is appreciated. Thanks.

Not available on Amazon UK

Hi. I can't seem to download the skill from Amazon it isn't showing is the skill list and when I use the link on the sinric site it redirects me to amazon uk.

Thanks.

Translate to Hindi

Can you guys translate this to Hindi, please?

Short Skill Description:
Connect your WeMos mini D1, ESP8266, ESP32 or Arduino development boards with Amazon Alexa

Full Skill Description:
With Sinric, you can connect your WeMos mini D1, ESP8266, ESP32, Arduino development boards with Alexa without emulating as a Belkin switch.

How to use

  1. Goto sinric.com
  2. Create an account and log in
  3. Create a new device. eg: tv
  4. Use the API key displayed on the home screen to connect your development board.

Here is an example of how to connect :
https://github.com/kakopappa/sinric/blob/master/arduino_examples/switch_example.ino

replace the "Place your API key here", "your wifi ssid", "your wifi password" in the code with your details

  1. Install / Enable Sinric smart home skill
  2. Ask Alexa to discover devices.
  3. Say Alexa, turn on "tv"

Example Phrases:
Alexa, turn on tv
Alexa, turn on bedroom lights
Alexa, dim bedroom lights

Keywords (Search terms):
Connect ESP8266 to Alexa, connect wemos mini to alexa, wemos mini emulate alexa

German translation

I am in Austria, and sadly the SKILL is not available on amazon.de.

Would you consider publishing it in German too?

I would gladly assist translating phrases to German.

Door Opener

Any plan to set up something that responds to "open" and "close" commands?

Not in Google home

I don't see this app in google home but it states it will work? Is this a mistake?

how to use data from "SetColor"?

Hi there, does any one have a small example or can explain how u use the returned data from "SetColor". I have looked at the examples but cant figure it out sorry. I have never used the ArduinoJson Library before.
This is what i currently have in my code, but the serial monitor does not print out the hue value.

    else if(action == "SetColor") {
      String hue = json ["value"]["hue"]["value"];
      Serial.println (" Color is set too: " + hue);          
    }

I am trying to get the hue value so i can send it to a strip of WS2812b LED's using the FastLED library.
Thanks in advance...

Sinric.com not showing my info

@kakopappa
I noticed yesterday when I log into sinric.com my devices are not there and the API is not mine. However, it welcomes me by name and all of my previously installed devices continue to work with alexa as expected. Thanks.

Multiple devices on a single 8266?

Will the code support multiple devices on the same ESP8266? I have been using your other wemo switch software (great job by the way!!!), except it starts having connection issues when I get up to 4 device ID's.

Will this new skill support multiple device ID's? It's a little confusing trying to reference the example.

Thanks again!!!

discovery failed.

I am not able to add device to alexa.
Im getting this on the serial monitor:

WiFi connected. IP address: 192.168.1.70
[WSc] Service connected to sinric.com at url: /
Waiting for commands from sinric.com ...
[WSc] get text: {"action":"test","sender":"web"}
[WSc] received test command from sinric.com

the test is from me using the test button on the sinric.com website.
I have the sinric skill added to alexa.

any help would be appreciated.

Custom color layout

@kakopappa

Is it possible you could add a custom color layout to: light devices, set color section?
it doesn't matter how you set the ("hue": , "saturation": , "brightness":) ill be able to work around it. i just don't want to use the pre-define colors for my custom color, as i'm using them for those specific colors.

Show device type capabilities when creating a device

Show device capabilities when you select a device type. For an example. If you select "Light" as device type when creating a device, it should show the enduser that light supports below capabilities

Alexa.PowerController
Alexa.BrightnessController
Alexa.ColorController
Alexa.ColorTemperatureController

so the users have an idea what it can do.

ESP-01?

Hi,
I installed the switch_example software on an ESP-01, I see Alexas commands on the Serial monitor. How do I control an IO output pin? I looked at both outputs (IO00 and IO02). Am I supposed to write the software to drive one of these pins?

Code help

Hello All, I'm Dan. I am fairly new to coding but have a little experience with arduino. I have managed to add code to the sinric multi switch example and control 4 relays. What i would like to do is build a central heating thermostat using sinric. Any help with the code or even just a push in the right direction would be really helpful. Sorry this is not an issue with sinric and just an issue with my lack of coding experience.

No Value payload in"SetColorTemperture"

When I tell Alexa (using the app) to set the color temperature (not increase/decrease), there is no Value payload, has this gone?
when I ask alexa, it (she?) tells me my value is out of range.

Excellent Work on this project by the way!

please help running Sinric on Raspberry pi

Hi Kakopappa, could you please provide me with some quick basic steps on how I can get Sinric running on a raspberry pi. I got it working great on arduino but I'm confused on Raspberry Pi.
I see the node-js sample ( I already have nodejs on the Pi) but I'm not understanding how to control the gpio pins on the pi with Alexa.
I'm very excited in getting sinric to run.
Thanks in advance.

IS dimming supported yet ? {"deviceId": xxxx, "action": "", value: 0}

Hi! have you implemented dimming?
I ask because although I've successfully used your example for openning and closing a relay, I have problem with dimming.
When I ask alexa to set device to xx (percent) the response in the serial is
{"deviceId": xxxx, "action": "", value: 0}
so she doen't even recognises the action... so nothing really happens. She says "I don't know what went wrong"...

Lose Sinric Control with WiFi Manager w/parameters & custom IP

Probably not a Sinric issue, but it is manifesting itself here...

Because I am using a combination of UDP and Alexa, I need to be able to set the IP address with the WiFi manager. I am using the standard code found on Tzapu GitHub... WiFi Manager with parameters and custom IP.

The first time the ESP connects to wifi, it uses DHCP to set the IP. Then with reset, it shows the custom IP in the WiFi manager and can be changed, if desired. I am not changing the IP. I just want to see it.

The sinric code works fine on first ESP connect to wifi, but after reset, it no longer receives the sinric commands... possible conflict with websockets???

The UDP connections all work fine and physical buttons work also.

I'm puzzled and confused. I'm not sure what is happening in the SPIFFS or websockets upon reset of the ESP. I don't change the IP address or any parameters. If I comment out:


  //set static ip
  IPAddress _ip,_gw,_sn;
  _ip.fromString(static_ip);
  _gw.fromString(static_gw);
  _sn.fromString(static_sn);

  wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);

Everything works as expected after formatting the SPIFFS and reentering the parameters. I just can't identify the IP address.

Thoughts and suggestions are appreciated. The full code is listed here:

#include <FS.h>  // this needs to be first, or it all crashes and burns...

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WebSocketsClient.h>   // get it from https://github.com/Links2004/arduinoWebSockets/releases 
#include <ArduinoJson.h>        // get it from https://arduinojson.org/ or install via Arduino library manager
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>        // get it from https://github.com/the-real-orca/WiFiManager
#include <WiFiUDP.h>  //get it from https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi/src


/* This version of the sinric switch uses the multi wifi manager to input wifi, API, and two device ids.
 * It is designed to work with an ESP8266-01 with the following pin use:
 * GPIO_2 = device 1. LOW is ON.  HIGH is OFF.  Intended to sink to an optoisolator with pin 1 connected to Vcc and pin 2 to GPIO_2.
 * GPIO_0 = device 2. LOW is ON.  HIGH is OFF.  Intended to sink to an optoisolator with pin 1 connected to Vcc and pin 2 to GPIO-0.
 * RX (pin 3) = Used to manually toggle device_ID 1. Connect a momentary N/O switch to GROUND and RX with a 220 ohm pullup resistor to Vcc.
 * TX (pin 1) = Used to manually toggle device_ID 2. Connect a momentary N/O switch to GROUND and RX with a 220 ohm pullup resistor to Vcc.
 * Pressing both TX and RX buttons (to low) will cause the ESP to reset and go into AP WiFiManager mode.
 * All other ESP pins are connected per usual ESP set up.
 */

 
 /*ESP8266-01 Flash settings:
  * Board - Generic ESP8266
  * Flash Mode - DIO
  * Flash Size - 1M (512K SPIFFS)
  * Debug Port - Disabled
  * Debug Level - None
  * lwIP Variant - V2 prebuilt (MSS=536)
  * Reset Method - ck
  * Crystal Frequency - 26M
  * Flash Frequency - 40MHz
  * CPU Frequency - 80MHz
  * Upload Speed - 115200
  * Port - TBD by your setup
  * Programmer - Arduino as ISP
  */
 
WebSocketsClient webSocket;
WiFiClient client;
WiFiUDP Udp;

//Swithc Contols variables
int GPIO_2 = 2; //To control Device 1
int GPIO_0 = 0; //To control Device 2
int RX = 3;  //To manually toggle device 1
int TX = 1;  //To manually toggle device 2
int RXState; //State of RX pin
int TXState; //State of TX pin
int GPIO_2State; //State of device 1
int GPIO_0State; //State of device 2

#define API_ENDPOINT "http://sinric.com"
#define HEARTBEAT_INTERVAL 300000 // 5 Minutes

//Set variables for UDP server
char udp_port[6]; //used to store in json the udp port from user input on WiFi Manager page
unsigned int udpPort;  // used by udp.begin()command (it is udpPort converted for use)
char pktBuf[25]; //buffer for UDP packets

 //Define the local IP variables
char ap_SSID[25] = "NewBox"; //SSID for ESP when in AP mode
char static_ip[16]; // ip address for ESP when in client mode
char static_gw[16]; // gateway address for ESP when in client mode
char static_sn[16]; // subnet address for ESP when in client mode

//Define the Alexa variables
char api_key[37]; //Sinric API Key
char first_deviceId[25]; //alexa device 1
char second_deviceId[25]; //alexa device 2

//Define the heartbeat timer variables
uint64_t heartbeatTimestamp = 0; //heartbeat timer reset
bool isConnected = false;

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
//  Serial.println("Should save config");
  shouldSaveConfig = true;
}

  //if a udp command is received, toggle the appropriate device
void toggle(String device_Id) {
  if (device_Id == (first_deviceId)) {
    GPIO_2State = digitalRead(GPIO_2);
    digitalWrite(GPIO_2, !GPIO_2State);
//       Serial.println("Device 1");
//       Serial.println("Status:");
//       Serial.println(GPIO_2State);
//       Serial.println("Waiting");
  } else if (device_Id == (second_deviceId)) {
    GPIO_0State = digitalRead(GPIO_0);
    digitalWrite(GPIO_0, !GPIO_0State);
//       Serial.println("Device 2:");
//       Serial.println("Status:");
//       Serial.println(GPIO_0State);
//       Serial.println("Waiting");
  }  
}

  //Alexa "ON" response
void turnOn(String deviceId) {
  if (deviceId == (first_deviceId)) {  // Device ID of first device  
//    Serial.print("Turn on 1st-device id: ");
//    Serial.println(deviceId);
        digitalWrite(GPIO_2, LOW);
  } else if (deviceId == (second_deviceId)) {  // Device ID of second device 
//    Serial.print("Turn on 2nd-device id: ");
//    Serial.println(deviceId);
        digitalWrite(GPIO_0, LOW);
  } else { 
//    Serial.print("Turn on for unknown device id: ");
//    Serial.println(deviceId);
  }     
}

  //Alexa "OFF" response
void turnOff(String deviceId) {
   if (deviceId == (first_deviceId)) {  // Device ID of first device  
//     Serial.print("Turn off 1st-Device ID: ");
//     Serial.println(deviceId);
        digitalWrite(GPIO_2, HIGH);
   } else if (deviceId == (second_deviceId)) { // Device ID of second device
//     Serial.print("Turn off 2nd-Device ID: ");
//     Serial.println(deviceId);
        digitalWrite(GPIO_0, HIGH);
  } else {
//     Serial.print("Turn off for unknown device id: ");
//     Serial.println(deviceId);
  }
}


  //Receive and process an Alexa command
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
    case WStype_DISCONNECTED:{
      isConnected = false;    
//      Serial.printf("[WSc] Webservice disconnected from sinric.com!\n");
      break;
    case WStype_CONNECTED: {
      isConnected = true;
//      Serial.printf("[WSc] Service connected to sinric.com at url: %s\n", payload);
//      Serial.printf("Waiting for commands from sinric.com ...\n");        
      }
      break;
    case WStype_TEXT: {
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject((char*)payload); 
        String deviceId = json ["deviceId"];     
        String action = json ["action"];

        if(action == "setPowerState") { // Switch or Light
            String value = json ["value"];
            if(value == "ON") {
                turnOn(deviceId);
            } else {
                turnOff(deviceId);
            }
        } else if(action == "setBrightness") {
          
        } else if(action == "AdjustBrightness") {
          
        } else if (action == "test") {
//            Serial.println("[WSc] received test command from sinric.com");
        }
      }
      break;
    case WStype_BIN:
//      Serial.printf("[WSc] get binary length: %u\n", length);
      break;
    }
  }
}

void setup() {
  Serial.begin(115200);
//  Serial.println();

  // Setup pins to off position
  pinMode(GPIO_2, OUTPUT);
  digitalWrite(GPIO_2, HIGH);
  pinMode(GPIO_0, OUTPUT);
  digitalWrite(GPIO_0, HIGH);
  pinMode(RX, INPUT_PULLUP);
  pinMode(TX, INPUT_PULLUP);


  
//  SPIFFS.format();  //clean FS, for testing

  //read configuration from FS json
//  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
//    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
//      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
//        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
//          Serial.println("\nparsed json");

          strcpy(ap_SSID, json["ap_SSID"]);
          strcpy(udp_port, json["udp_port"]);
          strcpy(api_key, json["api_key"]);
          strcpy(first_deviceId, json["first_deviceId"]);
          strcpy(second_deviceId, json["second_deviceId"]);

          if(json["ip"]) {
            Serial.println("setting custom ip from config");
            //static_ip = json["ip"];
            strcpy(static_ip, json["ip"]);
            strcpy(static_gw, json["gateway"]);
            strcpy(static_sn, json["subnet"]);
//            Serial.println(static_ip);
          } else { 
//            Serial.println("no custom ip in config");
          }
        } else {
//          Serial.println("failed to load json config");
        }
      }
    }
  } else {
//    Serial.println("failed to mount FS");
  }
  //end read
//  Serial.println(static_ip);
//  Serial.println(udp_port);
//  Serial.println(api_key);
//  Serial.println(first_deviceId);
//  Serial.println(second_deviceId);


  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_ap_SSID("ap_SSID", "Box name and SSID", ap_SSID, 25);
  WiFiManagerParameter custom_udp_port("udp_port", "UDP Port", udp_port, 6);
  WiFiManagerParameter custom_api_key("api key", "api key", api_key, 37);
  WiFiManagerParameter custom_first_deviceId("1st-deviceId", "1st deviceId", first_deviceId, 25);
  WiFiManagerParameter custom_second_deviceId("2nd-deviceId", "2nd deviceId", second_deviceId, 25);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //set static ip
  IPAddress _ip,_gw,_sn;
  _ip.fromString(static_ip);
  _gw.fromString(static_gw);
  _sn.fromString(static_sn);

  wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
  
  //add all your parameters here
  wifiManager.addParameter(&custom_ap_SSID);
  wifiManager.addParameter(&custom_udp_port);
  wifiManager.addParameter(&custom_api_key);
  wifiManager.addParameter(&custom_first_deviceId);
  wifiManager.addParameter(&custom_second_deviceId);

  //reset settings - for testing
  //wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  //wifiManager.setTimeout(120);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect(ap_SSID)) {
//    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(3000);
  }

  //if you get here you have connected to the WiFi
//  Serial.println("connected to WiFi...");

  //read updated parameters
  strcpy(ap_SSID, custom_ap_SSID.getValue());
  strcpy(udp_port, custom_udp_port.getValue());
  strcpy(api_key, custom_api_key.getValue());
  strcpy(first_deviceId, custom_first_deviceId.getValue());
  strcpy(second_deviceId, custom_second_deviceId.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["ap_SSID"] = ap_SSID;
    json["udp_port"] = udp_port;
    json["api_key"] = api_key;
    json["first_deviceId"] = first_deviceId;
    json["second_deviceId"] = second_deviceId;

    json["ip"] = WiFi.localIP().toString();
    json["gateway"] = WiFi.gatewayIP().toString();
    json["subnet"] = WiFi.subnetMask().toString();

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
//      Serial.println("failed to open config file for writing");
    }

    json.prettyPrintTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

//  Serial.println("local ip");
//  Serial.println(WiFi.localIP());
//  Serial.println(WiFi.gatewayIP());
//  Serial.println(WiFi.subnetMask());
    delay(500);

  // Alexa server address, port and URL
  webSocket.begin("iot.sinric.com", 80, "/");


  // Alexa event handler
  webSocket.onEvent(webSocketEvent);
  webSocket.setAuthorization("apikey", api_key);
  // try again every 5000ms if connection has failed
  webSocket.setReconnectInterval(5000);   // If you see 'class WebSocketsClient' has no member named 'setReconnectInterval' error update arduinoWebSockets


  //Start UDP server
  udpPort = atoi(udp_port);
  Udp.begin(udpPort);
//  Serial.println("UDP Target IP");
//  Serial.println(WiFi.localIP());
//  Serial.println("UDP port");
//  Serial.println(udpPort);
  
} //end void setup()


void loop() {
  
  //Get the state of all four pins
  RXState = digitalRead(RX); //Toggle button for device 1 (LOW is pressed)
  TXState = digitalRead(TX); //Toggle button for device 2 (LOW is pressed)
  GPIO_2State = digitalRead(GPIO_2); //State of device 1 (on/Off)
  GPIO_0State = digitalRead(GPIO_0); //State of device 2 (on/Off)

  //Receive incoming Udp packet and parse information
  int pktSize = Udp.parsePacket();
  if (pktSize) {
//    Serial.print(Udp.remoteIP());
//    Serial.print(":");
//    Serial.println(Udp.remotePort());
    Udp.read(pktBuf, pktSize);
   }

  String packetbuffer (pktBuf);

  //What to do with Udp packet
  if (packetbuffer.startsWith(first_deviceId)) {  //Toggle first_deviceId
    String device_Id = (first_deviceId);
    toggle(device_Id);
    String packetbuffer = "";
    for (int i = 0; i<25; i++){
      pktBuf[i] = (char) 0;
      }
    Udp.flush();
    delay(1000);
        
    } else if (packetbuffer.startsWith(second_deviceId)) {  //Toggle second_deviceId
      String device_Id = (second_deviceId);
      toggle(device_Id);
      String packetbuffer = "";
      for (int i = 0; i<25; i++){
        pktBuf[i] = (char) 0;
        }
      Udp.flush();
      delay(1000);
    }

  if (RXState ==LOW && TXState == LOW) {  //If RX & TX are LOW then reset the ESP into AP mode
    WiFiManager wifiManager;
//    SPIFFS.format();
    delay(1000);
    wifiManager.resetSettings();
    delay(1000);
    {
      ESP.reset();  //reset and try again, or maybe put it to deep sleep
      delay(5000);
    }
    
  } else if (RXState == LOW && TXState == HIGH) {  //Else if RX is LOW and TX is HIGH flip device_id 1
    digitalWrite(GPIO_2, !GPIO_2State);
    delay(1000);
    
  } else if (RXState == HIGH && TXState == LOW) {  // Else if RX is HIGH and TX is LOW flip device_id 2
    digitalWrite(GPIO_0, !GPIO_0State);
    delay(1000);
  }

  webSocket.loop();
  
  if(isConnected) {
    uint64_t now = millis();
      
    // Send heartbeat in order to avoid disconnections during ISP resetting IPs over night.
    if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
      heartbeatTimestamp = now;
      webSocket.sendTXT("H");          
    }
  }   
}

Sinric Down?

Is Sinric down? I cant login to my account anymore.. it always comes up with User not found . I can create a new account but the problem persists. Any info on this?

Multiple Pin Out Config

In the future would it be possible to include pin outputs in the example code e.g. for a relay. This would be extremely beneficial for beginners such as myself who are still learning.

Really appreciate the hard work, registration and integration to this point has been absolutely seamless.

Many thanks

Support for rolling shutters possible?

Hi,
I have motorized shutters in my house.
They come with a remote which has the ability to move them up, down and to a specified (favourite) position.
Is it possible to add support for this case? (Voice command "up", "down" and something for the favourite position?)

sinric NodeMCU

Hi

I'm Having issues getting this to run with the NodeMUC that i use.

a small back story i had this working with 2 relays using the Wemos code that you did a few months back and it was flawless for quite a time. then all of a sudden my relays kept switching them selfs off with no command from anyone in the house and as they was on the TV it was not really working out. I ended up moving away from that.

As i have been off work i though i would revisit setting the relays back up and have come accross Sinric. I have signed up to the site got an API key and a set of Device Id's for the relays. I upload the sketch and it seems to go onto the NodeMUC fine. I open the serial monitor and can see that i'm reaching out to sinric server. I even run a test from sinric back to the Node MCU and can see the test happening in real time.

Problem starts here - i can not get Alexa discovery to find the relays.
I'm thinking either this wont work with the NodeMCU or more likely its something i'm doing wrong. any help would be greatly appreciated

Alexa doesn't seem to be communicating properly

Hey, want to use this to trigger a relay. I don't see where you define which pins to use. I got as far as connecting to Alexa, but when I tell Alexa to turn on or off the relay, she says "Okay" but then nothing happens. I've tried every single other way to control a relay with Alexa and an ESP8266 d1 mini, but this is the first way that I can get Alexa to discover the device

Report back thermostat's data to Alexa - This is essential...

Hi! we need to be able to report the changing temperature from the thermostat back to alexa, as this is the only way to have alexa's temperarure value correnspond to the real one.
This will be really useful as:
We would be able to ask alexa what's the temperature and get a responce
We would be able to ask to make warmer (+1) or cooler (-1) and get a responce with the new temperature.

The above 2 functionallities are essential to the remote operation of a thermostat as we want to operate it without looking at it's screen.
So we have to know the current temperature and also have reported back the value that is set.

Also if I ask alexa to set the temperature to 23 and afterwards I manually change the setpoint to 25 then I will get false answers to the above questions as alexa won't know the new setpoint.

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.