Everything works as it should, I can turn on the light with a telephone. However, I wonder why the power consumption visible below in the "0" state, i.e. when waiting for the command to be given, is higher than when the light was on?


Code: Select all
int relay = D1;
int relay2 = D2;
int boardLed = D7;
bool vin = LOW;
bool vin2 = LOW;
void setup() {
// Ustawienia GPIO
pinMode(relay,OUTPUT);
pinMode(relay2,OUTPUT);
digitalWrite(relay,HIGH);
digitalWrite(relay2,HIGH);
Particle.subscribe("LED_on", myHandler);
Particle.subscribe("LED_off", thisHandler);
Particle.subscribe("kitchen_on", myHandler2);
Particle.subscribe("kitchen_off", thisHandler2);
bool success;
success = Particle.publish("LED_on", PUBLIC);
success = Particle.publish("LED_off", PUBLIC);
success = Particle.publish("kitchen_on", PUBLIC);
success = Particle.publish("kitchen_off", PUBLIC);
}
void loop() {
if (vin==HIGH){
digitalWrite(relay,HIGH);
}
else if (vin==LOW){
digitalWrite(relay,LOW);
}
if (vin2==HIGH){
digitalWrite(relay2,HIGH);
}
else if (vin2==LOW){
digitalWrite(relay2,LOW);
}
}
void myHandler(const char *event, const char *data){
vin=LOW;
}
void thisHandler(const char *event, const char *data){
vin=HIGH;
}
void myHandler2(const char *event, const char *data){
vin2=LOW;
}
void thisHandler2(const char *event, const char *data){
vin2=HIGH;
}