这个开发板需要SIM卡联网,官方的demo又有点问题,踩了坑,标记下
import utime # 延时函数在utime库中
import modem
from modem import net
from modem import sim
deviceName = modem.info.getDevImei()
# net.setModem(0) #开启全功能模式
print("deviceName:", deviceName)
print("设备ID:", modem.info.getDevProductId())
print("固件版本:", modem.info.getDevFwVersion())
print("信号强度:",net.getCsq())
print('网络模式:',net.getMode())
print('工作状态:',net.getModem())
print("获取邻近 CELL 的信息:",net.getCellInfo())
print("IMSI:",sim.getImsi())
print("SIM卡信息:",sim.getIccid())
print("SIM卡状态:",sim.getStatus())
import http
data_post = {
'url': 'http://httpbin.org/get',
'method': 'GET',
'headers': {
'Content-Type':'application/json'
},
'timeout': 30000,
'params': ''
}
def cb(data):
print("联网变量:",g_connect_status)
print(data)
import network
g_connect_status = False
def connect_network():
global g_connect_status
netw = network.NetWorkClient()
if netw._stagecode is not None and netw._stagecode == 3 and netw._subcode == 1:
g_connect_status = True
print("已联网,信号强度:", net.getCsq())
http.request(data_post, cb)
# netw.on(1,on_4g_cb)
# netw.connect(None)
else:
print('network register failed')
connect_network()#连接网络
# http.request(data_post, cb)
if __name__ == '__main__':
while True: # 无限循环
print("helloworld") # 打印"helloworld"字串到console中
utime.sleep(1) # 打印完之后休眠1秒
Comments | NOTHING