ESP8266 project does not synchronize

Hello, in a project with ESP8266 + DS18B20, synchronization does not work, and I do not see why
The code is based on a project with arduino uno which works, but I would like to add other functions, but there is not enough space, that is why I replace by an ESP 8266

In appendix, the code, and the debug
can you help me ?

DEBUG.txt (4.3 KB)
Many thanks in advance

what do you mean by synchronize? can you provide more details.

Hello, there is no data going to the dashboard, and the device goes all the time from on-line to off-line

See the dashboard picture in the appendix

Thank you in advance for your assistance

what is this code for?

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);
    }

Hello : I have copy the sktech on ESP8266 + ds18b20+Display+ Problems - #3 by michael.mcgrew2

I searched a lot to find a sketch for ESP8266 + DS18B20 who wants to compile

in that topic there is no code which i pointed above.
try this code:

/*
Cayenne DS18B20 Example
This sketch shows how to send DS18B20 Sensor data to the Cayenne Dashboard.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
3. Attach a DS18B20 to a digital pin on your Arduino.
   Schematic:
   [Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
                   |______________|
                   |
              Digital Pin
4. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
5. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a DS18B20 Sensor widget you have added) in the Dashboard.
6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
7. Compile and upload this sketch.
8. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the DS18B20 Sensor widget you have added) with data.
   To make a temporary widget permanent click the plus sign on the widget.
*/
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTESP8266.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 1

OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);

// WiFi network info.
 char ssid[] = "ssid";
 char wifiPassword[] = "wifiPassword";
void setup()
{
	Serial.begin(9600);
   Cayenne.begin(username, password, clientID, ssid, wifiPassword);
	sensors.begin();
}

void loop()
{
	Cayenne.loop();
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  	sensors.requestTemperatures();
	Cayenne.virtualWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0). "temp", "c");
}

Hello
I tried the sketch, but here are the flaws I get

C:\Users\soene\Dropbox\ActivitĂ© complĂ©mentaire\MicrocontrĂŽleurs\Arduino\sketch_mar28a\sketch_mar28a.ino: In function ‘void OutputHandler1(Request&)’:

sketch_mar28a:77:69: error: expected unqualified-id before string constant

exit status 1
expected unqualified-id before string constant

there was a small typo. try this code:

/*
Cayenne DS18B20 Example
This sketch shows how to send DS18B20 Sensor data to the Cayenne Dashboard.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
3. Attach a DS18B20 to a digital pin on your Arduino.
   Schematic:
   [Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
                   |______________|
                   |
              Digital Pin
4. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
5. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a DS18B20 Sensor widget you have added) in the Dashboard.
6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
7. Compile and upload this sketch.
8. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the DS18B20 Sensor widget you have added) with data.
   To make a temporary widget permanent click the plus sign on the widget.
*/
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTESP8266.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 1

OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);

// WiFi network info.
 char ssid[] = "ssid";
 char wifiPassword[] = "wifiPassword";
void setup()
{
  Serial.begin(9600);
   Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  sensors.begin();
}

void loop()
{
  Cayenne.loop();
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
    sensors.requestTemperatures();
  Cayenne.virtualWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0), "temp", "c");
}

Thanks , it works

1 Like