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