Skip to content

Commit

Permalink
Wait for the cellular service to appear (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl authored Mar 17, 2023
1 parent 9847c95 commit 937eda8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/net/cellular.toit
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ CONFIG_OPEN_DRAIN /int ::= 2
CONFIG_PRIORITY_LOW /int ::= 0
CONFIG_PRIORITY_HIGH /int ::= 1

service_/CellularServiceClient? ::= (CellularServiceClient).open
--if_absent=: null
service_/CellularServiceClient? := null
service_initialized_/bool := false

open config/Map? -> net.Interface:
if not service_initialized_:
// We typically run the cellular service in a non-system
// container with --trigger=boot, so we need to give it
// time to start so it can be discovered. We should really
// generalize this handling for net.open and wifi.open too,
// so we get a shared pattern for dealing with discovering
// such network services at start up.
service_initialized_ = true
service_ = (CellularServiceClient).open
--timeout=(Duration --s=5)
--if_absent=: null
service := service_
if not service: throw "cellular unavailable"
return SystemInterface_ service (service.connect config)

0 comments on commit 937eda8

Please sign in to comment.