Check the network connection
The ifconfig() method returns connection elements: IP address, subnet mask, default gateway and DNS server.
Because cellular connections are point-to-point, the subnet mask and default gateway are always 255.255.255.255 and 0.0.0.0. The XBee Cellular Modem reports 0.0.0.0 for its IP address and DNS server until it completes a connection to the cellular network.
In this sample, the return value options for the isconnected() method are:
- False: The XBee Cellular Modem is not connected to the cellular network. The IP address reported by ifconfig() is 0.0.0.0.
- True: The XBee Cellular Modem is connected to the cellular network. All connection elements should be populated.
Note that the connection elements that print depend on the XBee Cellular Modem network configuration.
- Access the MicroPython environment.
- At the MicroPython >>> prompt, type import network and press Enter.
- At the MicroPython >>> prompt, type c = network.Cellular() and press Enter.
- At the MicroPython >>> prompt, type c.isconnected() and press Enter.
- If the return value is False, the cellular connection is not complete. Wait until the red LED on the XBIB board is flashing (or if you have a different board, wait 5 to 10 seconds), and run the command again.
- If the return value is True, the cellular connection is complete.
- Once the cellular connection is complete, you can print the IP settings. At the MicroPython >>> prompt, type c.ifconfig() and press Enter to print the settings.
MicroPython v1.9.3-999-g00000000 on 2018-01-01; XBee Module with EFX32
Type "help()" for more information.
>>> import network
>>> c = network.Cellular()
>>> c.isconnected()
True
>>> c.ifconfig()
('100.96.17.xx', '255.255.255.255', '0.0.0.0', '100.96.17.xx')