Error message Cannot set property 'orientation' of undefined ?

Trying to update position of my entity, I did this code:

var res4=0;
var res5=0;
var res6=0;
var res7=0;
var res8=0;
var timer=0;
var entity;
function startup(Cesium) {
    'use strict';
//Sandcastle_Begin
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkM2NlYjcwMy1hOTY4LTRiMTgtOWFhMy1hMjZmODA3ZDA3ZTUiLCJpZCI6NTQxMCwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MzI3NzIyM30.A8aH7PfgRMThMye_Y77_hfVnxhnGRKGFd_14oZC23pk';

window.setInterval(flightradar('F-GLZJ'),100);

//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {

    timeline : false,
    infoBox : true,
    selectionIndicator : false,
    shadows : true,
    shouldAnimate : true,
    terrainProvider: Cesium.createWorldTerrain({requestVertexNormals : true, requestWaterMask: true}),
    scene3DOnly: true,
    baseLayerPicker: false
});

var scene = viewer.scene;
scene.globe.enableLighting = true;
scene.globe.depthTestAgainstTerrain = true;
//var layers = scene.imageryLayers;
//var mapOpenWeatherMaps = layers.addImageryProvider(new Cesium.createOpenStreetMapImageryProvider( {
// url: ‘http://tile.openweathermap.org/map/clouds_new’,
// fileExtension: ‘png’ + ‘?appid=d56085bd95e53422bbda70c0fea04ae0’
//}));

//mapOpenWeatherMaps.opacity=0.2

// Create entity:

var position = Cesium.Cartesian3.fromDegrees(res5,res4,res7);
var heading = Cesium.Math.toRadians(res6-90);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

    entity = viewer.entities.add({
    name : 'Cesium_Air',
    position : position,
    orientation : orientation,
    model : {
        uri : '../../SampleData/models/CesiumAir/Cesium_Air.glb',
        minimumPixelSize : 128,
        maximumScale : 20000
    }
});

// Position of the entity:

function flightradar(registration)
  {
  timer=timer+1;

// each 100 calling time, get live position from server

  if(timer>100)
      {var date= new Date();
      var res;
      var url = 'http://data-live.flightradar24.com/zones/fcgi/feed.js?reg=!’+registration+’&_=’+date;
      var doc= new XMLHttpRequest();
      doc.onreadystatechange = function(){
          if(doc.readyState == XMLHttpRequest.DONE){
              res=doc.responseText;//JS.data(doc.responseText);
              var res1=res.split("[");
              var res2=res1[1];
              var res3=res2.split(",");
               res4=parseFloat(res3[1]); //latitude_value
               res5=parseFloat(res3[2]); // longitude_value
               res6=parseFloat(res3[3]); // track_value
              res7=parseFloat(res3[4])*0.3048; // altitude_value
              res8=parseFloat(res3[5]); // speed_value
              //console.log(res4+" “+res5+” “+res6+” “+res7+” "+res8)
      }
    }
      doc.open(‘GET’, url, true);
      doc.send();
      timer=0;
}

// estimated position following speed & heading until server give position

var vit=res8;
var track=res6;
var lat=res4;
var lon=res5;
var radius = 6370640;
var speed_ms=vit*0.51444;
var distance=speed_ms*0.09;
var δ = Number(distance) / radius; // angular distance in radians
var θ = Number(track)*Math.PI/180;

var φ1 = lat*Math.PI/180;
var λ1 = lon*Math.PI/180;

var sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1);
var sinδ = Math.sin(δ), cosδ = Math.cos(δ);
var sinθ = Math.sin(θ), cosθ = Math.cos(θ);

var sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
var φ2 = Math.asin(sinφ2);
var y = sinθ * sinδ * cosφ1;
var x = cosδ - sinφ1 * sinφ2;
var λ2 = λ1 + Math.atan2(y, x);

var newLat =φ2*180/Math.PI;
var newLong=(λ2*180/Math.PI+540)%360-180;

res4=newLat;
res5=newLong;

// final position of the entity

  position = Cesium.Cartesian3.fromDegrees(res5,res4,res7);
  heading = Cesium.Math.toRadians(res6-90);
  pitch = 0;
  roll = 0;
  hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

entity.orientation=orientation;
viewer.trackedEntity = entity;
};

//Sandcastle_End

Sandcastle.finishedLoading();

}
if (typeof Cesium !== 'undefined') {
    startup(Cesium);
} else if (typeof require === 'function') {
    require(['Cesium'], startup);
};

When the entity add is inside the function flightradar with add line viewer.entities.removeAll();, it's working fine but it's flashing because the entity is delete and create many time, that why I want only change the orientation (position + attitude of it).

Then with the code above, I receive error Cannot set property 'orientation' of undefined but the var entity is declare at the top like other variable, could you help me?

Solve with this new code, window.interval is not working properly, start the requested function only one time.

Replaced by:

var clock= new Cesium.Clock();
var time = Date.now();

viewer.clock.onTick.addEventListener(function(clock){

    if(Date.now()>=time+100)
    {
        function();
        time=Date.now();
    }
});

my new code:

var res4=0;
var res5=0;
var res6=0;
var res7=0;
var res8=0;
var timer=0;
var fgaln;
var position = Cesium.Cartesian3.fromDegrees(2.111137, 49.451413, 1000);
var heading = Cesium.Math.toRadians(0-90);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(0, 0, 0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
function startup(Cesium) {
    'use strict';
//Sandcastle_Begin
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkM2NlYjcwMy1hOTY4LTRiMTgtOWFhMy1hMjZmODA3ZDA3ZTUiLCJpZCI6NTQxMCwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MzI3NzIyM30.A8aH7PfgRMThMye_Y77_hfVnxhnGRKGFd_14oZC23pk';

//window.setInterval(flightradar('EI-FHN'),10000);

//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {

    timeline : false,
    infoBox : true,
    selectionIndicator : false,
    shadows : true,
    shouldAnimate : true,
    terrainProvider: Cesium.createWorldTerrain({requestVertexNormals : true, requestWaterMask: true}),
    scene3DOnly: true,
    baseLayerPicker: false
});

//var scene = viewer.scene;
//scene.globe.enableLighting = true;
//scene.globe.depthTestAgainstTerrain = true;
//var layers = scene.imageryLayers;
//var mapOpenWeatherMaps = layers.addImageryProvider(new Cesium.createOpenStreetMapImageryProvider( {
// url: ‘http://tile.openweathermap.org/map/clouds_new’,
// fileExtension: ‘png’ + ‘?appid=d56085bd95e53422bbda70c0fea04ae0’
//}));

//mapOpenWeatherMaps.opacity=0.2

// Create entity:

var entity = viewer.entities.add({
id:'fgaln',
name : 'Cesium_Air',
position : position,
orientation : orientation,
model : {
        uri : './node_modules/cesium/Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
        minimumPixelSize : 128,
        maximumScale : 20000
    }
});

// Position of the entity:

function flightradar(registration)
  {
  timer=timer+1;

// each 100 calling time, get live position from server

  if(timer>100)
      {
      var date= Date.now();
      var res;
      var url = 'http://data-live.flightradar24.com/zones/fcgi/feed.js?reg=!’+registration+’&_=’+date;
      var doc= new XMLHttpRequest();
      doc.onreadystatechange = function(){
          if(doc.readyState == XMLHttpRequest.DONE){
              res=doc.responseText;//JS.data(doc.responseText);
              window.alert(‘requet’+res)
              var res1=res.split("[");
              var res2=res1[1];
              var res3=res2.split(",");
               res4=parseFloat(res3[1]); //latitude_value
               res5=parseFloat(res3[2]); // longitude_value
               res6=parseFloat(res3[3]); // track_value
              res7=parseFloat(res3[4])*0.3048; // altitude_value
              res8=parseFloat(res3[5]); // speed_value
              //console.log(res4+" “+res5+” “+res6+” “+res7+” "+res8)
      }
    }
      doc.open(‘GET’, url, true);
      doc.send();
      timer=0;
}

// estimated position following speed & heading until server give position

var vit=res8;
var track=res6;
var lat=res4;
var lon=res5;
var radius = 6370640;
var speed_ms=vit*0.51444;
var distance=speed_ms*0.09;
var δ = Number(distance) / radius; // angular distance in radians
var θ = Number(track)*Math.PI/180;

var φ1 = lat*Math.PI/180;
var λ1 = lon*Math.PI/180;

var sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1);
var sinδ = Math.sin(δ), cosδ = Math.cos(δ);
var sinθ = Math.sin(θ), cosθ = Math.cos(θ);

var sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
var φ2 = Math.asin(sinφ2);
var y = sinθ * sinδ * cosφ1;
var x = cosδ - sinφ1 * sinφ2;
var λ2 = λ1 + Math.atan2(y, x);

var newLat =φ2*180/Math.PI;
var newLong=(λ2*180/Math.PI+540)%360-180;

res4=newLat;
res5=newLong;
// final position of the entity

  position = Cesium.Cartesian3.fromDegrees(res5,res4,res7);
  heading = Cesium.Math.toRadians(res6-90);
  pitch = 0;
  roll = 0;
  hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
};

if (typeof fgaln !== 'undefined') {
    fgaln.orientation=orientation;
}else if(typeof entity !== 'undefined') {
    entity.orientation=orientation;
};

viewer.trackedEntity = fgaln;
var clock= new Cesium.Clock();
var time = Date.now();

viewer.clock.onTick.addEventListener(function(clock){

    if(Date.now()>=time+100)
    {
        window.alert(res6);
        flightradar('OO-JEM');
        entity.orientation=orientation;
        entity.position=position
        viewer.trackedEntity = entity;
        time=Date.now();
        window.alert(res8);
    }
});
//Sandcastle_End
Sandcastle.finishedLoading();
};

if (typeof Cesium !== 'undefined') {
    startup(Cesium);
    flightradar('OO-JEM');
} else if (typeof require === 'function') {
    require(['Cesium'], startup);
};