Skip to content

Conversation

@sivar2311
Copy link
Collaborator

new capability added

new capability added
@sivar2311 sivar2311 requested a review from kakopappa June 9, 2022 09:46
@kakopappa
Copy link
Contributor

Tested it and works

image

We do need an example code in the example folder. Here's the code I used for testing.

`
/*

// 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 "SinricProSwitch.h"

#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 SWITCH_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need

#define BUTTON_PIN 0 // GPIO for BUTTON (inverted: LOW = pressed, HIGH = released)

bool myPowerState = false;
unsigned long lastBtnPress = 0;

void handleButtonPress() {
unsigned long actualMillis = millis(); // get actual millis() and keep it in variable actualMillis
if (digitalRead(BUTTON_PIN) == LOW && actualMillis - lastBtnPress > 1000) { // is button pressed (inverted logic! button pressed = LOW) and debounced?
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];

// send a push notification
mySwitch.sendPushNotification("Hello SinricPro!");
lastBtnPress = actualMillis;  // update last button press variable

}
}

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

// setup function for SinricPro
void setupSinricPro() {
// add device to SinricPro
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];

// setup SinricPro
SinricPro.onConnected({ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected({ Serial.printf("Disconnected from SinricPro\r\n"); });
//SinricPro.restoreDeviceStates(true); // Uncomment to restore the last known state from the server.
SinricPro.begin(APP_KEY, APP_SECRET);
}

// main setup function
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // GPIO 0 as input, pulled high
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}

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

@sivar2311 sivar2311 merged commit e0d6734 into sinricpro:master Jun 11, 2022
@sivar2311
Copy link
Collaborator Author

@kakopappa I don't think an extra example is necessary.
A section in the Readme.md and a reference to the corresponding place in the documentation should be sufficient.

I just moved the documentation to a standalone repository (https://github.com/sinricpro/esp8266-esp32-sdk-documentation) and adjusted the link in the Readme.md accordingly.

@kakopappa
Copy link
Contributor

Thanks. I have raised a PR with changes please check when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants