aboutsummaryrefslogtreecommitdiffstats
path: root/package/comgt/files/setpin.gcom
blob: 66350fe20b7fe9776fed4c83424cc01787b03a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# set pin code from evnironment "$PINCODE"
opengt
 set com 115200n81
 set senddelay 0.05
 waitquiet 3 0.5
 flash 0.1

 let c=0
:start
 send "AT+CPIN?^m"
 waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR"
 if % = -1 goto timeout
 if % = 0 goto ready
 if % = 1 goto setpin
 if % = 2 goto ready
 if % = 3 goto checkrepeat
 if % = 4 goto checkrepeat

:checkrepeat
 inc c
 if c>3 goto pinerror
 waitquiet 12 0.5
 goto start

:timeout
 print "timeout checking for PIN."
 exit 1

:ready
 print "SIM ready\n"
 goto continue
 exit 0

:setpin
 # check if output was "SIM PIN2", that's ok.
 waitfor 1 "2"
 if % = 0 goto ready

 print "Trying to set PIN\n"
 send "AT+CPIN=\""
 send $env("PINCODE")
 send "\"^m"

 waitfor 20 "OK","ERR"
 if % = -1 goto pinerror
 if % = 0 goto continue
 if % = 1 goto pinerror

:pinerror
 print "Error setting PIN, check card manually\n"
 exit 1

:continue
 print "PIN set successfully\n"
 exit 0