main.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 wlan and wlan.connect then
  17. -- wifi 联网, ESP32系列均支持
  18. local ssid = "luatos1234"
  19. local password = "12341234"
  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.SPI_2, 24000000, pin.PB03, pin.PC00, pin.PC03)
  32. w5500.init(spi.HSPI_0, 24000000, pin.PC14, pin.PC01, pin.PC00)
  33. log.info("auto mac", w5500.getMac():toHex())
  34. w5500.config() --默认是DHCP模式
  35. w5500.bind(socket.ETH0)
  36. -- LED = gpio.setup(62, 0, gpio.PULLUP)
  37. sys.wait(1000)
  38. -- TODO 获取mac地址作为device_id
  39. elseif mobile then
  40. -- Air780E/Air600E系列
  41. --mobile.simid(2)
  42. -- LED = gpio.setup(27, 0, gpio.PULLUP)
  43. device_id = mobile.imei()
  44. sys.waitUntil("IP_READY", 30000)
  45. end
  46. -- -- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
  47. -- if crypto.cipher_suites then
  48. -- log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
  49. -- end
  50. while true do
  51. print(ftp.login(nil,"121.43.224.154",21,"ftp_user","3QujbiMG").wait())
  52. print(ftp.command("NOOP").wait())
  53. print(ftp.command("SYST").wait())
  54. print(ftp.command("TYPE I").wait())
  55. print(ftp.command("PWD").wait())
  56. print(ftp.command("MKD QWER").wait())
  57. print(ftp.command("CWD /QWER").wait())
  58. print(ftp.command("CDUP").wait())
  59. print(ftp.command("RMD QWER").wait())
  60. print(ftp.command("LIST").wait())
  61. print(ftp.pull("/1222.txt","/1222.txt").wait())
  62. local f = io.open("/1222.txt", "r")
  63. if f then
  64. local data = f:read("*a")
  65. f:close()
  66. log.info("fs", "writed data", data)
  67. else
  68. log.info("fs", "open file for read failed")
  69. end
  70. print(ftp.command("DELE /12222.txt").wait())
  71. print(ftp.push("/1222.txt","/12222.txt").wait())
  72. print(ftp.close().wait())
  73. log.info("meminfo", rtos.meminfo("sys"))
  74. sys.wait(15000)
  75. end
  76. end)
  77. -- 用户代码已结束---------------------------------------------
  78. -- 结尾总是这一句
  79. sys.run()
  80. -- sys.run()之后后面不要加任何语句!!!!!