Score
0
Watch 77 Star 332 Fork 69

合宙Luat / LuatOSLuaMIT

用 pm.request(pm.HIB) 休眠1个小时,经常 几分钟就被唤醒了,根本无法进入省电模式啊。

缺陷
已完成
zhangshan1aa  Opened this issue
-- LuaTools需要PROJECT和VERSION这两个信息
--PROJECT_KEY = "air302_nb11_demo1"


PROJECT = "air302_nb11_demo1"
VERSION = "1.0.3"
PROJECT_KEY = "gSnB9oj3Pv0BqFqOm1G3i3sTpeyq7YRE"



local sys = require "sys"
local jiu
local netc

local function print(...)
	_G.print("*== ",...)
end


--PRODUCT_KEY = "gSnB9oj3Pv0BqFqOm1G3i3sTpeyq7YRE"

-- 可以真正下载的
-- https://gitee.com/openLuat/LuatOS/releases/v0002_air302


local ci=0

adc.open(1) -- VBAT电压

--gpio.setup(12, function(val) print("IRQ_12") end, gpio.RISING)

-- gpio.close(pin)


local pin=9

local time22=os.time()

gpio.setup(pin,  nil, pull)



         local data1



-- 状态,如果是0 没有报警,如果是2  有报警了
local zhuang11=0

--[[





sys.taskInit(function()
   




   while 1 do



   local  result, data =  sys.waitUntil("xinhao11", 2000000)
 

 if result then
 
  print("udp1111111",result," ",data)
 
 end 




  --sys.wait(1000)	


    
    end
	
	
	
	
	

	
end)












sys.taskInit(function()


while 1 do





 --sys.publish("xinhao11","9999")

 




 sys.wait(1000000)


end





end)




]]

local iot_url = "http://iot.openluat.com/api/site/firmware_upgrade"
local ota_url = string.format("%s?project_key=%s&imei=%s&firmware_name=%s&version=%s", 
                        iot_url,
                        "gSnB9oj3Pv0BqFqOm1G3i3sTpeyq7YRE", 
                        nbiot.imei(),
                        PROJECT .. "_" .. rtos.firmware(),
                        VERSION
                    )

--print("ota", "url", ota_url)





local moren1="003600"

-- 5分钟休眠,发完数据  10秒休眠  local moren1="000300"

--nbiot.setPSM(1, tonumber(moren1), 8)




sys.taskInit(function()


    while 1 do
	   if socket.isReady() then
	   
            sys.wait(2000)
			
			
             netc = socket.udp()
			 
        -- netc:host("47.103.37.242")
        -- netc:port(8084)
			
			
			--netc:host("116.9.1.115")
   -- netc:port(8000)
			
			-- 第一连接上的时候 
            netc:on("connect", 
			function(id, re)
               
                if re then
      
				-- netc:send("IMEI:" .. nbiot.imei())
				 
				 
				 local ggs=nbiot.apn()
				 
				 print("udp2222 ", id, re,ggs)
				 
                  	netc:send("Q" .. nbiot.imei() .."5555222222")  
				 
                end
				
				
				
            end)
			
			
			
			
            netc:on("recv", function(id, data)
                print("udprecv ", #data, " ",data)
				
			--	os.remove("boot_time")
				
				
					 data=string.format("%06d",data)	
					


             netc:send(nbiot.imei() .."-"..data)  					
					 
				
             local     f = io.open("boot_time", "wb")

              f:write(tostring(data))
                f:close()
				

				
            end)
			
			
			
	
			
		
			  
			  
			  
			  --nbiot.rssi() 信号强度   nbiot.iccid()  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  	if netc:start() == 0 then
                while netc:closed() == 0 do
                   
			local 	result, data   sys.waitUntil("NETC_END_" .. netc:id(),1000)
					
                    if netc:closed() == 0 then
					
                      --  print("fa111", result," ", data  )
						
						--
                       
					  -- sys.wait(500) -- 
					   
					   	 local adc, adc1=adc.read(1)
						  
						  
						--  print("dianya ",adc,adc1 )
						
					
                         local zhuang =pm.lastReson()
						 
						 
                




                          local guanjiao= gpio.get(pin)

                    
					-- 000 开盒子,111 关闭盒子,   aaa 火警  bbb 无火警
					
					
					
					 print("zhuang guanjiao  ",zhuang," ",guanjiao )
					
					
					
			    local f1 = io.open("boot_time", "rb")
          
                   
				   if not f1 then
     
				
				   
				   -- 空的文件
				   print("kongkongkong")
				  local  f = io.open("boot_time", "wb")

              f:write(moren1)
                f:close()
				   
                   end	
			 			
						
						
						
				    local f1 = io.open("boot_time", "rb")
				  
				  if  f1 then							
				 data1 = tonumber(f1:read("*a"))
                   f1:close()
                    end 
						
						

						
					 data1=string.format("%06d",data1)	
						
						
						
						print("data1 ",data1)
					
	
					
						local sn=nbiot.imei()
					 
					  local time1=tonumber(os.time())+8*3600
					  
					  local qiang=nbiot.rssi()
					 
					qiang = string.format("%02d",qiang) 
					 
					 local dianya=tostring(adc1)
					 
					 dianya=string.format("%06d",dianya)
					 
					 
					 local caipin="000000"
					 
					 
					 

				
				
					 	
						
						
						
						
						
						
					
					local dianfa="002600"
					
				  local 	caipin2="000000"
					local caishijian="000000"
					
					local key1="00"
					
					local ICCID1=nbiot.iccid() 
					
					
				print("ICCID1 ",ICCID1)
					
					
					
					
					local difa='0000000000'
					local gaofa='0000000000'
					
					
					
					 if guanjiao==0  then
					 
					 
					 
					 
					 
					 
				--	if tonumber(os.time())-tonumber(time22)  >= tonumber(moren1) then
					 
					  -- 第一次或者 定时唤醒
					 
					   --  netc:send("Q" .. nbiot.imei() ..tostring(adc1).."111bbb")
						-- sys.wait(500) -- 等1秒在 休眠
						-- netc:send("Q" .. nbiot.imei() ..tostring(adc1).."111bbb")
					 
 local jie222=sn..time1..nbiot.imei()..qiang..dianya..caipin..data1..dianfa..caipin2..caishijian..key1..ICCID1.."111"..difa..gaofa..difa..gaofa
					 
					 
			netc:send(jie222)	

			sys.wait(500)
			netc:send(jie222)


 print("dataaaaaaa ",data1  )
 
--time22=os.time()

-- end 
 
 
 
		end 
					
			




-- 有报警 了
-- 有报警 了

-- 有报警 了

-- 有报警 了

-- 有报警 了

			if guanjiao==1 or  zhuang==2 then  --  1 就是有外部唤醒
					   -- 火警
  local jie222=sn..time1..nbiot.imei()..qiang..dianya..caipin..data1..dianfa..caipin2..caishijian..key1..ICCID1.."011"..difa..gaofa..difa..gaofa
			netc:send(jie222)	
			sys.wait(500)
			netc:send(jie222)
	          data1="000030"
				 print("data9999999999 ",data1)	 
					 end 
			-- 新的状态			 		
                     --  adc.close(1)
				   sys.wait(500) 
					               netc:clean()
                                  netc:close()
					   -- 等一秒,看看数据是否发送完成         pm.request(pm.DEEP)
			        --  sys.wait(1000) -- 等1秒在 休眠
					-- 升级
				http.get(ota_url, {dw="/update.bin"}, function(code,headers,body)
                if code == 200 then
                    -- 当且仅当服务器返回200时,升级文件下载成功
                    print("ota reboot!!")
                    rtos.reboot()
                else
                    print("ota resp", code, body)
                end
               end)

					-- 等  5秒在休眠,等数据发送完成
                      sys.wait(5000) 
                    print("data1a ",data1)
                    pm.dtimerStart(0, tonumber(data1)*1000) --5分钟唤醒
                    pm.request(pm.HIB) -- 建议休眠  DEEP
                    

                    --判断是否可以进休眠,如果请求失败,每隔10S请求一次
                    while false == pm.check() do
                        print("jie, ",pm.check())
                        sys.wait(2*1000) --延时10s
                        pm.request(pm.HIB) -- 建议休眠  DEEP
                    end
                  print("jie11, ",pm.check())
					 -- pm.request(pm.DEEP) 
			           --pm.force(pm.HIB)	  
				--	sys.wait(tonumber(data1)*1000) -- 5分钟 
				   end				
            end              --- while 了
            netc:clean()
			   print("dddddddddd")
            netc:close()
            sys.wait(tonumber(data1)*1000) --延时5分钟
        else
		 print("44444444444")
      sys.wait(2000)
      end
   end
   end
end)

-- 结尾总是这一句哦
sys.run()
Attachments
4674 wendal 1578914274 total 3 participants

Comments (8)

zhangshan1aa 2020-09-17 14:55

Wendal 你好像啥都不该啊。

zhangshan1aa 2020-09-17 14:58

Wendal 你好像啥都不没改啊

4674 wendal 1578914274
Wendal 2020-09-17 15:13 owner

改了markdown格式, 这个问题已经知晓, 需要上游厂商解决sdk的bug, 仍需要等待

4674 wendal 1578914274
Wendal 2020-09-17 15:13 owner

如果急需, 可以参考 demo/ctiot, 使用 pm.dtimer_check 判读是否为id=0,如果不是就继续休眠, 不执行业务逻辑

zhangshan1aa 2020-09-17 18:25

用 pm.dtimer_check 检查是 0,可以进入休眠,关键的问题是,正常休眠是24小时才定时唤醒,实际是 几分钟就被莫名其妙唤醒了,耗电量大了很多啊。

4674 wendal 1578914274
Wendal 2020-09-17 20:18 owner

Air302模块LuatOS测试pm温柔休眠功能,请使用cmnbiot2的nb卡,开卡时psm参数选择1min精度,就可以按照pm.dtimer定时时间唤醒

alien2017 2020-09-17 20:34 member

日志发出来看看

4674 wendal 1578914274
Wendal 2020-10-13 12:02 owner

已在QQ群里提供休眠的新demo

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority