Hi @rsiegel, sory for late reply, cause holidays
this is the last code used :
/* Cayenne chanels :
0: button →
1: read gpio0 ←
2: temps de fonctionnement ←
3: temperature ←
4: luminausite ←
5: proximite ←
*/
//
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid = “xxxx”;
char wifiPassword = “xxxx”;
//char ssid = “xxx”;
//char wifiPassword = “xxxx”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxx”;
char password = “xxx”;
char clientID = “xxx”;
// Time
unsigned long lastMillis = 0;
// Led state
#define LED_PIN 2 //LED sur GPIO2
int current ;//connaitre l’etat de la LED et Tx a cayenne
// cayenne Rx
int cmdLed; // le flag recu par cayenne du Button ch0
// This flag is used so the sync only happens on the first connection.
bool isFirstConnect = true;
// temperature
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 0 //lire DS18b20 sur GPIO0 MODIF:ONE_WIRE_BUS D1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//===================================
//= SETUP =
//===================================
void setup() {
Serial.begin(9600);
Serial.println(“\n++ Demarrage de Cayenne ++”);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
// LED
pinMode(LED_PIN, OUTPUT);
// temperature
DS18B20.begin();
} // FIN de setup
//===================================
//= LOOP =
//===================================
void loop() {
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(2, lastMillis / 60000);
Serial.print(“\nTemps de fonctionnement(min):”); Serial.println(lastMillis / 60000);
//Some examples of other functions you can use to send data.
// temperature 18B20
float temperature = getTemperature();
Serial.print("\nTx → "); Serial.println(temperature);
Cayenne.celsiusWrite(3, temperature); // Tx cayenne en Float ok !
Cayenne.luxWrite(4, 700);
Cayenne.virtualWrite(5, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
} //FIN de tempo 10s
} //FIN de loop
//=================================================================================
//====================== AUTRES FONCTIONS ==================================
//================================================================================
CAYENNE_IN(0) // Rx de la part de cayenne sur canal0 ET retour a cayenne ch0 Etat Gpio
{
cmdLed = getValue.asInt();
digitalWrite(LED_PIN, cmdLed); // Allume ou Eteint la Led GPIO2
Serial.print(“\nGet Commande led :”); Serial.println(cmdLed);
// grab the current state of the LED.
if (digitalRead(LED_PIN) == LOW)
current = 0;
else
current = 1;
Serial.print(“Tx Etat Led → “);
Cayenne.virtualWrite(1, current, “digital_sensor”, “d”); //Tx a cayenne etat led widget STATE
Serial.println(current);
Serial.println(“wait…”);
}
//=================================================================================
float getTemperature() {
do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
//delay(100); //MODIF : timer de mesure Temp (100)
} while (temp == 85.0 || temp == (-127.0));
return temp;
}
//================================================================================
// This function will run every time the Cayenne connection is established.
CAYENNE_CONNECTED()
{
CAYENNE_LOG(“Connection established”);
Serial.println(”++ Connecte a Cayenne ! ++”);
isFirstConnect = false;
}