I'm getting low memory error. Please help me to optimize my code. Here is my code:
namespace {
const char * USER_AGENT = "UbidotsESP8266"; // Assgin the user agent
const char * VERSION = "1.0"; // Assign the version
const char * METHOD = "POST"; // Set the method
const char * TOKEN = "assign_your_ubidots_token"; // Assign your Ubidots TOKEN
const char * DEVICE_NAME = "telemetry"; // Assign the desire device name
const char * DEVICE_LABEL = "ESP8266"; // Assign the device label
const char * VARIABLE_LABEL_1 = "temperature"; // Assign the variable label
const char * VARIABLE_LABEL_2 = "heartrate"; // Assign the variable label
const char * VARIABLE_LABEL_3 = "bloodpressure"; // Assign the variable label
}
char first_command[700]; // command
char second_command[700];
char telemetry_unit[100]; // response of the telemetry unit
/* Space to store values to send */
char str_sensor1[10];
char str_sensor2[10];
char str_sensor3[10];
/****************************************
* Main Functions
****************************************/
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
/* Analog reading */
float sensor1 = analogRead(A0);
float sensor2 = analogRead(A1);
float sensor3 = analogRead(A2);
/* 4 is mininum width, 2 is precision; float value is copied onto str_sensor*/
dtostrf(sensor1, 4, 2, str_sensor1);
dtostrf(sensor2, 4, 2, str_sensor2);
dtostrf(sensor3, 4, 2, str_sensor3);
/* Building first the logger command */
sprintf(first_command, "init#");
sprintf(first_command, "%s%s/%s|%s|%s|", first_command, USER_AGENT, VERSION, METHOD, TOKEN);
sprintf(first_command, "%s%s:%s=>", first_command, DEVICE_NAME, DEVICE_LABEL);
sprintf(first_command, "%s%s:%s", first_command, VARIABLE_LABEL_1, str_sensor1);
sprintf(first_command, "%s,%s:%s", first_command, VARIABLE_LABEL_2, str_sensor2); // uncomment this line to send sensor 2 values
sprintf(first_command, "%s|end#final", first_command);
/* Prints the command sent */
//Serial.println(first_command);// uncomment this line to print the command
/* Sends the command to the telemetry unit */
Serial1.print(first_command);
/* Reading the telemetry unit */
int i = 0;
while (Serial1.available() > 0) {
telemetry_unit[i++] = (char)Serial1.read();
}
Serial.println(telemetry_unit);
i = 0;
delay(1000);
/* Building the second logger command */
sprintf(second_command, "init#");
sprintf(second_command, "%s%s/%s|%s|%s|", second_command, USER_AGENT, VERSION, METHOD, TOKEN);
sprintf(second_command, "%s%s:%s=>", second_command, DEVICE_NAME, DEVICE_LABEL);
sprintf(second_command, "%s%s:%s", second_command, VARIABLE_LABEL_3, str_sensor3);
sprintf(second_command, "%s|end#final", second_command);
/* Prints the command sent */
//Serial.println(second_command);// uncomment this line to print the command
/* Sends the command to the telemetry unit */
Serial1.print(second_command);
/* Reading the telemetry unit */
while (Serial1.available() > 0) {
telemetry_unit[i++] = (char)Serial1.read();
}
Serial.println(telemetry_unit);
i = 0;
delay(5000);
}
Please help me to optimize it is just testing code i have other variables too that i haven't used in this sketch (like lm35 code, heart rate code and their variables) please help me out