Article From:https://www.cnblogs.com/yangfengwu/p/9969179.html

https://www.cnblogs.com/yangfengwu/p/9968883.html

This demo can be used directly from the government.

 

 Now let’s talk about the need. It’s the demand that one person put forward at the time.

For example, the number depositedName and Number1 10086
2 10010
... ....

 

For example, the number deposited01 0501 05Represent all numbers and dial 5 times 01 repeatedly. Repeat after 1 hour delay.GPIO4 Controlled Call (Low Level Effective)Read the information in the cell phone card after booting, and screen out the name 1-99 And the corresponding numberNumber of times to take out 015 Time interval 1 hourAfter reading, if GPIO4 is low level, first dial the number corresponding to Name 1, and then dial the number corresponding to 2 if there are two intervals of 50S, and if there are three,4,5....Dial in turnSequential dialing once plus 1 sequential dialing 5 times with 1 hour delay and then cycle

 

Direct source code

module(...,package.seeall)
require"cc"
require"pb"
require"sys"
require"net"
require"pins"
require"common"

--[[
GPIO4Low-level dialingGPIO5, GPIO6, GPIO7 Signal Intensity Indicators]]Local function print (...)_G.print ("testCall",...)
end

local ReadTelephoneTable={};
local ReadTelephoneTableCopy={};
local ReadTelephoneCnt=1;
local ReadErr=0;
local LoopCnt=0;
local DelayHour=0;
local CallReadyFlage=0;
local j=1;
local CallMax = 0;
local CallCnt = 0;
local DelayCallValue = 50000;
local InputState = 0;
local ReadTelephoneSuccess = 0;--Read Number CompletedInputKey= pio.P0_4;--Input buttonLed1= pio.P0_5;--Led1
Led2 = pio.P0_6;--Led2
Led3 = pio.P0_7;--Led3
pio.pin.setdir(pio.OUTPUT,InputKey)
pio.pin.setval(1,InputKey)

pio.pin.setdir(pio.OUTPUT,Led1)
pio.pin.setval(1,Led1)

pio.pin.setdir(pio.OUTPUT,Led2)
pio.pin.setval(1,Led2)

pio.pin.setdir(pio.OUTPUT,Led3)
pio.pin.setval(1,Led3)


function ReadTelephone()
    pb.read(ReadTelephoneCnt, readcb)
end

--[[Less than 70 hours, more than 35 hours]]Function Delay35 Hour ()Sys. timerStart (Call Telephone Loop, (Delay Hour)-35) * 60 * 60 * 1000) 
end
--[[Less than 100 hours, more than 70 hours]]Function Delay35 HourA ()Sys. timerStart (Call Telephone Loop, (Delay Hour)-70) * 60 * 60 * 1000)
end
--[[Less than 100 hours, more than 70 hours]]Function Delay35 HourB ()Sys. timerStart (Delay35 HourA,35 * 60 * 60 * 1000)
end

--[[Call]Function CallTelephoneLoop ()if  j<= CallMax and CallMax>=1 and DelayHour >= 1 and LoopCnt>=1 then
        cc.dial(ReadTelephoneTableCopy[j]);
        sys.timerStart(cc.hangUp,30000,ReadTelephoneTableCopy[j])
        print("Dial::"..ReadTelephoneTableCopy[j]);
        j=j+1;
        if  j > CallMax  then--Cycle it overJ= 1;
            CallCnt = CallCnt + 1;
            print("Number of cycles:"..CallCnt);
        end
        if  CallCnt >= LoopCnt  then--Number of cycles of settingsCallCnt= 0;
            print("Start delay:"..DelayHour.."hour");
            if  DelayHour <=35  then
                sys.timerStart(CallTelephoneLoop,DelayHour * 60 * 60 * 1000)
            elseif  DelayHour <=70  then
                sys.timerStart(Delay35Hour,35 * 60 * 60 * 1000)
            elseif  DelayHour <=100  then
                sys.timerStart(Delay35HourB,35 * 60 * 60 * 1000)
            end
        else
            print("loop");
            sys.timerStart(CallTelephoneLoop,DelayCallValue)
        end
    end
end


--[[Read Number]]Function readcb (result, name, number)if  result == true  then
        ReadTelephoneCnt = ReadTelephoneCnt +1;
        print(result,name,number);
        print("ReadTelephoneCnt"..ReadTelephoneCnt);
        if  string.len(name)>0  then
            ReadErr = 0;
            if  string.len(number)>0  then
                ReadErr = 0;
                ReadTelephoneTable[name] = number;
            end
        else
            if  string.len(number)==0 and string.len(name)==0 then
                print("ReadErr = ReadErr +1");
                ReadErr = ReadErr +1;
                if  ReadErr>5  then
                    ReadErr = 0;
                    sys.timerStop(ReadTelephone,1);
                    print("timerStop");
                    local i=1;
                    for key,value in pairs(ReadTelephoneTable) do
                        print(key,value)
                        if  key == "01" then
                            LoopCnt = tonumber(string.sub(value,1,2))
                            if  LoopCnt>99 or LoopCnt<1 then
                                LoopCnt = 0;
                            end
                            DelayHour = tonumber(string.sub(value,3,4))
                            if  DelayHour>99 or DelayHour<1 then
                                DelayHour = 0;
                            end
                            print("DelayHour"..DelayHour)  
                        else
                            print("key"..key)  
                            if  tonumber(key)~=nil and tonumber(key) <99 and tonumber(key)>0  then
                                ReadTelephoneTableCopy[i] = value;
                                i = i + 1;
                            end
                        end
                    end
                    CallMax = i - 1;
                    ReadTelephoneSuccess  = 1;
                end
            end
        end
        if  string.len(number)>0 then
            ReadErr = 0;    
            print("string.len(number)>0 ReadErr = 0");
        end
    else
        print(result,name,number);
    end
end

local InputCnt = 0;
local cnt = 0;
function  InputShowLed()
    if  pio.pin.getval(InputKey) == 0 then
        InputCnt = InputCnt +1;
        if  InputCnt>6 and InputState==0 then
            InputCnt = 0;
            if  ReadTelephoneSuccess == 1  then
                InputState = 1;
                j=1;
                CallCnt = 0;
                sys.timerStopAll(CallTelephoneLoop)
                sys.timerStart(CallTelephoneLoop,1)
            end
        end
    else
        InputCnt = 0;
        InputState = 0;
        sys.timerStopAll(CallTelephoneLoop)
    end
    cnt = cnt +1;
    if  cnt>100  then
        cnt = 0;
        print("Signal strength:"..net.getRssi())
        if  net.getRssi() == 0  then
            pio.pin.setval(0,Led1);--Indicating signal strength with three indicator lightsPio. pin. SETVAL0,Led2);
            pio.pin.setval(0,Led3); 
        elseif  net.getRssi()<10 then
            pio.pin.setval(0,Led1);
            pio.pin.setval(0,Led2);
            pio.pin.setval(1,Led3); 
        elseif  net.getRssi()<20 then
            pio.pin.setval(0,Led1);
            pio.pin.setval(1,Led2);
            pio.pin.setval(1,Led3); 
        elseif  net.getRssi()>20 then
            pio.pin.setval(1,Led1);
            pio.pin.setval(1,Led2);
            pio.pin.setval(1,Led3); 
        end
    end
end

--[[You can make a phone call] uuuuuuuuuuuLocal function CallReadyMethod ()CallReadyFlage= 1;
    print("*****************************CALL_READY*****************************");
end
---The other party answered.-- string num,Establish the dialog number of the callLocal function connection (num)Print ("Take the initiative to end the call")
    cc.hangUp(num)
end

--End CallLocal function disconnected (para)Print ("disconnected:"..(para or "nil"))
end

sys.timerLoopStart(ReadTelephone,1000,1)
sys.subscribe("CALL_CONNECTED",connected)
sys.subscribe("CALL_READY",CallReadyMethod)
sys.subscribe("CALL_DISCONNECTED",disconnected)
sys.timerLoopStart(InputShowLed,10)
cc.dtmfDetect(true)

 

 

In fact, logic processing is also quite complicated.

 

 

 

 

 

 

 Source code packaged for sale: https://item.taobao.com/item.htm? SPM = a2126o.11854294.0.0.3e3a4831ODxjIk& id = 582359919556

 The rest of us can study it by ourselves, or we can store the cell phone card number according to the stipulation to see the dialing situation.

Source Link

Link: https://pan.baidu.com/s/1-SRfsKGQ7rZVvFmp1ObHWw password: p9qs

If the link of the source code of the basic course is invalid, please download it in the introduction of Taobao. Because the link is still invalid, please contact the seller. Thank you.

https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-18540610442.6.36a74814ZSaRsu&id=569295486025

 

Link of this Article: 18-GPRS (Air202) Call

Leave a Reply

Your email address will not be published. Required fields are marked *