[solved] Unable to get data on Cayenne dashboard, please help

I am retrieving data from 3 adxl345 sensors connected to Arduino Uno which intern connected to ESP8266 NodeMCU (via I2C), i am getting data when i don’t connect to Cayenne but connecting to Cayenne my board is resetting.

Following is my ESP8266 code;

#define CAYENNE_PRINT Serial
#include <Wire.h>
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid = “xxxxxxx”;
char wifiPassword = “xxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
char password = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
char clientID = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

unsigned long lastMillis = 0;

int data={0,0,0,0,0,0,0,0,0};
int x,y,z,x2,y2,z2,x3,y3,z3;

void setup(void) {
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

Serial.begin(115200); /* begin serial for debug /
Wire.begin(D1, D2); /
join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}

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

//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();

Wire.requestFrom(8, 15); /* request & read data of size 13 from slave */
int i=0;

while(Wire.available()){
int c = Wire.read();
data[i]=c;
i++;
}

x=map(data[0],0,255,-127,127);
y=map(data[1],0,255,-127,127);
z=map(data[2],0,255,-127,127);
x2=map(data[3],0,255,-127,127);
y2=map(data[4],0,255,-127,127);
z2=map(data[5],0,255,-127,127);
x3=map(data[6],0,255,-127,127);
y3=map(data[7],0,255,-127,127);
z3=map(data[8],0,255,-127,127);

Serial.print(x);
Serial.print(“,”);
Serial.print(y);
Serial.print(“,”);
Serial.print(z);
Serial.print(“,”);
Serial.print(x2);
Serial.print(“,”);
Serial.print(y2);
Serial.print(“,”);
Serial.print(z2);
Serial.print(“,”);
Serial.print(x3);
Serial.print(“,”);
Serial.print(y3);
Serial.print(“,”);
Serial.println(z3);
delay(1000);

Cayenne.virtualWrite(1, x);
Cayenne.virtualWrite(2, y);
Cayenne.virtualWrite(3, z);
Cayenne.virtualWrite(4, x2);
Cayenne.virtualWrite(5, y2);
Cayenne.virtualWrite(6, z2);
Cayenne.virtualWrite(7, x3);
Cayenne.virtualWrite(8, y3);
Cayenne.virtualWrite(9, z3);
}
}

Please help

Why do you use Cayenne.virtualWrite inside main loop, move it from there.

But still the same problem, please help

#include <Wire.h>
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid = “xxxxxxx”;
char wifiPassword = “xxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = " ";
char password = " ";
char clientID = " ";
unsigned long lastMillis = 0;

int data={0,0,0,0,0,0,0,0,0};
int x,y,z,x2,y2,z2,x3,y3,z3;

void setup(void) {
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

Serial.begin(115200); /* begin serial for debug /
Wire.begin(D1, D2); / join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}

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

//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();

Wire.requestFrom(8, 15); /* request & read data of size 13 from slave */
int i=0;

while(Wire.available()){
int c = Wire.read();
data[i]=c;
i++;
}

x=map(data[0],0,255,-127,127);
y=map(data[1],0,255,-127,127);
z=map(data[2],0,255,-127,127);
x2=map(data[3],0,255,-127,127);
y2=map(data[4],0,255,-127,127);
z2=map(data[5],0,255,-127,127);
x3=map(data[6],0,255,-127,127);
y3=map(data[7],0,255,-127,127);
z3=map(data[8],0,255,-127,127);

Serial.print(x);
Serial.print(“,”);
Serial.print(y);
Serial.print(“,”);
Serial.print(z);
Serial.print(“,”);
Serial.print(x2);
Serial.print(“,”);
Serial.print(y2);
Serial.print(“,”);
Serial.print(z2);
Serial.print(“,”);
Serial.print(x3);
Serial.print(“,”);
Serial.print(y3);
Serial.print(“,”);
Serial.println(z3);
delay(10000);
}
}

CAYENNE_OUT(V0)
{
Cayenne.virtualWrite(V0, x);
}

CAYENNE_OUT(V1)
{
Cayenne.virtualWrite(V1, y);
}

CAYENNE_OUT(V2)
{
Cayenne.virtualWrite(V2, z);
}

CAYENNE_OUT(V3)
{
Cayenne.virtualWrite(V3, x2);
}

CAYENNE_OUT(V4)
{
Cayenne.virtualWrite(V4, y2);
}
CAYENNE_OUT(V5)
{
Cayenne.virtualWrite(V5, z2);
}
CAYENNE_OUT(V6)
{
Cayenne.virtualWrite(V6, x3);
}
CAYENNE_OUT(V7)
{
Cayenne.virtualWrite(V7, y3);
}
CAYENNE_OUT(V8)
{
Cayenne.virtualWrite(V8, z3);

}

@amruthrajsagar you are using MQTT so cayenne.virtualWrite is placed in main loop at an time interval interval using millis.

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(0, lastMillis);
    //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);
  }
}

if i do so, i only get values one time and it gets reset . it is not uploading to cloud

i would request you to alter the following code of mine to upload data to Cayenne, it will be a great pleasure
, thank you

#include <Wire.h>

int data={0,0,0,0,0,0,0,0,0};
int x,y,z,x2,y2,z2,x3,y3,z3;
void setup() {
Serial.begin(9600); /* begin serial for debug /
Wire.begin(D1, D2); /
join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}

void loop() {

Wire.requestFrom(8, 15); /* request & read data of size 13 from slave */
int i=0;

while(Wire.available()){
int c = Wire.read();
data[i]=c;
i++;
//Serial.print(c);
//Serial.print(“,”);
}
x=map(data[0],0,255,-127,127);
y=map(data[1],0,255,-127,127);
z=map(data[2],0,255,-127,127);
x2=map(data[3],0,255,-127,127);
y2=map(data[4],0,255,-127,127);
z2=map(data[5],0,255,-127,127);
x3=map(data[6],0,255,-127,127);
y3=map(data[7],0,255,-127,127);
z3=map(data[8],0,255,-127,127);
Serial.print(x);
Serial.print(“,”);
Serial.print(y);
Serial.print(“,”);
Serial.print(z);
Serial.print(“,”);
Serial.print(x2);
Serial.print(“,”);
Serial.print(y2);
Serial.print(“,”);
Serial.print(z2);
Serial.print(“,”);
Serial.print(x3);
Serial.print(“,”);
Serial.print(y3);
Serial.print(“,”);
Serial.println(z3);

//delay(1000);
}

#define CAYENNE_PRINT Serial

#include &lt;Wire.h&gt;

#include &lt;CayenneMQTTESP8266.h&gt;

// WiFi network info.

char ssid[] = “xxxxxxx”;

char wifiPassword[] = “xxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.

char username[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

char password[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

char clientID[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

unsigned long lastMillis = 0;

int data[]={0,0,0,0,0,0,0,0,0};

int x,y,z,x2,y2,z2,x3,y3,z3;

void setup(void) {

Cayenne.begin(username, password, clientID, ssid, wifiPassword);

Serial.begin(115200); /* begin serial for debug /

Wire.begin(D1, D2); / join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */

}

void loop(void) {

Cayenne.loop();

Wire.requestFrom(8, 15); /* request & read data of size 13 from slave */

int i=0;

while(Wire.available()){

int c = Wire.read();

data[i]=c;

i++;

}

x=map(data[0],0,255,-127,127);

y=map(data[1],0,255,-127,127);

z=map(data[2],0,255,-127,127);

x2=map(data[3],0,255,-127,127);

y2=map(data[4],0,255,-127,127);

z2=map(data[5],0,255,-127,127);

x3=map(data[6],0,255,-127,127);

y3=map(data[7],0,255,-127,127);

z3=map(data[8],0,255,-127,127);

Serial.print(x);

Serial.print(",");

Serial.print(y);

Serial.print(",");

Serial.print(z);

Serial.print(",");

Serial.print(x2);

Serial.print(",");

Serial.print(y2);

Serial.print(",");

Serial.print(z2);

Serial.print(",");

Serial.print(x3);

Serial.print(",");

Serial.print(y3);

Serial.print(",");

Serial.println(z3);

}
if (millis() - lastMillis  > 10000) {

lastMillis = millis();
 Cayenne.virtualWrite(1, x);
Cayenne.virtualWrite(2, y);
Cayenne.virtualWrite(3, z);
Cayenne.virtualWrite(4, x2);
Cayenne.virtualWrite(5, y2);
Cayenne.virtualWrite(6, z2);
Cayenne.virtualWrite(7, x3);
Cayenne.virtualWrite(8, y3);
  Cayenne.virtualWrite(9, z3);
    }

}

i seriously thank you a lot for your valuable reply.

I tried with the code given and i found that there is no error with the code which u gave and which i have posted. I found the problem that when i remove data jumpers from ESP8266, values will update to cloud (all values are zeros), but when i reconnect the jumper wire which receives data from sensors, it is giving as ‘wdt reset’.

I googled it but didnt work.
I want your help
Thank you

How about the following library example??.. how can i use this in my code;

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneESP8266WiFi.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “AuthenticationToken”;
// Your network name and password.
char ssid = “NetworkSSID”;
char password = “NetworkPassword”;

void setup()
{
Serial.begin(9600);
Cayenne.begin(token, ssid, password);
}

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

You need to add some sleeps to your code. You should always have some delay in loops to reset the watchdog timer (unless you really do wan’t it to reset) Try this:

#define CAYENNE_PRINT Serial
#include <Wire.h>
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = “xxxxxxx”;
char wifiPassword[] = “xxxxxx”;

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

unsigned long lastMillis = 0;

int data[]={0,0,0,0,0,0,0,0,0};

int x,y,z,x2,y2,z2,x3,y3,z3;

void setup(void) {
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);

	Serial.begin(115200); /* begin serial for debug /

	Wire.begin(D1, D2); / join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
	//!!!!!!!!^^^is this supposed to be commented out?!!!!!!!!!!!!!!!

}

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

	Wire.requestFrom(8, 15); /* request & read data of size 13 from slave */

	int i=0;

	while(Wire.available()){
		int c = Wire.read();
		data[i]=c;
		i++;
		delay(10);
	}
	
	x=map(data[0],0,255,-127,127);
	y=map(data[1],0,255,-127,127);
	z=map(data[2],0,255,-127,127);
	x2=map(data[3],0,255,-127,127);
	y2=map(data[4],0,255,-127,127);
	z2=map(data[5],0,255,-127,127);
	x3=map(data[6],0,255,-127,127);
	y3=map(data[7],0,255,-127,127);
	z3=map(data[8],0,255,-127,127);
	Serial.print(x);
	Serial.print(",");
	Serial.print(y);
	Serial.print(",");
	Serial.print(z);
	Serial.print(",");
	Serial.print(x2);
	Serial.print(",");
	Serial.print(y2);
	Serial.print(",");
	Serial.print(z2);
	Serial.print(",");
	Serial.print(x3);
	Serial.print(",");
	Serial.print(y3);
	Serial.print(",");
	Serial.println(z3);

	if (millis() - lastMillis  > 10000) {
		lastMillis = millis();
		Cayenne.virtualWrite(1, x);
		Cayenne.virtualWrite(2, y);
		Cayenne.virtualWrite(3, z);
		Cayenne.virtualWrite(4, x2);
		Cayenne.virtualWrite(5, y2);
		Cayenne.virtualWrite(6, z2);
		Cayenne.virtualWrite(7, x3);
		Cayenne.virtualWrite(8, y3);
		Cayenne.virtualWrite(9, z3);
	}

}
1 Like