這個直接用官方給的demo就可以
現在說個需求哈,是當初一個人給提出的需求
例如存入的號碼 姓名 號碼 1 10086 2 10010 ... .... 例如存入的號碼 01 0501 05代表所有的號碼循環撥打5次 01代表延時1小時後重複 GPIO4控制打電話(低電平有效) 開機以後先讀取手機卡里面的信息,篩選出來姓名1-99 和對應的號碼 取出01對應的次數 5 時間間隔 1小時 讀取完成以後如果GPIO4爲低電平,先撥打姓名1對應的號碼,如果後面還有2 間隔50S就會再撥打2對應的號碼,如果還有3,4,5....依次排着撥打 順序撥打完一遍 次數加1 順序撥打5次 延時1小時 然後 循環
直接源碼
module(...,package.seeall) require"cc" require"pb" require"sys" require"net" require"pins" require"common" --[[ GPIO4低電平撥打電話 GPIO5,GPIO6,GPIO7信號強度指示 ]] 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;--是否讀取號碼完成 InputKey = pio.P0_4;--輸入按鈕 Led1 = 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 --[[小於70小時,大於35小時使用]] function Delay35Hour() sys.timerStart(CallTelephoneLoop,(DelayHour-35) * 60 * 60 * 1000) end --[[小於100小時,大於70小時使用]] function Delay35HourA() sys.timerStart(CallTelephoneLoop,(DelayHour-70) * 60 * 60 * 1000) end --[[小於100小時,大於70小時使用]] function Delay35HourB() sys.timerStart(Delay35HourA,35 * 60 * 60 * 1000) end --[[撥打電話]] 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("撥打::"..ReadTelephoneTableCopy[j]); j=j+1; if j > CallMax then--循環了一遍 j = 1; CallCnt = CallCnt + 1; print("循環次數:"..CallCnt); end if CallCnt >= LoopCnt then--循環了設置的次數 CallCnt = 0; print("開始延時:"..DelayHour.."小時"); 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("循環"); sys.timerStart(CallTelephoneLoop,DelayCallValue) end end end --[[讀取號碼]] 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("信號強度:"..net.getRssi()) if net.getRssi() == 0 then pio.pin.setval(0,Led1);--用三個指示燈指示信號的強度 pio.pin.setval(0,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 --[[可以打電話]] local function CallReadyMethod() CallReadyFlage = 1; print("*****************************CALL_READY*****************************"); end ---對方接聽 -- string num,建立通話的對方號碼 local function connected(num) print("主動結束通話") cc.hangUp(num) end --結束通話 local 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)
其實邏輯處理也挺複雜的
源碼打包出售 https://item.taobao.com/item.htm?spm=a2126o.11854294.0.0.3e3a4831ODxjIk&id=582359919556
剩餘的大家自己去研究哈,也可以按照規定的存儲手機卡號碼,看看撥打情況
資料源碼鏈接
鏈接:https://pan.baidu.com/s/1-SRfsKGQ7rZVvFmp1ObHWw 密碼:p9qs
基礎教程源碼鏈接如果失效,請在淘寶介紹中下載,由於鏈接還是失效,請聯繫賣家,謝謝
https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-18540610442.6.36a74814ZSaRsu&id=569295486025