Git Product home page Git Product logo

sinricclass's Introduction

SinricClass

An "easy to use" class for connecting your esp-module to io.sinric.com and make your projects alexa compatible.

usage

include Sinric-Library (Sinric.h) and Sinric-Device-Libraries (eg. SinricSwitch.h, SinricLight.h ...) an define credentials

...
#include <Sinric.h>
#include <SinrichSwitch.h>
...
const char* api_key = "your-api-key"
const char* deviceId = "your-device-id"
...

define callback routine(s)

void onPowerState(const string& deviceId, bool state) {
  Serial.printf("device %s turned %s\r\n, deviceId.c_str(), state?"on":"off");
}

In setup()

  ...
  Sinric.begin(api_key);
  // add a switch
  SinricSwitch& mySwitch = Sinric.add<SinricSwitch>(deviceId);
  // set callback function
  mySwitch.onPowerState(onPowerState);
  ...

In loop()

  ...
  Sinric.handle();
  ...

Implemented devices and their callbacks

  • Switch (SinricSwitch in SinricSwitch.h)

    • Callbacks:
    onPowerState(const String& deviceId, bool state)
    
  • Light (SinricLight in SinricLight.h)

    • Callbacks:
    onPowerState(const String& deviceId, bool state)
    onSetBrightness(const String& deviceId, int brightness)
    onAdjustBrightness(const String& deviceId, int brightness)
    onSetColor(const String& deviceId, double hue, double sat, double value)
    onDecColorTemperature(const String& deviceId)
    onIncColorTemperature(const String& deviceId)
    onSetColorTemperature(const String& deviceId, int colorTemperature)
    
  • Thermostat (SinricThermostat in SinricThermostat.h)

    • Callbacks:
    onPowerState(const String& deviceIde, bool state)
    onSetTargetTemperature(const String& deviceId, double temperature, const String& scale)
    onAdjustTargetTemperature(const String& deviceId, double temperature, const String& scale)
    onSetThermostatMode(const String& deviceId, const String& mode)
    

Simple add new or not yet implemented devices

  • Make a new class derrivered from SinricDevice (defined in SinricDevice.h)

  • Override constructor for propper callback init

  • Define prototype functions for needed callbacks

  • Provide callback setter function

  • Override handle() to handle incomming commands and call the right callbacks

  • Use the new device like the pre-defined

myNewSinricDevice& newDevice = Sinric.add<myNewSinricDevice>(deviceId);
newDevice.CallbackSetFunction(callback-function);

Dependencies / Needed libraries

sinricclass's People

Contributors

sivar2311 avatar per1234 avatar

Watchers

James Cloos avatar MEEDTSF avatar

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.