使用Google Assistant触发通过IFTT和粒子云切换Raspberry Pi GPIO

时间:2018-12-13 01:25:14

标签: python raspberry-pi google-assistant-sdk particles ifttt

我正在尝试利用Google Assistant命令通过IFTTT和粒子云在Raspberry pi上触发GPIO4。

我已验证:

  1. IFTTT正确接受命令
  2. Particle Cloud与Raspberry Pi接口并正在触发连接到GPIO4的继电器
  3. IFTTT已正确连接到我的粒子云帐户。

这是我的粒子云代码,谁能告诉我我要去哪里错了?

(注D0可能是GPIO4的粒子云参考)

int relay = D0; //pin to which relay is connected
int boardLed = D7;
bool vin = LOW; //a virtual boolean variable

// setup() is run only once, it's where we set up GPIO and initialise peripherals
void setup() {

// Setup GPIO
pinMode(relay,OUTPUT); // relay pin is set as output
digitalWrite(relay,HIGH);
// Subscribe to events published by IFTTT using Particle.subscribe
Particle.subscribe("welcome_mode_off", myHandler); //turning off function declaration
Particle.subscribe("welcome_mode_pn", thisHandler); //turning on function declaration
}

// loop() runs continuously, it's our infinite loop.
void loop() {
if (vin==HIGH)
{
digitalWrite(relay,LOW);
}
else if (vin==LOW)
{
digitalWrite(relay,HIGH);
}

}

//our events are called when IFTTT applets are triggered
void myHandler(const char *event, const char *data)
{
vin=LOW;
}
void thisHandler(const char *event, const char *data)
{
vin=HIGH;
}

0 个答案:

没有答案