hello everyone
i am working on a project where i need to fetch the data from a api using the esp8266 and send this to arduino to display it to the 128*16 display.
i am able to fetch the data from the api using the esp8266 successfully, this fetched data m printing on the serial monitor.
this data from serial monitor is read by atmega to display on the display. the problem is m not able to get a complete data from serial monitor only a part of data is recievd.
//ESP8266 code
/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
int i=0;
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
void setup()
{
USE_SERIAL.begin(9600);
//USE_SERIAL.setDebugOutput(true);
//USE_SERIAL.println();
//USE_SERIAL.println();
//USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--)
{
//USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFi.begin("DIGISOL","edot2018");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
//Serial.print(".");
}
//Serial.println("");
//Serial.println("WiFi connected");
//Serial.println("IP address: ");
//Serial.println(WiFi.localIP());
}
void loop()
{
// wait for WiFi connection
// if((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http,http2;
//USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("http://192.168.1.12/FlightStats/api/Flight/GetArrivingFlightsStatus/"); //HTTP
http2.begin("http://192.168.1.12/FlightStats/api/Flight/GetDepartingFlightsStatus/");
//start connection and send HTTP header
int httpCode = http.GET();
int httpCode2 = http2.GET();
// httpCode will be negative on error
if(httpCode == 200 )
{
// HTTP header has been send and Server response header has been handled
//USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
//USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode2);
String myString = http.getString();
String myString2 = http2.getString();
JsonObject& root = jsonBuffer.parseObject(myString);
const char* description = root["Description"];
JsonObject& root1 = jsonBuffer.parseObject(myString2);
const char* description2 = root1["Description"];
USE_SERIAL.println(description);
delay(200);
USE_SERIAL.println(description2);
delay(200);
}
else
{
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
delay(10000);
}
esp prints this output on serial monitor
6E 714 BLR 16:30 SCH I5* 799 DEL 16:35 SCH I5* 1321 BLR 17:00 SCH SG 924 AMD 17:00 SCH 9W 2385 BOM 17:05 SCH SG 3106 MAA 17:05 SCH 6E 418 BOM 17:10 SCH G8 285 DEL 17:30 SCH 6E 468 BOM 17:35 SCH SG 487 BOM 17:35 SCH 6E 724 DEL 17:50 SCH I5* 1518 HYD 17:55 SCH SG 2790 STV 18:05 SCH G8 372 BOM 18:15 SCH 9W 621 BOM 18:35 SCH AI 662 BOM 18:45 SCH 6E 6386 DEL 18:50 SCH I5* 1335 BLR 19:10 SCH SG 2892 MAA 19:15 SCH SG 145 DEL 20:00 SCH 6E 281 BLR 20:00 SCH WY 208 MCT 20:20 SCH AI 975 KWI 20:25 SCH
code for atmega
boolean newData = false;
char message[500];
char message2[500];
char rc;
int yes=0;
static byte ndx = 0;
char endMarker = '\n';
int done=0;
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
//Serial.println("arduino ready");
drawChar(0,1,'A',0,false);
drawChar(8,1,'R',0,false);
drawChar(16,1,'R',0,false);
drawChar(0,9,'D',0,false);
drawChar(8,9,'E',0,false);
drawChar(16,9,'P',0,false);
if(yes == 0)
{
recvWithEndMarker();
showNewData();
}
if (yes == 1)
{
recvWithEndMarkerr();
showNewDataa();
}
draw();
}
void draw()
{
const char *next = message;
const char *next2 = message2;
while(*next && *next2) {
if(*next != endMarker){
drawChar(120,1,*next,0,false);
next++;
}
if(*next2 != endMarker){
drawChar(120,9,*next2,0,false);
next2++;
}
for (byte i=0; i<7; i++) {
delay(100);
moveLeft(1,0,15);
};
}
}
void recvWithEndMarker() {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
message[ndx] = rc;
ndx++;
}
else {
message[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
yes = 1;
}
}
}
void showNewData() {
if (newData == true) {
newData = false;
}
}
void recvWithEndMarkerr() {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
message2[ndx] = rc;
ndx++;
}
else {
message2[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
done=1;
}
}
void showNewDataa() {
if (newData == true) {
newData = false;
yes = 0;
}
}
help plz
i think the problem is with the serial read