JSON to OLED, two data points laid on top of each other, won't separate

So ive been working on an international space station longitude and latitude tracker…im using a JSON from online (api.open-notify.org ) , a node mcu 12e esp 8266 and a little 128 x 64 OLED…I have everything set up, two sections of the display show longitude and latitude, but for some reason I can’t split the longitude from the latitude on my OLED. It does so fine on my serial monitor…but on the OLED, longitude and latitude are both displayed in both sections, one on top of the other…overlaid so that they’re illegible.

I know its not the position of the text/cursor because when I move it around the problem persists.

I can’t seem to find the solution becuase in my code, there isn’t a separation, the long&lat just magically show up after their respective “id’s” in the serial monitor

Here’s my code:

#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <Adafruit_GrayOLED.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <SPI.h>
#include <Wire.h>

#define SCREEN_WIDTH 128 
#define SCREEN_HEIGHT 64 

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#include "USE_ESP8266.h"
#include <TimeLib.h>
char server [] = "api.open-notify.org";
void digitalClockDisplay();

void setup ()
{
display.begin(SSD1306_SWITCHCAPVCC, 0X3C);
display.clearDisplay ();

  Serial.begin(115200);
  if (!configureNetwork()) //start the network
  {
    Serial.println("Failed to configure the network");
    while(1)
    {
      delay(0); //halt; ESP8266 does not like infinity loop without a delay
    }
   }
int ret = client.connect(server, 80);
if (ret == 1)
{
  Serial.println("Connected");
  client.println("GET /iss-now.json HTTP/1.0"); //the http request
  client.print("Host: "); client.println(server);
  client.println("Connection: close");
  client.println();
}
else
{
  Serial.println("Connection failed, error was: ");
  Serial.print(ret, DEC);
  while(1)
  {
    delay(0); //halt; esp8266 does not like infinite loop without a delay
  }
 }
}

char timestampMarker[] = "\"timestamp\":";
char posMarker[] = "\"iss_position\":";

void loop ()
{
  if (client.available())
  {
    String id = client.readStringUntil('"');
    if (id.equals("timestamp")) //start of timestamp
    {
      if (client.find(':')) //a ":" follows each identifier
      {
      unsigned long timestamp = client.parseInt();
      setTime(timestamp);
      digitalClockDisplay();
      
      }
      else
      {
        Serial.println("failed to parse timestamp.");
      }
    }
    if (id.equals("iss_position")) //start of position data
    {
      if (client.find(':'))  
      {
       while(client.peek () != '}' && client.find('"'))
       {
        String id = client.readStringUntil ('"');
        float val = client.parseFloat ();
        client.find ('"');
        Serial.print(id + ":"); Serial.println(val, 4); 

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println("longitude:"); 
display.display();

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,30); 
display.println(val);
display.display();

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,40);
display.println("latitude:"); 
display.display(); 
 
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,50); 
display.println(val, 4);
display.display();

       }
      }
      else
      {
        Serial.print("Failed to parse position data.");
      }
    }
  }
if (!client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while(1)
  {
    delay (0); //halt, esp8266 does not like loop w/o delay
  }
 }
}
String padDigits(int digit)
{
  String str = String("0") + digit; //put a zero in front of digit
  return str.substring(str.length() - 2);
}

void digitalClockDisplay () 
{
  String datestr = String(year()) + "-" + padDigits(month()) +
                   "-" + padDigits(day());
  String timestr = String(hour()) + ":" + padDigits(minute()) +
                   ":" + padDigits(second());
  Serial.println(datestr + " " + timestr);
}

ANY HELP IS APPRECIATED!!!

You are not separating the parsing of the longitude and latitude. You locate "iss_position and then you just blindly read and parse a float and write it to your longitude and latitude location. You then repeat and pick up of latitude value and write it to both locations as well. Rather than looking for “iss_possition”, look for “latitude” and put that where you want it. Duplicate the code, but look for “longitude” and put that where you want it.

Basically, parse 3 pieces of data “timestamp”, “longitude” and “latitude”

#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <Adafruit_GrayOLED.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <SPI.h>
#include <Wire.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#include "USE_ESP8266.h"
#include <TimeLib.h>
char server [] = "api.open-notify.org";
void digitalClockDisplay();

float longitude, latitude;

void setup ()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0X3C);
  display.clearDisplay ();

  Serial.begin(115200);
  if (!configureNetwork()) //start the network
  {
    Serial.println("Failed to configure the network");
    while (1)
    {
      delay(0); //halt; ESP8266 does not like infinity loop without a delay
    }
  }
  int ret = client.connect(server, 80);
  if (ret == 1)
  {
    Serial.println("Connected");
    client.println("GET /iss-now.json HTTP/1.0"); //the http request
    client.print("Host: "); client.println(server);
    client.println("Connection: close");
    client.println();
  }
  else
  {
    Serial.println("Connection failed, error was: ");
    Serial.print(ret, DEC);
    while (1)
    {
      delay(0); //halt; esp8266 does not like infinite loop without a delay
    }
  }
}

char timestampMarker[] = "\"timestamp\":";
char posMarker[] = "\"iss_position\":";

void loop ()
{
  if (client.available())
  {
    String id = client.readStringUntil('"');
    if (id.equals("timestamp")) //start of timestamp
    {
      if (client.find(':')) //a ":" follows each identifier
      {
        unsigned long timestamp = client.parseInt();
        setTime(timestamp);
        digitalClockDisplay();

      }
      else
      {
        Serial.println("failed to parse timestamp.");
      }
    }
    else if (id.equals("longitude")) //start of position data
    {
      if (client.find(':'))
      {
        longitude = client.parseFloat ();
        Serial.print(id + ":"); Serial.println(longitude, 4);

        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0, 20);
        display.println("longitude:");
        display.display();

        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0, 30);
        display.println(val);
        display.display();
      }
      else
      {
        Serial.print("Failed to parse longitude data.");
      }
    }
    else if (id.equals("latitude")) //start of position data
    {
      if (client.find(':'))
      {
        latitude = client.parseFloat();
        Serial.print(id + ":"); Serial.println(latitude, 4);

        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0, 40);
        display.println("latitude:");
        display.display();

        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0, 50);
        display.println(val, 4);
        display.display();

      }
      else
      {
        Serial.print("Failed to parse latitude data.");
      }
    }
  }
  if (!client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while (1)
    {
      delay (0); //halt, esp8266 does not like loop w/o delay
    }
  }
}
String padDigits(int digit)
{
  String str = String("0") + digit; //put a zero in front of digit
  return str.substring(str.length() - 2);
}

void digitalClockDisplay ()
{
  String datestr = String(year()) + "-" + padDigits(month()) +
                   "-" + padDigits(day());
  String timestr = String(hour()) + ":" + padDigits(minute()) +
                   ":" + padDigits(second());
  Serial.println(datestr + " " + timestr);
}

im working on it, getting some syntactical errors now (in completely different parts of the code :face_with_raised_eyebrow:).

need to stop for now, but I will resume working on it tomorrow afternoon/evening. thanks for the help

I think this will separate the two, assuming the labels are “latitude” and “longitude”:

    if (id.equals("iss_position")) //start of position data
    {
      if (client.find(':'))
      {
        while (client.peek () != '}' && client.find('"'))
        {
          String id = client.readStringUntil ('"');
          float val = client.parseFloat ();
          client.find ('"');
          Serial.print(id + ":"); Serial.println(val, 4);

          if (id == "longitude")
          {
            display.setTextSize(1);
            display.setTextColor(WHITE);
            display.setCursor(0, 20);
            display.println("longitude:");
            display.setCursor(0, 30);
            display.println(val);
            display.display();
          }

          if (id == "latitude")
          {
            display.setTextSize(1);
            display.setTextColor(WHITE);
            display.setCursor(0, 40);
            display.println("latitude:");
            display.setCursor(0, 50);
            display.println(val, 4);
            display.display();
          }
        }
      }
      else
      {
        Serial.print("Failed to parse position data.");
      }
    }