Lavanya rajan
Well-known member
I'm attempting to upload two arrays of float values to a MySQL database table using Teensy 4.0 and ESP8266. Each array consists of 512 elements with precision up to two digits. However, upon uploading the code, I encounter the following error. Could anyone provide assistance in resolving this issue?
Attaching the code
Error I'm getting
AT+CIPSEND=7047
too long
ERROR
Failed: AT+CIPSEND=7047
Attaching the code
Code:
#include <ArduinoJson.h>
String SSID = "xxxx";
String PASSWORD = "xxxx";
String HOST_NAME = "xxxx";
void sendCommand(String command, unsigned long timeout);
bool recFind(String target, uint32_t timeout, bool prntln);
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
delay(2000);
flushSerial();
delay(200);
Serial.println(F("Started"));
// Check communications with the ESP8266
sendCommand("AT+GMR", 5000);
sendCommand("AT", 5000);
sendCommand("AT+CWMODE?", 5000);
sendCommand("AT+CWMODE=1", 5000);
// Join WiFi
String joinstring = "AT+CWJAP=\"" + SSID + "\",\"" + PASSWORD + "\"";
sendCommand(joinstring, 7000);
// Get IP Address
sendCommand("AT+CIFSR", 7000);
}
void loop() {
StaticJsonDocument<8192> doc;
JsonArray xvalues = doc.createNestedArray("x");
JsonArray yvalues = doc.createNestedArray("y");
// Populate arrays with float values
for (int i = 0; i < 512; i++) {
xvalues.add(round_range(i * 1.23)); // Add some arbitrary value as x values
yvalues.add(round_range(i * 2.34)); // Add some arbitrary value as y values
}
// Serialize JSON document
String jsonPayload;
serializeJson(doc, jsonPayload);
// Send HTTP request
sendCommand("AT+CIPSTART=\"TCP\",\"" + HOST_NAME + "\",80", 10000);
String data = "POST /xxx/xxx.php HTTP/1.1\r\n";
data += "Host: " + HOST_NAME + "\r\n";
data += "Content-Type: application/json\r\n";
data += "Content-Length: " + String(jsonPayload.length()) + "\r\n\r\n";
data += jsonPayload;
// Send the HTTP request
String sendRequest = "AT+CIPSEND=" + String(data.length());
sendCommand(sendRequest, 5000);
sendCommand(data, 5000);
delay(100); // Small delay between sending each array element
// Wait for response from server
if (recFind("CLOSED", 5000, true)) {
Serial.println("CLOSED");
} else {
Serial.println("No response from server");
}
}
void sendCommand(String command, unsigned long timeout) {
Serial1.println(command);
if (recFind("OK", timeout, true)) {
Serial.println("Success: " + command);
} else {
Serial.println("Failed: " + command);
}
}
void flushSerial() {
while (Serial1.available() > 0) {
Serial1.read();
}
}
bool recFind(String target, uint32_t timeout, bool prntln) {
String rdBuff = "";
unsigned long startMillis = millis();
while (millis() - startMillis < timeout) {
while (Serial1.available() > 0) {
char rdChar = Serial1.read();
rdBuff += rdChar;
if (prntln) {
Serial.write(rdChar);
}
if (rdBuff.indexOf(target) != -1) {
return true;
}
}
}
return false;
}
double round_range(double value) {
return (int)(value * 100 + 0.5) / 100.0;
}
Error I'm getting
AT+CIPSEND=7047
too long
ERROR
Failed: AT+CIPSEND=7047