You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
Hey Guys,
I am trying to update the status of the relay through the server but doesnt seem to be working. It worked with the old sinric server. Heres the code.
#define APP_KEY "42db20f2-f08195193ab2" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "10dea-9c89-327702c47897" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LIGHT_ID "612bb2608" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need
Hey Guys,
I am trying to update the status of the relay through the server but doesnt seem to be working. It worked with the old sinric server. Heres the code.
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#include <ArduinoJson.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProLight.h"
#include <WiFiManager.h>
#include <DNSServer.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
#include <StreamString.h>
#include <WiFiUdp.h>
#include <WebSocketsClient.h>
String header;
#include <AceButton.h> // https://github.com/bxparks/AceButton
using namespace ace_button;
// Set web server port number to 80
WiFiServer server(80);
WiFiManager wifiManager;
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
WiFiClient client;
#define HEARTBEAT_INTERVAL 300000 // 5 Minutes
#define APP_KEY "42db20f2-f08195193ab2" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "10dea-9c89-327702c47897" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LIGHT_ID "612bb2608" // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE 9600 // Change baudrate to your need
#define BAUD_RATE 115200 // Change baudrate to your need
ButtonConfig config1;
AceButton button1(&config1);
void handleEvent1(AceButton*, uint8_t, uint8_t);
const int pump=0;
const int BUTTON1_PIN = 2;
uint64_t heartbeatTimestamp = 0;
bool isConnected = false;
void setPowerStateOnServer(String deviceId, String value);
void setTargetTemperatureOnServer(String deviceId, String value, String scale);
bool onPowerState(const String &deviceId, bool &state) {
if(deviceId=="612bbbc92c014831f8242608"){
Serial.printf("Device %s power turned %s \r\n", deviceId.c_str(), state?"on":"off");
if(state){
digitalWrite(pump,LOW);
Serial.println("PUMP 01 TURNED ON");
}
else{
digitalWrite(pump,HIGH);
}
}
return true; // request handled properly
}
void setupSinricPro() {
// get a new Light device from SinricPro
SinricProLight &myLight1 = SinricPro["612bbbc92c014831f8242608"];
// set callback function to RED LIGHT
myLight1.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");
//wifiManager.resetSettings();
wifiManager.autoConnect("Wi-Pump01");
Serial.println("Connected.");
server.begin();
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(pump,OUTPUT);
digitalWrite(pump,HIGH);
config1.setEventHandler(button1Handler);
button1.init(BUTTON1_PIN);
setupSinricPro();
}
void loop() {
SinricPro.handle();
button1.check();
}
void setPowerStateOnServer(String deviceId, String value) {
DynamicJsonDocument jsonBuffer(2048);
jsonBuffer["deviceId"] = deviceId;
jsonBuffer["action"] = "setPowerState";
jsonBuffer["value"] = value;
StreamString databuf;
serializeJson(jsonBuffer, databuf);
webSocket.sendTXT(databuf);
}
void setTargetTemperatureOnServer(String deviceId, String value, String scale) {
DynamicJsonDocument jsonBuffer(2048);
jsonBuffer["action"] = "SetTargetTemperature";
jsonBuffer["deviceId"] = deviceId;
JsonObject valueObj = jsonBuffer.createNestedObject("value");
JsonObject targetSetpoint = valueObj.createNestedObject("targetSetpoint");
targetSetpoint["value"] = value;
targetSetpoint["scale"] = scale;
StreamString databuf;
serializeJson(jsonBuffer, databuf);
webSocket.sendTXT(databuf);
}
void button1Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT1");
switch (eventType) {
case AceButton::kEventPressed:
Serial.println("kEventPressed");
setPowerStateOnServer("612bbbc92c014831f8242608", "OFF");
digitalWrite(0, HIGH);
break;
}
}
The text was updated successfully, but these errors were encountered: