Hi,
What i try to accomplish:
I have an Arduino Mega with a CTE TFT shield connected to a SSD1963 (CTE70)
Display. Also connected to this Arduino is my ESP8266 programmed with AT firmware.
I try to fetch over the ESP8266 an image what i have on my webserver send this over
serial to my Mega and display it on my display.
What i have at the moment is that it is connecting to my webserver and is fetching the image but
what i receive are pieces of the Image containing multiple times SEND OK, then some data etc.
Perhaps somebody can point me in the right direction what i am doing wrong or if it is even possible what
i try to do.
#include <ArduinoJson.h>
#include <UTFT.h>
#include <Time.h>
#include <Timer.h>
#include <tinyFAT.h>
//#include <UTFT_tinyFAT.h>
#include "OneWire.h"
#include "DallasTemperature.h"
#include <UTFT_SdRaw.h>
#include <SdFat.h>
#define SD_CHIP_SELECT 53 // SD chip select pin
const int buffer=400;//JSON Buffer size
// file system object
SdFat sd;
SdFile myFile;
#define LOCATIONID "AT/Salzburg" // location id
#define ONE_WIRE_BUS 16
// WLAN
#define SSID "WLAN" // insert your SSID
#define PASS "PASS" // insert your password
// Camera
#define DST_IP "192.168.20.200"
//Display
UTFT myGLCD(CTE70, 38, 39, 40, 41);
UTFT_SdRaw myFiles(&myGLCD);
char fileName[] = "2468.txt";
byte response;
byte incomingbyte;
boolean EndFlag=0;
int j=0, k=0, count=0;
//Check Module and connect to WLAN
void espLogin()
{
Serial1.println("AT+RST"); // reset and test if module is redy
delay(5000);
if (Serial1.find("OK")) {
Serial.println("WiFi - Module is ready");
} else {
Serial.println("Module doesn't respond.");
delay(1000);
espLogin();
}
delay(2000);
// try to connect to wifi
boolean connected = false;
for (int i = 0; i < 5; i++) {
if (connectWiFi()) {
connected = true;
Serial.println("Connected to WiFi...");
delay(2000);
getimage();
}
}
if (!connected) {
Serial.println("Coudn't connect to WiFi.");
delay(6000);
espLogin();
}
delay(5000);
}
boolean connectWiFi()
{
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
Serial.println(cmd);
Serial1.println(cmd);
delay(2000);
if (Serial1.find("OK")) {
Serial.println("OK, Connected to WiFi.");
return true;
} else {
Serial.println("Can not connect to the WiFi.");
delay(5000);
return false;
}
getimage();
}
void getimage()
{
myFile.open(fileName, O_RDWR | O_CREAT | O_AT_END);
String out = "";
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
Serial1.println(cmd);
Serial.println(cmd);
if(Serial1.find("ERROR")) return;
cmd = "GET /test.jpg";
cmd += " HTTP/1.1\r\nHost: 192.168.20.200\r\n\r\n";
Serial1.print("AT+CIPSEND=");
Serial1.println(cmd.length());
Serial.println(cmd.length());
if(Serial1.find(">")){
Serial.println(">");
}else{
Serial1.println(F("AT+CIPCLOSE"));
Serial.println("Connection get Forecast timeout");
delay(1000);
getimage();
}
Serial1.print(cmd);
Serial.print(cmd);
delay(1000);
while(Serial1.available()>0) {
incomingbyte=Serial1.read();
out += (char)incomingbyte;
//Serial.print(out);
myFile.print((char)incomingbyte);
}
myFile.close();
delay(3000);
myGLCD.print("out",100,150,150);
// Done with processing for now - close connection
Serial1.println("AT+CIPCLOSE");
}
void parseJSON(char json[400])
{
Serial.println(json);
StaticJsonBuffer<buffer> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success())
{
Serial.print("?fparseObject() failed");
return;
}
}
void setup()
{
Serial.println(F("Initialising SD card..."));
bool mysd = 0;
// see if the card is present and can be initialized:
while (!mysd)
{
if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
Serial.println(F("Card failed, or not present"));
Serial.println(F("Retrying...."));
}
else
{
mysd = 1;
Serial.println(F("Card initialised."));
}
}
Serial1.begin(115200);
Serial.begin(115200); // Debug
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setColor(0,255,0);
espLogin();
getimage(),
delay(10000);
}
void loop()
{
}