DEBUG connected with Wifi-2.4, channel 7 dhcp client start... [569] Connecting to Wifi-2.4 scandone ip:192.168.1.12,mask:255.255.255.0,gw:192.168.1.1 [2071] Connected to WiFi [2071] IP: 192.168.1.12 [2071] Connecting to mqtt.mydevices.com:1883 [3280] Connected [3413] Publish: topic 4, channel 65534, value NodeMCU, subkey , key [3414] Publish: topic 6, channel 65534, value Xtensa32, subkey , key [3427] Publish: topic 7, channel 65534, value 80000000, subkey , key [3501] Publish: topic 5, channel 65534, value 1.3.0, subkey , key [3572] Publish: topic 8, channel 65534, value ESP8266, subkey , key SKETCH #define CAYENNE_DEBUG #define CAYENNE_PRINT Serial #include #include #include #include #include // Data wire is conntec to the Arduino digital pin 2 #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature DS18B20(&oneWire); // WiFi network info. char ssid[] = "Wifi-2.4"; char wifiPassword[] = "gillesetsophie"; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "3f12e5f0-b73d-11e6-b51c-abe30c418779"; char password[] = "388d4c05edd69614cb7f6438685a3cdfcb3643d2"; char clientID[] = "69e316e0-6f92-11ea-b73d-1be39589c6b2"; unsigned long lastMillis = 0; #define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial. #define VIRTUAL_CHANNEL20 20 #define VIRTUAL_CHANNEL21 21 #define LEDR_PIN 6 // Do not use digital pins 0 or 1 since those conflict with the use of Serial. // constants won't change. They're used here to set pin numbers: const int BUTTON_PIN = 5; // the number of the pushbutton pin // variables will change: int BUTTON_PINState; // variable for reading the int ACTUATOR_PIN; int value; int countTours; int Kilos; int diviseur ; int addr = 0; int addr1 = 1; int addr2 = 2; void SetupDS18B20(){ DS18B20.begin(); } void setup() { Serial.begin(9600); Cayenne.begin(username, password, clientID, ssid, wifiPassword); pinMode(BUTTON_PIN, INPUT); pinMode(LEDR_PIN, OUTPUT); } void loop() { Cayenne.loop(); Kilos = (countTours / diviseur); int BUTTON_PINState = digitalRead(5); if ( BUTTON_PINState == 1) { countTours++; //ecrireEEprom(); } //lireEEprom(); Serial.print("diviseur= " ); Serial.print(diviseur); Serial.print("value= " ); Serial.println(value); } // Default function for sending sensor data at intervals to Cayenne. CAYENNE_OUT_DEFAULT() { // Write data to Cayenne here. DS18B20.requestTemperatures(); //Read temperature from DS18b20 float tempC = DS18B20.getTempCByIndex(0); Cayenne.celsiusWrite(1, tempC); //Switch wifi and wait WiFi.disconnect(); WiFi.forceSleepBegin(); delay(60000); //Switch wifi on again WiFi.mode(WIFI_STA); WiFi.begin(ssid, wifiPassword); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(200); } } // Default function for processing actuator commands from the Cayenne Dashboard. // You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands. CAYENNE_IN_DEFAULT() { //CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString()); //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message"); } CAYENNE_IN(VIRTUAL_CHANNEL20) { if (getValue.asInt() == 1) { digitalWrite(LEDR_PIN, HIGH); } else { digitalWrite(LEDR_PIN, LOW); } } CAYENNE_OUT(7) { Cayenne.virtualWrite(7, Kilos); //virtual pin1 } CAYENNE_OUT(8) { Cayenne.virtualWrite(8, countTours); //virtual pin1 } CAYENNE_OUT(9) { Cayenne.virtualWrite(9, diviseur); //virtual pin1 } CAYENNE_IN(VIRTUAL_CHANNEL21) { int value = getValue.asInt(); // 0 to 255 CAYENNE_LOG("Channel %d, pin %d, value %d", 21, ACTUATOR_PIN, value); // Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255. //analogWrite(ACTUATOR_PIN, value); diviseur=value; // ecrireEEprom(); }