@@ -299,16 +299,7 @@ void networkBegin()
299299 ethernetStart ();
300300#endif // COMPILE_ETHERNET
301301
302- #ifdef COMPILE_WIFI
303- // Start WiFi
304- networkSequenceStart (NETWORK_WIFI, settings.debugNetworkLayer );
305- #endif // COMPILE_WIFI
306-
307- // Start LARA (cellular modem)
308- #ifdef COMPILE_CELLULAR
309- if (present.cellular_lara )
310- laraStart ();
311- #endif // COMPILE_CELLULAR
302+ // WiFi and cellular networks are started/stopped as consumers come online/offline in networkUpdate()
312303}
313304
314305// ----------------------------------------
@@ -1296,12 +1287,44 @@ void networkUpdate()
12961287 uint8_t priority;
12971288 NETWORK_POLL_SEQUENCE *sequence;
12981289
1299- if (networkConsumers () == 0 )
1290+ // If there are no consumers, do not start the network
1291+ if (networkConsumers () == 0 && networkIsOnline () == false )
13001292 {
1301- // If there are no consumers, do not start the network
13021293 return ;
13031294 }
13041295
1296+ // If there are no consumers, but the network is online, shut down all networks
1297+ if (networkConsumers () == 0 && networkIsOnline () == true )
1298+ {
1299+ // Shutdown all networks
1300+ for (int index = 0 ; index < NETWORK_OFFLINE; index++)
1301+ {
1302+ NetMask_t bitMask = 1 << index;
1303+ if (networkInterfaceTable[index].stop && (networkStarted & bitMask))
1304+ {
1305+ // Stop this network
1306+ systemPrintf (" Stopping %s\r\n " , networkGetNameByIndex (index));
1307+ networkSequenceStop (index, settings.debugNetworkLayer );
1308+ }
1309+ }
1310+ }
1311+
1312+ // Allow consumers to start networks
1313+ if (networkConsumers () > 0 && networkIsOnline () == false )
1314+ {
1315+ // Start network as needed. Skip Ethernet as its always on.
1316+ for (int index = NETWORK_WIFI; index < NETWORK_OFFLINE; index++)
1317+ {
1318+ NetMask_t bitMask = 1 << index;
1319+ if (networkInterfaceTable[index].stop )
1320+ {
1321+ // Start this network
1322+ systemPrintf (" Starting %s\r\n " , networkGetNameByIndex (index));
1323+ networkSequenceStart (index, settings.debugNetworkLayer );
1324+ }
1325+ }
1326+ }
1327+
13051328 // Walk the list of network priorities in descending order
13061329 for (priority = 0 ; priority < NETWORK_OFFLINE; priority++)
13071330 {
@@ -1416,72 +1439,79 @@ uint8_t networkConsumers()
14161439
14171440 uint16_t consumerType = 0 ;
14181441
1419- // Rover + NTRIP Client
1420- if (inRoverMode () == true && settings.enableNtripClient == true )
1442+ // Network needed for NTRIP Client
1443+ if (( inRoverMode () == true && settings.enableNtripClient == true ) || online. ntripClient )
14211444 {
14221445 consumerCount++;
14231446 consumerType |= (1 << 0 );
14241447 }
14251448
1426- // Base + NTRIP Server
1427- if (inBaseMode () == true && settings.enableNtripServer == true )
1449+ // Network needed for NTRIP Server
1450+ if (( inBaseMode () == true && settings.enableNtripServer == true ) || online. ntripServer )
14281451 {
14291452 consumerCount++;
14301453 consumerType |= (1 << 1 );
14311454 }
14321455
1433- // TCP Client
1434- if (settings.enableTcpClient == true )
1456+ // Network needed for TCP Client
1457+ if (settings.enableTcpClient == true || online. tcpClient )
14351458 {
14361459 consumerCount++;
14371460 consumerType |= (1 << 2 );
14381461 }
14391462
1440- // TCP Server
1441- if (settings.enableTcpServer == true )
1463+ // Network needed for TCP Server
1464+ if (settings.enableTcpServer == true || online. tcpServer )
14421465 {
14431466 consumerCount++;
14441467 consumerType |= (1 << 3 );
14451468 }
14461469
1447- // UDP Server
1448- if (settings.enableUdpServer == true )
1470+ // Network needed for UDP Server
1471+ if (settings.enableUdpServer == true || online. udpServer )
14491472 {
14501473 consumerCount++;
14511474 consumerType |= (1 << 4 );
14521475 }
14531476
1454- // PointPerfect ZTP or get keys
1477+ // Network needed for PointPerfect ZTP or key update requested from menu (or display menu)
14551478 if (settings.requestKeyUpdate == true )
14561479 {
14571480 consumerCount++;
14581481 consumerType |= (1 << 5 );
14591482 }
14601483
1461- // PointPerfect Corrections enabled with a non-zero length key
1462- if (settings.enablePointPerfectCorrections == true && strlen (settings. pointPerfectCurrentKey ) > 0 )
1484+ // Network needed for PointPerfect Corrections key update
1485+ if (settings.requestKeyUpdate == true )
14631486 {
1464- if (online.rtc == true )
1465- {
1466- // Check if keys need updating
1467- int daysRemaining =
1468- daysFromEpoch (settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1 );
1469- if (daysRemaining < 28 )
1470- {
1471- consumerCount++;
1472- consumerType |= (1 << 6 );
1473- }
1474- else
1475- {
1476- // PointPerfect is enabled, allow MQTT to begin
1477- consumerCount++;
1478- consumerType |= (1 << 7 );
1479- }
1480- }
1487+ consumerCount++;
1488+ consumerType |= (1 << 6 );
14811489 }
14821490
1483- // OTA
1491+ // Network needed for PointPerfect Corrections MQTT client
1492+ if ((settings.enablePointPerfectCorrections == true && strlen (settings.pointPerfectCurrentKey ) > 0 ) ||
1493+ online.mqttClient )
1494+ {
1495+ // PointPerfect is enabled, allow MQTT to begin
1496+ consumerCount++;
1497+ consumerType |= (1 << 7 );
1498+ }
1499+
1500+ // Network needed to obtain the latest firmware version
1501+ if (otaRequestFirmwareVersionCheck == true )
1502+ {
1503+ consumerCount++;
1504+ consumerType |= (1 << 8 );
1505+ }
14841506
1507+ // Network needed for to start a firmware update
1508+ if (otaRequestFirmwareUpdate == true )
1509+ {
1510+ consumerCount++;
1511+ consumerType |= (1 << 9 );
1512+ }
1513+
1514+ // Debug
14851515 if (settings.debugNetworkLayer )
14861516 {
14871517 static unsigned long lastPrint = 0 ;
@@ -1493,7 +1523,7 @@ uint8_t networkConsumers()
14931523 if (consumerCount > 0 )
14941524 {
14951525 systemPrintf (" - Consumers: " , consumerCount);
1496-
1526+
14971527 if (consumerType & (1 << 0 ))
14981528 systemPrint (" Rover NTRIP Client, " );
14991529 if (consumerType & (1 << 1 ))
@@ -1505,11 +1535,15 @@ uint8_t networkConsumers()
15051535 if (consumerType & (1 << 4 ))
15061536 systemPrint (" UDP Server, " );
15071537 if (consumerType & (1 << 5 ))
1508- systemPrint (" PPL Key Request, " );
1538+ systemPrint (" PPL Key Update Request, " );
15091539 if (consumerType & (1 << 6 ))
1510- systemPrint (" PPL Key Update, " );
1540+ systemPrint (" PPL Key Update Scheduled , " );
15111541 if (consumerType & (1 << 7 ))
15121542 systemPrint (" PPL MQTT Client, " );
1543+ if (consumerType & (1 << 8 ))
1544+ systemPrint (" OTA Version Check, " );
1545+ if (consumerType & (1 << 9 ))
1546+ systemPrint (" OTA Scheduled Check, " );
15131547 }
15141548
15151549 systemPrintln ();
0 commit comments