'cfrom' not declared in this scope



whoever can finish this  job ill buy coffee for them.
/**The MIT License (MIT)

Copyright (c) 2018 by Daniel Eichhorn - ThingPulse

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

See more at https://thingpulse.com
*/

#include <Arduino.h>
#include "font.h"
#include <WiFiManager.h>
#include <ESPHTTPClient.h>
#include <JsonListener.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
// time
#include <time.h>                       // time() ctime()
#include <sys/time.h>                   // struct timeval
#include <coredecls.h>   
#include <WiFiManager.h>               

#include "SH1106Wire.h"
#include "OLEDDisplayUi.h"
#include "Wire.h"
#include "OpenWeatherMapCurrent.h"
#include "OpenWeatherMapForecast.h"
#include "WeatherStationFonts.h"
#include "WeatherStationImages.h"
#include "PlaneImage.h"

//#include "gauge.h"

/***************************
 * Begin Settings
 **************************/

/*********************************** WiFi Setup ******************************/
const char* WIFI_SSID = "";
const char* WIFI_PWD = "";


/****************************** Time Zone Setup *********************************/

#define TZ              +8       // (utc+) TZ in hours
#define DST_MN          0      // use 60mn for summer time in some countries

/**************************Refresh Setup ***********************************/

const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 20 minutes


/************************* Display Settings *************************************/

const int I2C_DISPLAY_ADDRESS = 0x3c;
#if defined(ESP8266)
const int SDA_PIN = D1;
const int SDC_PIN = D2;
#else
const int SDA_PIN = D1; //D3;
const int SDC_PIN = D2; //D4;
#endif

 // Initialize the oled display for address 0x3c
 // sda-pin=5 and sdc-pin=4
SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
OLEDDisplayUi ui( &display );

/********************************** Button ****************************************/

int upButton = 13;
int downButton = 12;
int pushButton = 14;
int offButton = 0;
int onButton = 2;
int current_page = 0;
int UP = 0;
int DOWN = 0;
int submenu = 0;
int current_next_state = 0;
int lasttextblobfade = 0;
int statetextblobfade = 0;

/****************************** OpenWeatherMap Settings **********************************/

// Sign up here to get an API key:
// https://docs.thingpulse.com/how-tos/openweathermap-key/
String OPEN_WEATHER_MAP_APP_ID = "856212fc608f19a241e8c6ea8ac43a84";
/*
Go to https://openweathermap.org/find?q= and search for a location. Go through the
result set and select the entry closest to the actual location you want to display 
data for. It'll be a URL like https://openweathermap.org/city/2657896. The number
at the end is what you assign to the constant below.
 */
String OPEN_WEATHER_MAP_LOCATION_ID = "1733046";

// Pick a language code from this list:
// Arabic - ar, Bulgarian - bg, Catalan - ca, Czech - cz, German - de, Greek - el,
// English - en, Persian (Farsi) - fa, Finnish - fi, French - fr, Galician - gl,
// Croatian - hr, Hungarian - hu, Italian - it, Japanese - ja, Korean - kr,
// Latvian - la, Lithuanian - lt, Macedonian - mk, Dutch - nl, Polish - pl,
// Portuguese - pt, Romanian - ro, Russian - ru, Swedish - se, Slovak - sk,
// Slovenian - sl, Spanish - es, Turkish - tr, Ukrainian - ua, Vietnamese - vi,
// Chinese Simplified - zh_cn, Chinese Traditional - zh_tw.
String OPEN_WEATHER_MAP_LANGUAGE = "en";
const uint8_t MAX_FORECASTS = 4;

const boolean IS_METRIC = true;

// Adjust according to your language
const String WDAY_NAMES[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const String MONTH_NAMES[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};


OpenWeatherMapCurrentData currentWeather;
OpenWeatherMapCurrent currentWeatherClient;

OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
OpenWeatherMapForecast forecastClient;

/************************* Time Zone Setup ***********************************************/

#define TZ_MN           ((TZ)*60)
#define TZ_SEC          ((TZ)*3600)
#define DST_SEC         ((DST_MN)*60)
time_t now;

#define HOSTNAME "ESP8266-OTA-"

// flag changed in the ticker function every 10 minutes
bool readyForWeatherUpdate = false;

String lastUpdate = "--";

long timeSinceLastWUpdate = 0;

/******************************** declaring prototypes ***********************************************/

void configModeCallback (WiFiManager *myWiFiManager);
void drawProgress(OLEDDisplay *display, int percentage, String label);
void updateData(OLEDDisplay *display);
void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
//void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex);
void drawHumidity(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
//void drawFR24(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void setReadyForWeatherUpdate();
//void drawPressure(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void switchToFrame(uint8_t frame);
int8_t getWifiQuality();
//void drawWind(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void process_flight(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y, String flight);
void display_flight(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
 

/***************************** Add frames **************************************************/

// this array keeps function pointers to all frames
// frames are the single views that slide from right to left0
FrameCallback frames[] = { drawDateTime, drawForecast, drawHumidity, display_flight};
int numberOfFrames = 4;

//OverlayCallback overlays[] = { drawHeaderOverlay };
int numberOfOverlays = 1;

//*********************** LED SETUP ***************************************/

const int LEDpin = 16;
//const int buttonPin = 0;

const long onDuration = 15000;// OFF time for LED
const long offDuration = 20;// ON time for LED
int LEDState =HIGH;// initial state of LED

long rememberTime=0;// this is used by the code

/******************************* FR24 ******************************************/

const char* server         = "data-live.flightradar24.com";
const unsigned short port  = 80;
const String area          = "<long max>,<long min>,<lat min>,<lat max>"; //REPLACE WITH YOUR DATA ex : 40.00,39.50,10.50,11.00
const String path          = "/zones/fcgi/feed.js?faa=1&bounds=3.462%2C2.438%2C101.156%2C102.504&satellite=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=14400&gliders=1&stats=1&enc=aUZxeUj-cudNzTMJ_LNTMhchOm2J_TlYbC5HPIDKD_0";


/*********************************** End Setup ***************************************/


void setup() {
  WiFi.mode( WIFI_OFF );
  WiFi.forceSleepBegin();
  delay( 1 );;
  Serial.begin(115200);
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(pushButton, INPUT_PULLUP);
  pinMode(offButton, INPUT_PULLUP);
  pinMode(onButton, INPUT_PULLUP);
  pinMode(LEDpin, OUTPUT);
  

  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  display.init();
  display.clear();
  display.display();

  //display.flipScreenVertically();
  display.setFont(Orbitron_Medium_12);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setContrast(255);
  display.drawString(64, 10, "NTP");
  display.setFont(Orbitron_Medium_12);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64, 30, "Smartwatch");
  display.flipScreenVertically();
  display.display();
  delay(3000);

  WiFi.forceSleepWake();
  delay( 1 );

  

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;
  // Uncomment for testing wifi manager
  //wifiManager.resetSettings();
  wifiManager.setAPCallback(configModeCallback);

  //or use this for auto generated name ESP + ChipID
  wifiManager.autoConnect();

  //Manual Wifi
  //WiFi.begin(WIFI_SSID, WIFI_PWD);
  String hostname(HOSTNAME);
  hostname += String(ESP.getChipId(), HEX);
  WiFi.hostname(hostname);

  int counter = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    display.clear();
    //display->drawFastImage(90 , 10, 32, 32, wind);
    display.setFont(SansSerif_plain_10);
    display.drawString(64, 10, "Connecting to WiFi");
    display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbole : inactiveSymbole);
    display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbole : inactiveSymbole);
    display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbole : inactiveSymbole);
    display.flipScreenVertically();
    display.display();

    counter++;
  }
  // Get time from network time service
  configTime(TZ_SEC, DST_SEC, "pool.ntp.org");

  ui.setTargetFPS(60);

  //ui.setActiveSymbol(activeSymbole);
  //ui.setInactiveSymbol(inactiveSymbole);

  // You can change this to
  // TOP, LEFT, BOTTOM, RIGHT
  //ui.setIndicatorPosition(BOTTOM);

  // Defines where the first frame is located in the bar.
  //ui.setIndicatorDirection(LEFT_RIGHT);
  ui.disableIndicator();
  // You can change the transition that is used
  // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
  //ui.setFrameAnimation(SLIDE_LEFT);
  ui.disableAutoTransition();
  ui.setIndicatorPosition(RIGHT);
  ui.setFrameAnimation(SLIDE_UP);

  ui.setFrames(frames, numberOfFrames);

 // ui.setOverlays(overlays, numberOfOverlays);

  // Inital UI takes care of initalising the display too.
  //ui.init();
  
  // Setup OTA
  //Serial.println("Hostname: " + hostname);
 // ArduinoOTA.setHostname((const char *)hostname.c_str());
 // ArduinoOTA.onProgress(drawOtaProgress);
  //ArduinoOTA.begin();



  Serial.println("");
  display.flipScreenVertically();
  updateData(&display);
}

  String get_flight_details() {
  String results = "";

  display.setFont(ArialMT_Plain_10);
  display.drawString(64, 10, "connecting to ");
  Serial.println(server);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  if (!client.connect(server, port)) {
    display.drawString(64, 10, "connection failed");
    return "Connection closed";
  }

  String url = path;
  display.setFont(ArialMT_Plain_10);
  display.drawString(64, 10, "Requesting URL:");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + server + "\r\n" +
               "Connection: close\r\n\r\n");
               
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return "Connection timeout";
    }
  }

  // Read all the lines of the reply from server and print them to Serial

  while (client.available()) {
    results += client.readStringUntil(']');
    break;
  }

  Serial.println();
  Serial.println("closing connection");
  results.remove(0,1);  // Removing nlc

  Serial.println("Fetched data: " +results);
  return results;
}

void process_flight(String flight){
  display.setFont(ArialMT_Plain_10);
  Serial.println("Processing flight:");
  display.display();
  delay(1000);
  Serial.println(flight);
  
  
  char *cflight = (char*)malloc(flight.length());
  
  flight.toCharArray(cflight,flight.length());
  
  char *dummy  = strtok(cflight,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *calt   = strtok(NULL,",");
  char *cspeed = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *cac    = strtok(NULL,",");
  char *creg   = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *cfrom  = strtok(NULL,",");
  char *cto    = strtok(NULL,",");
  char *cflno  = strtok(NULL,",");
  
  Serial.println("DUMP::::");
  Serial.println(cfrom);
  Serial.println(cto);
  Serial.println(creg);
  Serial.println(calt);
  Serial.println(cspeed);
  Serial.println(cac);
  Serial.println(cflno);
  Serial.println("ENDOFDUMP<<<");

  //display_flight();
  //cfrom,cto,cac,calt,cspeed,cflno,creg
  //display.display();
  delay(3000);
  display.clear();

  free(cflight);
  
}

String parse_flight(String json){
  int start_c = json.indexOf('[',0);
  String c    = json.substring(start_c);

  c.replace("\"\"","N/A");
  c.replace("\"","");
  
  return c;
}

void loop() {

 LEDState = digitalRead(offButton);
 digitalWrite(LEDpin,LEDState);// set initial state
 if( LEDState ==HIGH )
 {
    if( (millis()- rememberTime) >= onDuration){   
    LEDState = LOW;// change the state of LED
    rememberTime=millis();// remember Current millis() time
    }
 }
 else
 {   
    if( (millis()- rememberTime) >= offDuration){     
    LEDState =HIGH;// change the state of LED
    rememberTime=millis();// remember Current millis() time
    }
 }
  
   // Robojax LED blink with millis()
  digitalWrite(LEDpin,LEDState);

  if (!digitalRead(downButton)){
    ui.previousFrame();
    delay(250);

  }

  if (!digitalRead(upButton)){
    ui.nextFrame();
    delay(250);

  }

  if (!digitalRead(pushButton)){
     display.displayOn();
     delay(100);
  }     
     

  if (!digitalRead(offButton)){
     display.displayOff();
     delay(100);

  }

  if (!digitalRead(onButton)){
     display.displayOn();
     delay(100);
  }

  if (millis() - timeSinceLastWUpdate > (1000L*UPDATE_INTERVAL_SECS)) {
    setReadyForWeatherUpdate();
    timeSinceLastWUpdate = millis();
    
  }

  if (readyForWeatherUpdate && ui.getUiState()->frameState == FIXED) {
    updateData(&display);

  }

  int remainingTimeBudget = ui.update();

  if (remainingTimeBudget > 0) {
   
    // You can do some work here
    // Don't do stuff if you are below your
    // time budget.
    delay(remainingTimeBudget);
  }  
}

void display_flight(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y){
  
  display->setFont(ArialMT_Plain_10);
  display->drawString(15, 0, "From : ");
  display->setFont(DejaVu_Serif_13);
  display->drawString(43, 0, cfrom);
  display->setFont(ArialMT_Plain_10);
  display->drawString(80, 0, "To : ");
  display->setFont(DejaVu_Serif_13);
  display->drawString(104, 0, cto);
  display->setFont(ArialMT_Plain_10);
  //display.setFont(DejaVu_Serif_13);
  display->drawString(45, 18, "Alt");
  display->drawString(15, 18, calt);
  display->drawString(46, 29, "kts");
  display->drawString(15, 29, cspeed);
  display->setFont(DejaVu_Serif_13);
  display->drawString(90, 50, cac);
  display->drawString(30, 50, cflno);

  display->drawFastImage(80, 20, 24, 24, plane);
}


void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  Serial.println(myWiFiManager->getConfigPortalSSID());
  display.clear();
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_10);
  display.drawString(64, 10, "Wifi Manager");
  display.drawString(64, 20, "Please connect to AP");
  display.drawString(64, 30, myWiFiManager->getConfigPortalSSID());
  display.drawString(64, 40, "To setup Wifi Configuration");
  display.display();
}

void drawProgress(OLEDDisplay *display, int percentage, String label) {
  display->clear();
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->setFont(SansSerif_plain_10);
  display->drawString(64, 10, label);
  display->drawProgressBar(2, 28, 124, 10, percentage);
  display->display();
}

void updateData(OLEDDisplay *display) {
  drawProgress(display, 10, "Updating time...");
  drawProgress(display, 30, "Updating weather...");
  currentWeatherClient.setMetric(IS_METRIC);
  currentWeatherClient.setLanguage(OPEN_WEATHER_MAP_LANGUAGE);
  currentWeatherClient.updateCurrentById(&currentWeather, OPEN_WEATHER_MAP_APP_ID, OPEN_WEATHER_MAP_LOCATION_ID);
  drawProgress(display, 50, "Updating forecasts...");
  forecastClient.setMetric(IS_METRIC);
  forecastClient.setLanguage(OPEN_WEATHER_MAP_LANGUAGE);
  uint8_t allowedHours[] = {12};
  forecastClient.setAllowedHours(allowedHours, sizeof(allowedHours));
  forecastClient.updateForecastsById(forecasts, OPEN_WEATHER_MAP_APP_ID, OPEN_WEATHER_MAP_LOCATION_ID, MAX_FORECASTS);
  String json;
  String flight;

  json   = get_flight_details();
  flight = parse_flight(json);
  process_flight(flight);

  readyForWeatherUpdate = false;
  drawProgress(display, 100, "Done...");
  delay(1000);
}



void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  now = time(nullptr);
  struct tm* timeInfo;
  timeInfo = localtime(&now);
  char buff[16];

  
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->setFont(SansSerif_plain_10);


  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->setFont(SansSerif_plain_10);
  String date = WDAY_NAMES[timeInfo->tm_wday];

  sprintf_P(buff, PSTR("%S %d %d %04d"), WDAY_NAMES[timeInfo->tm_wday].c_str(), timeInfo->tm_mday, timeInfo->tm_mon+1, timeInfo->tm_year + 1900);
  display->drawString(58 + x, 1 + y, String(buff));
  display->setFont(Orbitron_Medium_18);

  sprintf_P(buff, PSTR("%02d:%02d"), timeInfo->tm_hour, timeInfo->tm_min);
  display->drawString(74 + x, 20 + y, String(buff));
  display->setTextAlignment(TEXT_ALIGN_LEFT);

  display->setFont(ArialMT_Plain_10);
  sprintf_P(buff, PSTR(": %02d"), timeInfo->tm_sec);
  display->drawString(111 + x, 0 + y, String(buff));
  display->setTextAlignment(TEXT_ALIGN_LEFT);

  display->setFont(SansSerif_plain_10);
  display->setTextAlignment(TEXT_ALIGN_RIGHT);
  String temp = String(currentWeather.temp, 1) + (IS_METRIC ? "°C" : "°F");
  display->drawString(38, 52, temp);

  display->setFont(Meteocons_Regular_28);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->drawString(20 + x, 15 + y, currentWeather.iconMeteoCon);

  display->setFont(SansSerif_plain_10);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->drawStringMaxWidth(78 + x, 41 + y,124, currentWeather.description);


  int8_t quality = getWifiQuality();
  for (int8_t i = 0; i < 4; i++) {
    for (int8_t j = 0; j < 2 * (i + 1); j++) {
      if (quality > i * 25 || j == 0) {
        display->setPixel(120 + 2 * i, 63 - j);
      }
    }
  }
}

void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  display->setFont(Orbitron_Medium_10);
  String cityName = String(currentWeather.cityName);
  display->drawString(40 + x, 0 + y, cityName);
  
  display->setFont(SansSerif_plain_10);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->drawString(90 + x, 38 + y, currentWeather.description);

  display->setFont(Orbitron_Medium_22);
  display->setTextAlignment(TEXT_ALIGN_LEFT);
  String temp = String(currentWeather.temp, 1) + (IS_METRIC ? "°" : "°F");
  display->drawString(60 + x, 15 + y, temp);

  display->setFont(Meteocons_Regular_18);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->drawString(25 + x, 5 + y, currentWeather.iconMeteoCon);

  now = time(nullptr);
  struct tm* timeInfo;
  timeInfo = localtime(&now);
  char buff[14];
  sprintf_P(buff, PSTR("%02d:%02d"), timeInfo->tm_hour, timeInfo->tm_min);

  display->setColor(WHITE);
  display->setFont(SansSerif_plain_10);
  display->setTextAlignment(TEXT_ALIGN_LEFT);
  display->drawString(0, 54, String(buff));   
  
}


void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  drawForecastDetails(display, x, y, 0);
  drawForecastDetails(display, x + 44, y, 1);
  drawForecastDetails(display, x + 88, y, 2);
}

void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex) {
  time_t observationTimestamp = forecasts[dayIndex].observationTime;
  struct tm* timeInfo;
  timeInfo = localtime(&observationTimestamp);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->setFont(SansSerif_plain_10);
  display->drawString(x + 20, y, WDAY_NAMES[timeInfo->tm_wday]);

  display->setFont(Meteocons_Regular_18);
  display->drawString(x + 20, y + 12, forecasts[dayIndex].iconMeteoCon);
  String temp = String(forecasts[dayIndex].temp, 0) + (IS_METRIC ? "°C" : "°F");
  display->setFont(Orbitron_Medium_12);
  display->drawString(x + 20, y + 34, temp);
  display->setTextAlignment(TEXT_ALIGN_LEFT);
}

void drawHumidity(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  //display->setFont(ArialMT_Plain_10);
  //display->drawFastImage(60, 0, 24, 24, humidity1);
  display->setFont(ArialMT_Plain_10);
  display->setTextAlignment(TEXT_ALIGN_CENTER);
  display->drawString(26 + x, 15 + y, "Humidity  : ");
  String humidity = String(currentWeather.humidity) + (" %");
  display->setFont(DejaVu_Serif_13);
  display->drawString(73 + x, 15 + y, humidity);
  
  //display->drawFastImage(0, 40, 24, 24, presssure);
  display->setFont(ArialMT_Plain_10);
  display->drawString(24 + x, 42 + y, "Prs           :");
  String pressure = String(currentWeather.pressure) + (" hPa");
  display->setFont(DejaVu_Serif_13);
  display->drawString(88 + x, 40 + y, pressure);

  //display->drawFastImage(0, 0, 24, 24, temp24);
  display->setFont(ArialMT_Plain_10);
  display->drawString(25 + x, 0 + y, "Temp       : ");  
  display->setFont(DejaVu_Serif_13);    
  String temp = String(currentWeather.temp, 1) + (IS_METRIC ? "°" : "°F");
  display->drawString(73 + x, 0 + y, temp);

  //display->setFont(ArialMT_Plain_10); 
  //display->drawString(10 + x, 0 + y, "Loc: ");
  //display->setFont(ArialMT_Plain_10);
  //String cityName = String(currentWeather.cityName);
  //display->drawString(57 + x, 0 + y, cityName);

  display->setFont(ArialMT_Plain_10); 
  display->drawString(26 + x, 28 + y, "W.Speed : ");
  String windSpeed = String(currentWeather.windSpeed) + (" km/h");
  display->setFont(DejaVu_Serif_13);
  display->drawString(90 + x, 27 + y, windSpeed);
  //display->drawFastImage(3 , 25, 16, 16, wind);

  now = time(nullptr);
  struct tm* timeInfo;
  timeInfo = localtime(&now);
  char buff[14];
  sprintf_P(buff, PSTR("%02d:%02d"), timeInfo->tm_hour, timeInfo->tm_min);

  display->setColor(WHITE);
  display->setFont(SansSerif_plain_10);
  display->setTextAlignment(TEXT_ALIGN_LEFT);
  display->drawString(100, 0, String(buff));  

  int8_t quality = getWifiQuality();
  for (int8_t i = 0; i < 4; i++) {
    for (int8_t j = 0; j < 2 * (i + 1); j++) {
      if (quality > i * 25 || j == 0) {
        display->setPixel(120 + 2 * i, 63 - j);
      }
    }
  }
}

// converts the dBm to a range between 0 and 100%
int8_t getWifiQuality() {
  int32_t dbm = WiFi.RSSI();
  if(dbm <= -100) {
      return 0;
  } else if(dbm >= -50) {
      return 100;
  } else {
      return 2 * (dbm + 100);
  }
}

void setReadyForWeatherUpdate() {
  Serial.println("Setting readyForUpdate to true");
  readyForWeatherUpdate = true;
}

the error 'cfrom'
'cto'
'calt'
'cspeed'
'cac'
'cflno'
was not declared in this scope

I do need need coffee :wink:
No idea what you are asking? And no time to digest the long list of code.

'cfrom' not declared means: you use something which is unknown.
A H file missing to include?
A typo in name?
'cfrom' defines in another code file but forgotten to "export" via extern in a H-file, forgotten to include the H-file, forgotten to "import" via extern ... in the file using it..?

Try to find where this 'cfrom' is defined.
When used in other files - open the file and "would you know what cfrom is"?

Such "not declared" is often pretty obvious if you try to read the source code files like a compiler does: is all what you want to do obvious and defined, at least declared (e.g. as extern)?
If "reading the text" remains unclear on one word - the compiler will complain in such a way.

hi thanks for replied. cfrom was the output from json. how to declared output json.substring in order sfrom to get the value

Not familiar, but I would guess: there was a H-file generated, to export all what Jason has defined.
If not so (I would be surprised if not) - declare it yourself in C/C++ code - when you know type and size).

Try to find a H-file created, updated by Jason. Include this one and make sure it can be found by IDE (compiler).
"not declared" means: "something missing"

you have declared cfrom locally in function process_flight() but you have called it elsewhere in your code eg: in function display_flight()

you have to declare cfrom ( and other variables that throw same error ) globally ie: way above the setup() function

this is the part where im stuck. need help the magic code here

/******************************* FR24 ******************************************/

const char* server         = "data-live.flightradar24.com";
const unsigned short port  = 80;
const String area          = "<long max>,<long min>,<lat min>,<lat max>"; //REPLACE WITH YOUR DATA ex : 40.00,39.50,10.50,11.00
const String path          = "/zones/fcgi/feed.js?faa=1&bounds=3.462%2C2.438%2C101.156%2C102.504&satellite=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=14400&gliders=1&stats=1&enc=aUZxeUj-cudNzTMJ_LNTMhchOm2J_TlYbC5HPIDKD_0";

String json = json;
int start_c = json.indexOf('[',0);
String cfrom = json.substring(start_c);
String cto = json.substring(start_c);
String calt = json.substring(start_c);
String cspeed = json.substring(start_c);
String cac = json.substring(start_c);
String cflno = json.substring(start_c);


/*********************************** End Setup ***************************************/


void setup() {
  WiFi.mode( WIFI_OFF );
  WiFi.forceSleepBegin();
  delay( 1 );;
  Serial.begin(115200);
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(pushButton, INPUT_PULLUP);
  pinMode(offButton, INPUT_PULLUP);
  pinMode(onButton, INPUT_PULLUP);
  pinMode(LEDpin, OUTPUT);
  

i try to declared globally but the value not show up.

Your setup function is missing a closing } and you have no loop function.

What does that mean, please?

the sform, sto, sac, sflno value not showing up on my oled display

The code you posted last is incomplete.

The simplest change would be to move the declarations out of the function:

char *calt;
char *cspeed;
char *cac;
char *creg;
char *cfrom;
char *cto;
char *cflno;

void process_flight(String flight){
  display.setFont(ArialMT_Plain_10);
  Serial.println("Processing flight:");
  display.display();
  delay(1000);
  Serial.println(flight);
 
  char *cflight = (char*)malloc(flight.length());
  
  flight.toCharArray(cflight,flight.length());
  
  char *dummy  = strtok(cflight,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  calt   = strtok(NULL,",");
  cspeed = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  cac    = strtok(NULL,",");
  creg   = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  cfrom  = strtok(NULL,",");
  cto    = strtok(NULL,",");
  cflno  = strtok(NULL,",");
  
  Serial.println("DUMP::::");
  Serial.println(cfrom);
  Serial.println(cto);
  Serial.println(creg);
  Serial.println(calt);
  Serial.println(cspeed);
  Serial.println(cac);
  Serial.println(cflno);
  Serial.println("ENDOFDUMP<<<");

  //display_flight();
  //cfrom,cto,cac,calt,cspeed,cflno,creg
  //display.display();
  delay(3000);
  display.clear();

  free(cflight);
}

I think you will have a problem with those data fields since you are freeing the memory allocated for "cflight". The individual fields point to that memory and if the memory is reused, the strings will be corrupted.

You could create some global character arrays and use strncpy() to copy the data from each field into a separate global array.

Another option would be to merge 'process_flight()' and 'display_flight()'. That would allow you to use the existing local variables and display the data before 'cflight' is released.

void display_flight(String flight, OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y){
  
  display.setFont(ArialMT_Plain_10);
  Serial.println("Processing flight:");
  display.display();
  delay(1000);
  Serial.println(flight);
  
  
  char *cflight = (char*)malloc(flight.length());
  
  flight.toCharArray(cflight,flight.length());
  
  char *dummy  = strtok(cflight,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *calt   = strtok(NULL,",");
  char *cspeed = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *cac    = strtok(NULL,",");
  char *creg   = strtok(NULL,",");
  dummy        = strtok(NULL,",");
  char *cfrom  = strtok(NULL,",");
  char *cto    = strtok(NULL,",");
  char *cflno  = strtok(NULL,",");
  
  Serial.println("DUMP::::");
  Serial.println(cfrom);
  Serial.println(cto);
  Serial.println(creg);
  Serial.println(calt);
  Serial.println(cspeed);
  Serial.println(cac);
  Serial.println(cflno);
  Serial.println("ENDOFDUMP<<<");

  //display_flight();
  //cfrom,cto,cac,calt,cspeed,cflno,creg
  //display.display();

  display->setFont(ArialMT_Plain_10);
  display->drawString(15, 0, "From : ");
  display->setFont(DejaVu_Serif_13);
  display->drawString(43, 0, cfrom);
  display->setFont(ArialMT_Plain_10);
  display->drawString(80, 0, "To : ");
  display->setFont(DejaVu_Serif_13);
  display->drawString(104, 0, cto);
  display->setFont(ArialMT_Plain_10);
  //display.setFont(DejaVu_Serif_13);
  display->drawString(45, 18, "Alt");
  display->drawString(15, 18, calt);
  display->drawString(46, 29, "kts");
  display->drawString(15, 29, cspeed);
  display->setFont(DejaVu_Serif_13);
  display->drawString(90, 50, cac);
  display->drawString(30, 50, cflno);

  display->drawFastImage(80, 20, 24, 24, plane);

  delay(3000);
  display.clear();

  free(cflight);
}

thank you for replied.