Hi,
i’m on ESP-01 with arduino IDE
I want to synchronise my Button State on Cayenne with my pin state on the ESP . For example if my board reset when batteries low …
i saw a syncAll() function example for Ethernet arduino board. So i transforme the sketch to ESP01 :
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "aaaaa";
char wifiPassword[] = "bbbbbb";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxxxxxxxx";
char password[] = "yyyyyyyyy";
char clientID[] = "zzzzzzz";
// This flag is used so the sync only happens on the first connection.
bool isFirstConnect = true;
//===================================
//= SETUP =
//===================================
void setup() {
Serial.begin(9600);
Serial.println("\n++ Demarrage de Cayenne ++");
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
} // FIN de setup
//===================================
//= LOOP =
//===================================
void loop() {
Cayenne.loop();
} //FIN de loop
//=================================================================================
//====================== AUTRES FONCTIONS ==================================
//================================================================================
// This function will run every time the Cayenne connection is established.
CAYENNE_CONNECTED()
{
CAYENNE_LOG("Connection established");
if (isFirstConnect)
{
// This causes Cayenne to resend data for any virtual pins.
Cayenne.syncAll();
isFirstConnect = false;
}
}
CAYENNE_IN(V6)
{
CAYENNE_LOG("Current Virtual Pin 6 value: %s", getValue.asStr());
}
CAYENNE_IN(V7)
{
CAYENNE_LOG("Current Virtual Pin 7 value: %s", getValue.asStr());
}
On cayenne, i created a button on chanel 6 & 7 : when i push v7 button : Arduino serial monitor display :
[1316551] In: value 1, channel 7
[1316551] publishState: topic 1 channel 7
[1316551] Publish: topic 1, channel 7, value 1, subkey , key
[1317839] Send response: DHIDoxHDFFIGtyv
[1326015] Connection ok
But if i Reset my board i don’t see v7 state :
[3253] Connected to WiFi
[3253] IP: 192.168.0.54
[3253] Connecting to mqtt.mydevices.com:1883
[3610] Connected
[3610] Connection established
[3885] Publish: topic 5, channel 65534, value ESP8266, subkey , key
[4051] Publish: topic 7, channel 65534, value Xtensa32, subkey , key
[4176] Publish: topic 8, channel 65534, value 80000000, subkey , key
[4298] Publish: topic 6, channel 65534, value v1, subkey , key
[15453] Connection ok
Could someone help me with this function on ESP8266 board ?
Thanks