#picaxe 40x2
#no_data
#no_table
#terminal 76800
symbol NetLight = B.0
symbol NetLightpin = pinB.0
symbol RingIndicator = B.1
symbol RingIndicatorpin = pinB.1
#macro SendSIM(X)
hserout 0,(X,13,10)
pause 1000
sertxd(13,10,X)
gosub PrintHser
#endmacro
setfreq em64
pause 8000
hsersetup B115200_64,%00001
pause 8000
sertxd(13,10,"Starting")
do
pause 16000
gosub CheckNetwork
if b0 > 1 then exit
loop
BeginAgain:
SendSIM("AT")
SendSIM("ATE1")
SendSIM("AT+CGMI")
SendSIM("AT+CGSN")
SendSIM("AT+CSUB")
SendSIM("AT+CGMR")
SendSIM("AT+IPREX?")
SendSIM("AT+CSQ")
SendSIM("AT+COPS?")
SendSIM("AT+CSUB")
SendSIM("AT+CPSI?")
SendSIM("AT+CFGRI=?")
SendSIM("AT+CFGRI?")
SendSIM("AT+CMGF=1")
SendSIM("AT+CPMS=?")
SendSIM("AT+CPMS?")
SendSIM("AT+CNMI=?")
SendSIM("AT+CNMI?")
SendSIM("AT+CGFUNC=?")
SendSIM("AT+CGFUNC?")
b12 = 0
hserout 0,("AT+CMGL=",34,"ALL",34,13,10)
gosub PrintHser1
SendSIM("AT+CFGRI=?")
SendSIM("AT+CFGRI?")
end
PrintHser:
b12 = 12
PrintHser1:
w4 = 0
w5 = 0
ptr = 0
RepeatPrintHser:
do while ptr < hserptr
b8 = b9
b9 = b10
b10 = b11
b11 = @ptr
sertxd(@ptrinc)
loop
if b8 = "O" and b9 = "K" and b10 = 13 and b11 = 10 then EndPrintHser
pause 8000
if ptr < hserptr then RepeatPrintHser
if b12 = 0 then EndPrintHser
b12 = b12 - 1
sertxd(".")
goto RepeatPrintHser
EndPrintHser:
hserptr = 0
return
CheckNetwork:
' return status of NETLIGHT pin
' ON searching; call connected
' 200ms pulses = 4G
' 800ms pulses = 2G/3G
' OFF - nothing happening
' NETLIGHT pin is active low
' returns b0 = 0 OFF; b0 = 1 SEARCHING; b0 = 2 2G/3G; b0 = 4 4G
b0 = 1 - NetLightpin ' initial value (0=OFF, 1=active)
count NetLight,64000,w1
if w1 > 0 then ' pulsing
b0 = 2
if w1 > 5 then ' fast, so 4G
b0 = 4
endif
endif
sertxd(13,10,"Network status = ",#b0," Count = ",#w1)
return