2424#include < string.h>
2525#include < time.h>
2626
27+ #define TM_HTTP_BODY_WAIT 250
28+
2729Predictor::Predictor (void ) {
2830}
2931
@@ -46,32 +48,36 @@ bool Predictor::init(uint32_t catNum) {
4648 http.begin (url);
4749 http.setFollowRedirects (HTTPC_STRICT_FOLLOW_REDIRECTS );
4850 if ((retCode = http.GET ()) == HTTP_CODE_OK ) {
51+
52+ delay (TM_HTTP_BODY_WAIT );
4953 WiFiClient response = http.getStream ();
5054 satName = response.readStringUntil (' \n ' );
51- tle[0 ] = response.readStringUntil (' \n ' );
52- tle[1 ] = response.readStringUntil (' \n ' );
53-
54- // Check that the response looks plausible
55- if (satName.length () && !satName.startsWith (" No GP data" ) && tle[0 ].length () && tle[1 ].length ()) {
56-
57- // Convert the string format TLE to SGP4 elements and initialise the satellite record.
58- // twoline2rv needs non-const char arrays (it may modify them), so we make temporary copies.
59- strncpy (tleTemp[0 ], tle[0 ].c_str (), 80 );
60- strncpy (tleTemp[1 ], tle[1 ].c_str (), 80 );
61- SGP4Funcs::twoline2rv (tleTemp[0 ], tleTemp[1 ], ' a' , wgs72, satrec);
62-
63- // Convert the TLE epoch to a standard UNIX timestamp
64- SGP4Funcs::invjday_SGP4 (satrec.jdsatepoch , satrec.jdsatepochF , year, mon, day, hr, minute, sec);
65- t.tm_year = year - 1900 ; t.tm_mon = mon - 1 ; t.tm_mday = day; t.tm_hour = hr; t.tm_min = minute; t.tm_sec = sec;
66- epoch = mktime (&t);
67- done = true ;
68-
69- // Debug
70- Serial.println (String (" Predictor init complete:" ));
71- Serial.println (String (" Sat Name: " ) + satName);
72- Serial.println (String (" TLE[0]: " ) + tle[0 ]);
73- Serial.println (String (" TLE[1]: " ) + tle[1 ]);
74- Serial.println (String (" Epoch: " ) + String (epoch));
55+ if (satName.length () && !satName.startsWith (" No GP data" )) {
56+
57+ tle[0 ] = response.readStringUntil (' \n ' );
58+ tle[1 ] = response.readStringUntil (' \n ' );
59+
60+ if (tle[0 ].length () && tle[1 ].length ()) {
61+
62+ // Convert the string format TLE to SGP4 elements and initialise the satellite record.
63+ // twoline2rv needs non-const char arrays (it may modify them), so we make temporary copies.
64+ strncpy (tleTemp[0 ], tle[0 ].c_str (), 80 );
65+ strncpy (tleTemp[1 ], tle[1 ].c_str (), 80 );
66+ SGP4Funcs::twoline2rv (tleTemp[0 ], tleTemp[1 ], ' a' , wgs72, satrec);
67+
68+ // Convert the TLE epoch to a standard UNIX timestamp
69+ SGP4Funcs::invjday_SGP4 (satrec.jdsatepoch , satrec.jdsatepochF , year, mon, day, hr, minute, sec);
70+ t.tm_year = year - 1900 ; t.tm_mon = mon - 1 ; t.tm_mday = day; t.tm_hour = hr; t.tm_min = minute; t.tm_sec = sec;
71+ epoch = mktime (&t);
72+ done = true ;
73+
74+ // Debug
75+ Serial.println (String (" Predictor init complete:" ));
76+ Serial.println (String (" Sat Name: " ) + satName);
77+ Serial.println (String (" TLE[0]: " ) + tle[0 ]);
78+ Serial.println (String (" TLE[1]: " ) + tle[1 ]);
79+ Serial.println (String (" Epoch: " ) + String (epoch));
80+ }
7581 }
7682 } else {
7783 Serial.printf (" Predictor init failed with HTTP %d\n " , retCode);
0 commit comments