74 lines
2.0 KiB
Plaintext
74 lines
2.0 KiB
Plaintext
send_at("ATE0")
|
|
send_at("AT")
|
|
# reboot and wait
|
|
send_at("AT+CREBOOT")
|
|
print("rebooting... please wait")
|
|
failed = True
|
|
for i in range(1,10):
|
|
if send_at("ATE0", "OK", timeout=3):
|
|
failed = False
|
|
break
|
|
send_at("AT")
|
|
if failed:
|
|
print("failed to reboot")
|
|
exit()
|
|
# set as verbose
|
|
send_at("AT+CMEE=2")
|
|
# sim and rf status check
|
|
send_at("AT+CPIN?")
|
|
send_at("AT+CSQ")
|
|
# manual APN conf
|
|
send_at("AT+CFUN=0")
|
|
send_at("AT+CGDCONT=1,\"IP\",\"m2m.public.cz\"")
|
|
send_at("AT+CFUN=1")
|
|
send_at("AT+CGATT?")
|
|
send_at("AT+CGNAPN")
|
|
send_at("AT+CNCFG=0,1,\"m2m.public.cz\"")
|
|
# APN check
|
|
send_at("AT+CGNAPN")
|
|
# activate apn/pdp#
|
|
send_at("AT+CNACT=0,1")
|
|
send_at("AT+CNACT?")
|
|
# synch UTC
|
|
send_at(f'AT+CNTP="{NTP_SERVER}",2,0,2')
|
|
time.sleep(12)
|
|
send_at("AT+CNTP")
|
|
send_at("AT+CCLK?")
|
|
# file system init
|
|
send_at("AT+CFSINIT")
|
|
# upload ca certificate
|
|
with open(CA_LOCAL_PATH, "rb") as f:
|
|
data = f.read()
|
|
cert_len = len(data)
|
|
send_at(f'AT+CFSWFILE=1,"{CA_FILENAME}",0,{cert_len},10000', "DOWNLOAD")
|
|
time.sleep(1)
|
|
print(ser.read_all().decode())
|
|
ser.write(data)
|
|
send_at("AT+CFSTERM")
|
|
# setup mqtt with ssl
|
|
send_at(f'AT+SMCONF="URL","{EMQX_HOST}","{EMQX_PORT}"')
|
|
send_at("AT+SMCONF=\"KEEPTIME\",60")
|
|
send_at("AT+SMCONF=\"CLEANSS\",1")
|
|
send_at(f'AT+SMCONF="CLIENTID","{MQTT_CLIENT_ID}"')
|
|
send_at('AT+SMCONF="QOS",1')
|
|
send_at("AT+SMCONF?")
|
|
# set tls version to 1.2, ignore rtc time and set cipher. then check it
|
|
send_at('AT+CSSLCFG="sslversion",1,3')
|
|
send_at('AT+CSSLCFG="IGNORERTCTIME",1,1')
|
|
send_at('AT+CSSLCFG=“CIPHERSUITE”,1,0,0x0035')
|
|
send_at('AT+CSSLCFG=“CIPHERSUITE”,1,1,0x002F')
|
|
send_at("AT+CSSLCFG?")
|
|
time.sleep(10)
|
|
# convert and use uploaded certificate
|
|
send_at(f'AT+CSSLCFG="CONVERT",2,"{CA_FILENAME}"')
|
|
send_at(f'AT+SMSSL=2,"{CA_FILENAME}",""') # no idea how to CHOOSE the certificte
|
|
send_at("AT+SMSSL?")
|
|
# try to connect
|
|
if not send_at("AT+SMCONN", "OK", timeout=20):
|
|
print(" - FAILED to connect")
|
|
# disconnect/clean-up
|
|
send_at("AT+SMDISC")
|
|
send_at("AT+CNACT=0,0")
|
|
|
|
ser.close()
|