Hello everyone. I need help with my project “gate remote control”. It is only simply project to open and close our entrance gate using the Sonoff Dual with Android App Cayenne and the Cayenne dashboard on PC.
I wrote the code (see below), everything works, but there is a problem with the open/close widget. It works properly on the PC (see picture), but it does not work on the phone. (see second picture)
I do not know what I am doing wrong…
Code:
#include <CayenneMQTTESP8266.h>
#define CAYENNE_PRINT Serial // zakomentuj pokud chces usetrit misto
#define BUTTON_1 9 // koncak vrat
#define ACTUATOR_PIN 12 // auto
#define LED_PIN 13 // LED signalizace zapnuto
#define ACTUATOR2_PIN 5 // chodec
#define SWITCH 10 // tlacitko sonoffchar ssid = “hhhh”;
char wifiPassword = “hhhh”;char username = “hhhh”;
char password = “hhhh”;
char clientID = “hhhh”;void setup(){
Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
pinMode(ACTUATOR2_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_1, INPUT);
pinMode(SWITCH, INPUT);
digitalWrite(ACTUATOR_PIN, LOW);
digitalWrite(ACTUATOR2_PIN, LOW);
digitalWrite(LED_PIN, LOW);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}void Stav_Vrat(){
if (digitalRead(BUTTON_1) == LOW) {
Cayenne.virtualWrite(V1, 0, “digital_sensor”, “d”);
Serial.println(“Vrata: zavreno…”);
}
else {
Cayenne.virtualWrite(V1, 1, “digital_sensor”, “d”);
Serial.println(“Vrata: otevreno…”);
}
}void Sepnuti_tlacitka(){
if (digitalRead(SWITCH) == LOW) {
digitalWrite(ACTUATOR_PIN, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN, LOW);
}
}void loop(){
Cayenne.loop(); //spusteni Cayenne
Stav_Vrat();
Sepnuti_tlacitka();
}// This function is called when data is sent from Cayenne.
CAYENNE_IN(V2)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 1) {
digitalWrite(ACTUATOR_PIN, HIGH);
//digitalWrite(LED_PIN, LOW);/*delay(2000); digitalWrite(ACTUATOR_PIN, LOW); digitalWrite(LED_PIN, LOW); */
}
else {
digitalWrite(ACTUATOR_PIN, LOW);
//digitalWrite(LED_PIN, HIGH);
}
}CAYENNE_IN(V3)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 1) {
digitalWrite(ACTUATOR2_PIN, HIGH);
//digitalWrite(LED_PIN, LOW);/*delay(2000); digitalWrite(ACTUATOR_PIN, LOW); digitalWrite(LED_PIN, LOW); */
}
else {
digitalWrite(ACTUATOR2_PIN, LOW);
//digitalWrite(LED_PIN, HIGH);
}
}
CAYENNE_OUT(V4){Cayenne.virtualWrite(V4, WiFi.RSSI()); //display signal WiFi connection
}
Picture 1:
Picture 2:
Thanks for answer