import kv
|
from modem import sim
|
from modem import info
|
from modem import net
|
import _thread
|
import tool
|
import app_led
|
import app_network
|
from driver import UART
|
import app_aliyunIot
|
import app_uart
|
import app_uart485
|
import utime # 延时函数在utime库中
|
#查看初始化KEY如果没有指定的值就初始化
|
g_connect_status = False
|
uart = UART();
|
|
key=kv.get('key')
|
print('cha-kan-key',key)
|
print(key=='K0000\r\n')
|
if key=='K0000\r\n' or key=='K\r\n':
|
print('不用初始化KEY')
|
else:
|
print('需要初始化KET')
|
kv.set('key', 'K0000\r\n')
|
imei=info.getDevImei()
|
print('获取设备IMEI:',imei)
|
print("设备固件版本",info.getDevFwVersion())
|
print("信号强度:",net.getCsq())
|
print("ICCID:",sim.getIccid())
|
print("SIM卡状态:",sim.getStatus())
|
|
|
if __name__ == '__main__':
|
|
|
|
|
print('初始化led灯')
|
app_led.led_disp_thread()
|
print('等待初始化-----1')
|
utime.sleep(10)
|
print('检验联网是否成功')
|
ret= app_network.connect_network()
|
g_connect_status=ret
|
if ret:
|
print('联网成功,准备获取三元组信息')
|
iotKeys= tool.getDeviceInfo(imei)
|
timeJg= tool.getDefaultParameter()
|
print('得到三元组信息',iotKeys,type(iotKeys))
|
if iotKeys!=None:
|
print(iotKeys)
|
app_aliyunIot.iotInit(iotKeys['deviceName'],iotKeys['productKey'],iotKeys['deviceSecret'])
|
# app_aliyunIot.iotInit("861755054458895","k08fzh1lswD","74594782a30f61ed44f59c886013e2ee")
|
app_uart.uart_init()
|
utime.sleep(2)
|
_thread.start_new_thread(app_uart.uart_read, (timeJg,))
|
print('已经开启串口-----------------------------------------------------------------------222222222222222222222-----------------------------------------------------------')
|
app_uart485.uart_init()
|
# utime.sleep(2)
|
# _thread.start_new_thread(app_uart485.uart_read, ())
|
print('485已经开启')
|
#打开串口通讯
|
else:
|
print('连网失败 准备重启 ')
|
utime.sleep(1)
|
reboot()
|