main.lua 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "ftpdemo"
  3. VERSION = "1.0.0"
  4. --[[
  5. 本demo需要ftp库, 大部分能联网的设备都具有这个库
  6. ftp也是内置库, 无需require
  7. ]]
  8. -- sys库是标配
  9. _G.sys = require("sys")
  10. --[[特别注意, 使用ftp库需要下列语句]]
  11. _G.sysplus = require("sysplus")
  12. sys.taskInit(function()
  13. -----------------------------
  14. -- 统一联网函数, 可自行删减
  15. ----------------------------
  16. if rtos.bsp():startsWith("ESP32") then
  17. -- wifi 联网, ESP32系列均支持
  18. local ssid = "uiot"
  19. local password = "12345678"
  20. log.info("wifi", ssid, password)
  21. -- TODO 改成esptouch配网
  22. LED = gpio.setup(12, 0, gpio.PULLUP)
  23. wlan.init()
  24. wlan.setMode(wlan.STATION)
  25. wlan.connect(ssid, password, 1)
  26. local result, data = sys.waitUntil("IP_READY", 30000)
  27. log.info("wlan", "IP_READY", result, data)
  28. device_id = wlan.getMac()
  29. elseif rtos.bsp() == "AIR105" then
  30. -- w5500 以太网, 当前仅Air105支持
  31. w5500.init(spi.HSPI_0, 24000000, pin.PC14, pin.PC01, pin.PC00)
  32. log.info("auto mac", w5500.getMac():toHex())
  33. w5500.config() --默认是DHCP模式
  34. w5500.bind(socket.ETH0)
  35. LED = gpio.setup(62, 0, gpio.PULLUP)
  36. sys.wait(1000)
  37. -- TODO 获取mac地址作为device_id
  38. elseif rtos.bsp() == "EC618" then
  39. -- Air780E/Air600E系列
  40. --mobile.simid(2)
  41. LED = gpio.setup(27, 0, gpio.PULLUP)
  42. device_id = mobile.imei()
  43. sys.waitUntil("IP_READY", 30000)
  44. end
  45. -- -- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
  46. -- if crypto.cipher_suites then
  47. -- log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
  48. -- end
  49. while true do
  50. print(ftp.login(nil,"121.43.224.154",21,"ftp_user","3QujbiMG").wait())
  51. print(ftp.command("NOOP").wait())
  52. print(ftp.command("SYST").wait())
  53. print(ftp.command("TYPE I").wait())
  54. print(ftp.command("PWD").wait())
  55. print(ftp.command("MKD QWER").wait())
  56. print(ftp.command("CWD /QWER").wait())
  57. print(ftp.command("CDUP").wait())
  58. print(ftp.command("RMD QWER").wait())
  59. print(ftp.command("LIST").wait())
  60. print(ftp.pull("/1222.txt","/1222.txt").wait())
  61. local f = io.open("/1222.txt", "r")
  62. if f then
  63. local data = f:read("*a")
  64. f:close()
  65. log.info("fs", "writed data", data)
  66. else
  67. log.info("fs", "open file for read failed")
  68. end
  69. print(ftp.command("DELE /12222.txt").wait())
  70. print(ftp.push("/1222.txt","/12222.txt").wait())
  71. print(ftp.close().wait())
  72. log.info("meminfo", rtos.meminfo("sys"))
  73. sys.wait(15000)
  74. end
  75. end)
  76. -- 用户代码已结束---------------------------------------------
  77. -- 结尾总是这一句
  78. sys.run()
  79. -- sys.run()之后后面不要加任何语句!!!!!