main.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "HZ201P"
  3. VERSION = "1.0.0"
  4. log.info("main", PROJECT, VERSION)
  5. -- 引入必要的库文件(lua编写), 内部库不需要require
  6. sys = require "sys"
  7. sysplus = require("sysplus")
  8. --运营商给的dns经常抽风,手动指定
  9. socket.setDNS(nil, 1, "223.5.5.5")
  10. socket.setDNS(nil, 2, "119.29.29.29")
  11. pm.ioVol(pm.IOVOL_ALL_GPIO, 1800)
  12. -- gnss的备电和gsensor的供电
  13. local vbackup = gpio.setup(24, 1)
  14. -- gnss的供电
  15. local gpsPower = gpio.setup(26, 1)
  16. -- 使用合宙iot平台时需要这个参数
  17. PRODUCT_KEY = "YXdzIDo5QawWCIRywShMAKjmJsInXtsb" -- 到 iot.openluat.com 创建项目,获取正确的项目id
  18. libfota = require "libfota"
  19. function fota_cb(ret)
  20. log.info("fota", ret)
  21. if ret == 0 then
  22. rtos.reboot()
  23. end
  24. end
  25. -- 使用合宙iot平台进行升级
  26. sys.subscribe("net_ready",function()
  27. libfota.request(fota_cb)
  28. sys.timerLoopStart(libfota.request, 3600000, fota_cb)
  29. end)
  30. --云平台逻辑
  31. require "cloud"
  32. --获取所有参数
  33. attributes = require "attributes"
  34. attributes.initial()--初始化
  35. --gnss
  36. require "gnss"
  37. -- Gsensor
  38. require "da267"
  39. sys.subscribe("STEP_COUNTER", function(step)
  40. log.info("STEP_COUNTER", step)
  41. if step > 0 then
  42. attributes.set("step", step)
  43. end
  44. end)
  45. -- LED
  46. --全局状态变量
  47. _G_CONNECTED = false
  48. local blueLed = gpio.setup(1, 0)
  49. local redLed = gpio.setup(16, 0, nil, nil, 4)
  50. local chargeState = gpio.setup(20, nil, 0)
  51. sys.taskInit(function()
  52. while true do
  53. if attributes.get("ledControl") then
  54. blueLed(attributes.get("blueLed") and 1 or 0)
  55. redLed(attributes.get("redLed") and 1 or 0)
  56. sys.wait(500)
  57. else
  58. redLed(chargeState() == 0 and 1 or 0)
  59. blueLed(1)
  60. sys.wait(_G_CONNECTED and 100 or 1000)
  61. blueLed(0)
  62. sys.wait(_G_CONNECTED and 100 or 1000)
  63. end
  64. end
  65. end)
  66. --电量检测与上报
  67. require "battery"
  68. --信号值检测与上报
  69. sys.taskInit(function ()
  70. while true do
  71. attributes.set("rsrp", mobile.rsrp())
  72. attributes.set("rsrq", mobile.rsrq())
  73. sys.wait(60000)
  74. end
  75. end)
  76. --拨打电话与音频
  77. require "ccVolte"
  78. -- SIM DETECT
  79. local simCheck = gpio.setup(41, function()
  80. log.info("sim status", gpio.get(41))
  81. end)
  82. -- 用户代码已结束---------------------------------------------
  83. -- 结尾总是这一句
  84. sys.run()