setpin.gcom 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # set pin code from evnironment "$PINCODE"
  2. opengt
  3. set com 115200n81
  4. set senddelay 0.05
  5. waitquiet 3 0.5
  6. flash 0.1
  7. let c=0
  8. :start
  9. send "AT+CFUN=1^m"
  10. send "AT+CPIN?^m"
  11. waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR"
  12. if % = -1 goto timeout
  13. if % = 0 goto ready
  14. if % = 1 goto setpin
  15. if % = 2 goto ready
  16. if % = 3 goto checkrepeat
  17. if % = 4 goto checkrepeat
  18. :checkrepeat
  19. inc c
  20. if c>3 goto pinerror
  21. waitquiet 12 0.5
  22. goto start
  23. :timeout
  24. print "timeout checking for PIN."
  25. exit 1
  26. :ready
  27. print "SIM ready\n"
  28. goto continue
  29. exit 0
  30. :setpin
  31. # check if output was "SIM PIN2", that's ok.
  32. waitfor 1 "2"
  33. if % = 0 goto ready
  34. print "Trying to set PIN\n"
  35. send "AT+CPIN=\""
  36. send $env("PINCODE")
  37. send "\"^m"
  38. waitfor 20 "OK","ERR"
  39. if % = -1 goto pinerror
  40. if % = 0 goto continue
  41. if % = 1 goto pinerror
  42. :pinerror
  43. print "Error setting PIN, check card manually\n"
  44. exit 1
  45. :continue
  46. print "PIN set successfully\n"
  47. exit 0