ADXL345 with ESP8266 using ThingSpeak error problem

Hello,
I am trying run the adxl345 with esp8266 using thingspeak cloud. but i got error that "Error compiling for board Arduino Uno" & " ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]".

please help !

Here is the code

#include <SoftwareSerial.h>
#include <Wire.h>
//#include <Wire.h>
#define RX 2
#define TX 3
int getSensorData();
int ADXL345 = 0x53;
int X_out, Y_out, Z_out;
int countTrueCommand;
int countTimeCommand; 
boolean found = false; 
int valSensor = 1;
int sendCommand();
String AP = "High Voltage Lab";       // AP NAME
String PASS = "profnkroy"; // AP PASSWORD
String API = "ERK34DSVQ9XJGLO2";   // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
String field1 = "field1";
String field2 = "field2";
String field3 ="field3";
//int X_OUT,Y_OUT,Z_OUT;
SoftwareSerial esp8266(RX,TX); 
 
  
void setup() {
  Serial.begin(9600);
  esp8266.begin(115200);
  Wire.begin();
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
  Serial.begin(9600);
  Serial.println("date&time,x_out,y_out,z_out");
  Wire.beginTransmission(ADXL345);
  Wire.write(0x2D); //talk to POWER_CTL Register - 0x2D
  Wire.write(8); // Bit D3 High for measuring enable (8dec -> 0000 1000 binary)
  Wire.endTransmission();
  delay(10);
}

void loop()  {
valSensor = getSensorData();
String getData = "GET /update?api_key="+ API +"&field1="+valSensor+"&field2="+valSensor+"&field3="+valSensor;// field +"="+String(valSensor);//CHANGE
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
Wire.beginTransmission(ADXL345);
Wire.write(0x32);
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true);

  X_out = ( Wire.read() | Wire.read() << 8);
  Y_out = ( Wire.read() | Wire.read() << 8);
  Z_out = ( Wire.read() | Wire.read() << 8);
  

  Serial.print(",");
  Serial.print(X_out);
  Serial.print(",");
  Serial.print(Y_out);
  Serial.print(",");
  Serial.println(Z_out);
  delay(0.00000001);
}
 // return random(1000); // Replace with your own sensor code
 

void sendCommand(String command, int maxTime, char readReplay[]) {
  Serial.print(countTrueCommand);
  Serial.print(". at command => ");
  Serial.print(command);
  Serial.print(" ");
  while(countTimeCommand < (maxTime*1))
  {
    esp8266.println(command);//at+cipsend
    if(esp8266.find(readReplay))//ok
    {
      found = true;
      break;
    }
  
    countTimeCommand++;
  }
  
  if(found == true)
  {
    Serial.println("OYI");
    countTrueCommand++;
    countTimeCommand = 0;
  }
  
  if(found == false)
  {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }
  
  found = false;
 }

here is error message:

C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino: In function 'void setup()':
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:30:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   sendCommand("AT",5,"OK");
                          ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:31:35: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   sendCommand("AT+CWMODE=1",5,"OK");
                                   ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:32:61: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
                                                             ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino: In function 'void loop()':
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:45:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 sendCommand("AT+CIPMUX=1",5,"OK");
                                 ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:46:66: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
                                                                  ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:47:62: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
                                                              ^
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL\Revised_ESP_ADXL.ino:49:35: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 sendCommand("AT+CIPCLOSE=0",5,"OK");
                                   ^
C:\Users\DELL\AppData\Local\Temp\ccGq0fs3.ltrans0.ltrans.o: In function `loop':
C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL/Revised_ESP_ADXL.ino:43: undefined reference to `getSensorData()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.

C:\Users\DELL\Documents\program@ard\Revised_ESP_ADXL/Revised_ESP_ADXL.ino:43: undefined reference to `getSensorData()

You do not have a definition for the getSensorData() function in your sketch

I am new to arduino programming . please help what should modified or added to my sketch .
thank you!

Your sketch needs a getSensorData() function to be defined

There is a very odd comment in the sketch

// return random(1000); // Replace with your own sensor code

Where did you get the sketch ?

from one of the site in google . i got basic structure of sketch them i modified it . and i got lot of error ,many error i resolved . but i stuck in this error from past 2 days.

Did the original sketch have the function in it ?

yes .
basically i merge two individual program adxl345 and esp8266 . both program run individually . but when merged both then error occurred .
if possible ,please help

Copy the function from the original to your sketch but I have no great hope that the combined sketch will work as you want even if it compiles

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.