module SIM7672
This module provides the modem class for the SIM7672 LTE modem
on MicroCat.1. It manages power control, network registration, and a PPP
session over UART, providing internet connectivity over a cellular
network using a SIM card.
The modem class is not normally instantiated directly — use
microcat1.modem() instead.
Recommended usage:
import microcat1
m = microcat1.modem()
m.active(True)
m.connect('your_apn', 'your_apn_username', 'your_apn_password')
print(m.ifconfig())
m.disconnect()
- class SIM7672.modem(uart=machine.UART, baudrate=115200, handshake=True, led=machine.Pin, debug=False)
Bases:
objectControl the SIM7672 LTE modem on MicroCat.1.
Manages the full lifecycle of a cellular connection: power on/off, network registration, and PPP session establishment over UART.
- __init__(uart=machine.UART, baudrate=115200, handshake=True, led=machine.Pin, debug=False)
Initialize the modem.
- Parameters:
uart – UART instance for communication (default: UART(1))
baudrate – Baud rate for UART communication (default: 115200)
handshake – Enable hardware handshake (default:
True)led – LED pin for modem status indication (default: Pin(34))
debug – Enable debug output (default:
False)
- active(activate=None, reset=True)
Control or query the modem’s power state.
Returns the current state if no argument is provided.
- Parameters:
activate –
Trueto power on,Falseto power offreset – Reset modem if powering on and already active (default:
True)
- Returns:
Trueif modem is active,Falseotherwise
- config(param=None, apn=None, user=None, key=None, pdp=None, security=None)
Get or set modem parameters.
For querying, parameters name should be quoted as a
str, and only one parameter can be queries at time.- Parameters:
param – Specific parameter to get (default:
None)apn – Access Point Name (default:
None)user – Username for authentication (default:
None)key – Password for authentication (default:
None)pdp – PDP type (default:
None)security – Security type (default:
None)
- Returns:
Value of specified parameter if param is given, otherwise
None
- connect(apn=None, user=None, key=None, pdp=None, security=None, detach=False, retries=60, delay=500, transition_timeout=10000)
Connect to the cellular network.
- Parameters:
apn – Access Point Name (default:
None)user – Username for authentication (default:
None)key – Password for authentication (default:
None)pdp – PDP type (default:
None)security – Security type (default:
None)detach – Detach before connecting (default:
False)retries – Number of connection attempts (default: 60)
delay – Delay between attempts in milliseconds (default: 500)
transition_timeout – Maximum wait time for state transition in milliseconds (default: 10000)
- disconnect(retries=2, delay=10000, transition_timeout=20000)
Disconnect from the cellular network.
- Parameters:
retries – Number of disconnection attempts (default: 2)
delay – Delay between attempts in milliseconds (default: 10000)
transition_timeout – Maximum wait time for state transition in milliseconds (default: 20000)
Note
Stable connection pattern
Call
connect()before each request anddisconnect()immediately after. On failure, callmachine.reset()— this is the only reliable recovery method (disconnect()/connect()alone does not recover a wedged PPP stack). After reset, allow a few seconds for the modem to warm up before the firstconnect()call to avoid a false0.0.0.0result triggering another reset.
- ifconfig()
Get network interface configuration.
- Returns:
Network configuration tuple (ip, subnet, gateway, dns)
- isconnected()
Check if the PPP session is established.
- Returns:
Trueif the PPP session is established,Falseotherwise
Note
This reflects the PPP session state, not end-to-end network reachability. The PDP context can be terminated by the carrier while the PPP session remains alive; in that case this method returns
Truebut data transfer will fail (e.g.,OSErrorECONNABORTEDorEHOSTUNREACH).To detect this state, check
ifconfig()— if it returns('0.0.0.0', ...), the IP stack is no longer functional. Recovery viadisconnect()/connect()alone is not reliable; callmachine.reset()to recover from a clean boot sequence.
- status()
Get PPP connection status.
- Returns:
PPP connection status
Constants
- SIM7672.SEC_NONE = 0
No authentication (alias of
network.PPP.SEC_NONE).
- SIM7672.SEC_PAP = 1
PAP authentication (alias of
network.PPP.SEC_PAP).
- SIM7672.SEC_CHAP = 2
CHAP authentication (alias of
network.PPP.SEC_CHAP).
- SIM7672.PDP_IP = 'IP'
IPv4 PDP context type (
'IP').
- SIM7672.PDP_IPV6 = 'IPV6'
IPv6 PDP context type (
'IPV6').
- SIM7672.PDP_IPV4V6 = 'IPV4V6'
Dual-stack IPv4/IPv6 PDP context type (
'IPV4V6').
- SIM7672.PDP_NONIP = 'Non-IP'
Non-IP PDP context type (
'Non-IP').