Corrupt data being sent

Hi, I have an arduino uno with esp-01 . If i check the serial monitor it shows that the first data sent after mqttmydevices.com,1883 is corrupted.
as below.
The arduino shows up as online but no data on dashboard.
Ive replaced both the arduino and esp01,same result. Ive connected to different wifi ame problem.

AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“TNCAPxxxxxxx”,“885xxxxxxx”
AT+CIPSTART=1,“TCP”,“mqtt.mydevices.com”,1883
AT+CIPSEND=1,40

The code uploaded is

#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTESP8266Shield.h>


// WiFi network info.
char ssid[] = "TNCAPxxxxxx";
char wifiPassword[] = "8xxxxxxx";

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






#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3
#define VIRTUAL_PIN4 V4
#define VIRTUAL_PIN5 V5

 
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.

const int tmpPin1 = 2;
const int tmpPin2 = 3;
const int tmpPin3 = 4;
const int tmpPin4 = 5;
const int tmpPin5 = 6;



OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);
OneWire oneWire4(tmpPin4);
OneWire oneWire5(tmpPin5);


DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
DallasTemperature sensors3(&oneWire3);
DallasTemperature sensors4(&oneWire4);
DallasTemperature sensors5(&oneWire5);



// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(&EspSerial);

void setup()
{
  EspSerial.begin(115200);
  //delay(20);
  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  sensors1.begin();
  sensors2.begin();
}

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

// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN1)
{
  // Send the command to get temperatures.
  sensors1.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN1, sensors1.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}

CAYENNE_OUT(VIRTUAL_PIN2)
{
  // Send the command to get temperatures.
  sensors2.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN2, sensors2.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}

CAYENNE_OUT(VIRTUAL_PIN3)
{
  // Send the command to get temperatures.
  sensors3.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN3, sensors3.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}

CAYENNE_OUT(VIRTUAL_PIN4)
{
  // Send the command to get temperatures.
  sensors4.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN4, sensors4.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}

CAYENNE_OUT(VIRTUAL_PIN5)
{
  // Send the command to get temperatures.
  sensors5.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN5, sensors5.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}

Does your code work without Cayenne? I’m guessing you can do it the way you have it here but normally you’d connect all temp sensors to the same pin as the example here has https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/master/examples/Simple/Simple.pde

first make sure you get the esp connected and sending simple data using this code:

/*
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

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 ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
   folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial hardware serial pins available on the UNO. 
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";


char username[] = "";
char password[] = "";
char clientID[] = "";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial

ESP8266 wifi(&EspSerial);

void setup()
{
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);
    Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}

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

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

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

Make sure your esp baud rate is set to115200

Thanks I tried that code and it shows corrupt data sent again.
I cant attach the actual serial monitor in anything but a jpeg because the corrupted data stops the text program from working.
I can attach the picture and hope you can see it fails after the mqqt part.
The arduino comes on line but no widget.
It goes off and on line but never any widget appearing
AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“Plants1”,“Junglebook63”
AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“Plants1”,“Junglebook63”
AT+CIPSTART=1,“TCP”,“mqtt.mydevices.com”,1883
AT+CIPSEND=1,40

follow this procedure:

  • Set the esp baud rate manually to 9600. there are several tutorials on the internet on how to do it.

  • Upload the below code:

    /*
      This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.
    
      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 ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
       folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
      2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial hardware serial pins available on the UNO.
      3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
      4. Set the network name and password.
      5. Compile and upload the sketch.
      6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    
      NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
    */
    
    //#define CAYENNE_DEBUG       // Uncomment to show debug messages
    //#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
    #include <CayenneMQTTESP8266Shield.h>
    
    // WiFi network info.
    char ssid[] = "";
    char wifiPassword[] = "";
    
    char username[] = "";
    char password[] = "";
    char clientID[] = "";
    
    // Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
    #define EspSerial Serial
    
    ESP8266 wifi(&EspSerial);
    
    void setup()
    {
      delay(10);
    
      // Set ESP8266 baud rate
      EspSerial.begin(9600);
      delay(10);
      Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
    }
    
    void loop()
    {
      Cayenne.loop();
    }
    
    // Default function for sending sensor data at intervals to Cayenne.
    // You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
    CAYENNE_OUT_DEFAULT()
    {
      // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
      Cayenne.virtualWrite(0, millis());
      // Some examples of other functions you can use to send data.
      //Cayenne.celsiusWrite(1, 22.0);
      //Cayenne.luxWrite(2, 700);
      //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
    }
    
    // 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");
    }
    

Hi,
I set up the esp01 to 9600 and uploaded the revised sketch.
I can see it doing exactly the same and sending a small amount of corrupot data evry time it does that mqtt 1883 part .
As i have tried 2 arduino uno boards,2 esp01 modules and used a seperate 3.2 volt supply for the esp.I think it must be something else but I have searched the internet without finding a similar problem.If it doesnt work I will try a different type of board ,maybe a Nano instead.

i just tried with the same setup and same code and it works for me. the corrupt data is the AT command the arduino uno is sending to esp for connection. looking at the image you send it looks like it is disconecting soon after publishing. can you try adding a new device using Bring your own thing and change the client_id in your code.

Thanks, I will try that.
I have about 8 instances of arduino waiting to connect but they dont go when i remove them.
Is there a quick way of doing that .
Thanks again

we have an issue right now with that. will let you know once done. now next add a new device as Bring your own thing to get the MQTT credentials.

Thanks, Ive tried that now and it gives the same result. I also shutdown the other project i was running just in case it was due to that. Still same corrupt data. Im beginning to think it must be the batch of ESP01 boards i have purchased…
It obviously not your end and everything else works. .

do you have an Arduino mega? also can you share your circuit daigram?

I decided enough time had been spent on that issue. It must be my end. I have moved on to using a Nodemcu v3 device which added under bring own thing straight away.
Are there any sketches to publish data from it. Its running temp sensor reading from ds18b20 and i can see it working in the serial monitor.
Thanks again for the support

which data you you want to publish. there are many examples in the library.

Thanks i can see that you deleted the pending ones. Great. i had other problems so removed the account and started afresh. looks to be going well now.

1 Like

If another device works, you may want to try to flash the latest AT firmware on your esp-01 AT | Espressif Systems (select ESP8266 AT Bin V1.7.0)

2 Likes

Thanks, When ive tried that before it ends up with unuseable esp01 modules. There are so many ways of doing things on internet and ive yet to find a clear tutorial. Seems it should be easy but maybe not.

i am not sure what is the issue with your esp, but it works fine at my end. you can try to connect them to an arduino mega serial1 where the library is most stable.

1 Like