RobotDyn Serial data receive issue

hello everyone

I am using a board called Robotdyn uno wifi .

i am using ESP8266 to read two json data from two diferent url and then m printing this on the Serial monitor.

i am able to read the json data and sent it on serial monitor successfully.

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(115200);
    for(uint8_t t = 4; t > 0; t--) 
    {
        delay(1000);
    }

  WiFi.begin("DIGISOL","edot2018");
 
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
  }

}

void loop() 
{ 
    HTTPClient http,http2;

    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(500);
        USE_SERIAL.println(description2); 
    } 
    else 
    {
        USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
    delay(10000);
}

Then using atmega 832p i am reading this data sent by the ESP8266 through serial monitor and then displaying it on to the display.

the data is not receiving correctly from the serial monitor, some of the character from the String are missing or interchanged.

atmega code

#include "font8x8_basic.h"
#include "font8x8_extended.h"
#include "font8x16_basic.h"

#include <Time.h> 
#include <Wire.h> 

#define SERIAL Serial
#define COLUMNS 16
#define HEIGHT 16

String message4,message5;
int m2Size,m5Size,len = 0,cycled = 0;
int count = 0;



void setup() 
{
   SERIAL.begin(115200);
   delay(1000);
   sei();//allow interrupts
}

void loop() 
{
  if(SERIAL.available() > 0) 
   {
    ATSTART();
    draw();
   }
   else if (cycled == 1)
   {
    count=0;
    draw();
   }
   else
   {
    ATSTART();
    draw();
   }
   //cli();
   delay(1000);   
}
void ATSTART()
{
    while(SERIAL.available() == 0){}
    message4 = SERIAL.readString();
    Serial.read();
    m2Size = message4.length();
    m2Size = m2Size - 2 ;
    while(SERIAL.available() == 0){}
    message5 = SERIAL.readString();
    Serial.read();
    m5Size = message5.length();
    m5Size = m5Size - 2 ;
    //Serial.println(m2Size);
    //Serial.println(message4);
    if(m2Size >= m5Size)
    {
      len = m2Size;
    }
    else
    {
      len = m5Size;
    }
}

void draw()
{
    drawChar(0,0,'A',0,false);
    drawChar(8,0,'R',0,false);
    drawChar(16,0,'R',0,false);
    drawChar(0,9,'D',0,false);
    drawChar(8,9,'E',0,false);
    drawChar(16,9,'P',0,false);
    while(count <= len)
    {
      if(count <= m2Size)
      {
        drawChar(120,1,message4[count],0,false);
      }
      if(count <= m5Size)
      {
        drawChar(120,8,message5[count],0,false);
      }
    count = count + 1;
      for (byte i=0; i<8; i++) 
          {
            delay(100);
            moveLeft(1,0,15);
          };
    }
    cycled = 1;
}

can anyone plz help me with this.
Since this board is new there is no proper explanation on how this stuff works.
i anyhow reached so far with my project using this board.

it is very simple. 3 devices (USB, Atmega, esp8266) and 3 pairs of switches. the switches connect TX/RX of pair of devices. if you turn on more switches you create a disturbance on the serial lines

if you turn on more switches you create a disturbance on the serial lines

but i have turned on only 2 switches 1&2 so that atmega communicate with esp8266, then y m i getting the disturbance.

ok. in your post you write Serial Monitor, but you mean Serial interface. Serial Monitor is a window in IDE.

your code for reading the data looses the characters. read about Serial input basics

OK thanks for the link.

i was reading it from the monitor as a string so now ill use that method thank you.

just one more help

as i can send the data from esp to atmega , can i send the data from atmega to esp at the same time.

like whenever atmega says i want more data then only esp will send it the data through serial monitor..

thank you

codworks:
as i can send the data from esp to atmega , can i send the data from atmega to esp at the same time.

like whenever atmega says i want more data then only esp will send it the data through serial monitor..

with switches 1 and 2, Atmega and esp are connected RX-TX, TX-RX. what is written to TX can be read on RX

hey juraj

see this piece of code to retrieve data from the serial monitor.

String message4,message5;
int m2Size=0,m5Size=0;


while(SERIAL.available() == 0){}
    message4 = SERIAL.readString();
    m2Size = message4.length();
    m2Size = m2Size - 2 ;
    while(SERIAL.available() == 0){}
    message5 = SERIAL.readString();
    m5Size = message5.length();
    m5Size = m5Size - 2 ;
    if(m2Size >= m5Size)
    {
      len = m2Size;
    }
    else
    {
      len = m5Size;
    }

this should work right??

your code for reading the data looses the characters. read about Serial input basics

i tried with this link but in this i need to give the size of the char array but in my case size may varry.

for example

Description "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 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 6E 281 BLR 20:00 SCH SG 145 DEL 20:00 SCH AI 975 KWI 20:25 SCH 6E 336 DEL 22:00 SCH I5* 1329 BLR 22:35 SCH 6E 259 HYD 22:50 SCH AI 84 BOM 22:50 SCH "

hey juraj

is it correct what i am doing?

ESP8266 code

#define serial Serial

void setup() {
  serial.begin(9600);
  delay(500);
  pinMode(12, OUTPUT);    
  digitalWrite(12,LOW);
}

// the loop function runs over and over again forever
void loop() {
  if (serial.available())
  {
  serial.println("Enter 1 or 0 to see led change");
  while(serial.available() == 0){}
  int cmd = serial.parseInt();
  if(cmd == 1)
  {
    digitalWrite(12, HIGH);   
  }                                 
  else if (cmd == 0 )
  {
   digitalWrite(12, LOW);                                        
  }
  delay(2000);  
  }
  
}

ATMEGA code

int data = 0;
void setup()
{
  Serial.begin(9600);
  delay(500);
}
void loop()
{
  while(Serial.available() == 0 ){}
  String item = Serial.readString();
  data = 1;
  Serial.println(data);
  delay(2000);
  while(Serial.available () == 0){}
  item = Serial.readString();
  data = 0;
  Serial.println(data);
  delay(2000);
}

only one help for last time

thank you

no. you cant wait for input like that (while available) in esp8266. if the code doesn't come out of loop in some seconds then the watchdog resets the board (cause 4). google esp8266 watchdog

oh

i read that post so only change i need to do is in that while(Serial.available() == 0) loop i need to feed the watch dog so that it can reset the watchdog right.

if i remove the while loop will it work??

sorry, I help you with board an esp8266 specific problems, but not with basic coding

Serial Input Basics

hey guys

i am trying since a week but still not able to get the solution for this

as i can send the data from esp to atmega , can i send the data from atmega to esp at the same time.

like whenever atmega says i want more data then only esp will send it the data through serial monitor..

plz help

thank you