sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

2 in 1 #35

Closed kanawati975 closed 4 years ago

kanawati975 commented 4 years ago

Hi everyone... Sorry to bother, but I'm very interested in your project and trying to learn as much as possible. My question: Would be hard to combine two sketches together? For instance: I'm using SinricPro on an ESP8266-12E and made a smart light in my room, and I'd love to also connect a sensor (such as DHT11) to the same board. Would that be possible? Thanks for your patience

sivar2311 commented 4 years ago

Sure, you can have as much SinricPro devices you like to have in just one sketch / one ESP module. Include the libraries you need (SinricProLight.h and SinricProTemperaturesensor.h) and implement the callback functions to your need.

Edit: Example: I have a Switch device and a Temperature sensor device running in one sketch:

  SinricProSwitch& myPC = SinricPro[PC_ID];
  myPC.onPowerState(onTurnOnPC);

  SinricProTemperaturesensor &myTemp = SinricPro[TEMP_ID];
  myTemp.onPowerState(onTempPower);
kanawati975 commented 4 years ago

@sivar2311 Vielen, lieben Dank. Thank you very much for your answer. I know for a fact that my lack of skills can be annoying, so please excuse my Ignorance. So, if I just compared a two examples and combined them and removed the repeated parts, I should have 2 functions in 1 sketch. Right?

sivar2311 commented 4 years ago

So, if I just compared a two examples and combined them and removed the repeated parts, I should have 2 functions in 1 sketch. Right?

Yes, that's correct! See MultiSwitch_beginner Example.

In this example only Switch devices types have been used, but you could mix device types as you like to have it.

kanawati975 commented 4 years ago

@sivar2311 Thank you once again. This is helpful. Would it be ok if I mixed two examples and let you take a look? If you have some free time, that would be highly appreciated.

sivar2311 commented 4 years ago

Sure.

Please upload your code to gist github and share the link

sivar2311 commented 4 years ago

@kanawati975 How did you proceed?

kanawati975 commented 4 years ago

@sivar2311 Sorry I've got caught IRL and have a bad flu. I'll work on it as soon as possible

sivar2311 commented 4 years ago

Oh, I'm sorry to hear that. Take your time. Get well soon!!

sivar2311 commented 4 years ago

Closed due to inactivity. Please, feel free to reopen this issue if needed.

kanawati975 commented 4 years ago

Hi again, This is an attempt... Hoping that I did ok:

https://gist.github.com/kanawati975/f5ae00fda05fa4f7d7a9273a64c2de26

Apart of a warning of depricated something in Websocketclient, the sketch was complied with no errors.