Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. pk1=0
  2. pk2=1
  3. pk3=2
  4. pk4=3
  5.  
  6. gpio.mode(pk1, gpio.OUTPUT);
  7. gpio.mode(pk2, gpio.OUTPUT);
  8. gpio.mode(pk3, gpio.OUTPUT);
  9. gpio.mode(pk4, gpio.OUTPUT);
  10. gpio.write(pk1,gpio.LOW);
  11. gpio.write(pk2,gpio.LOW);
  12. gpio.write(pk3,gpio.LOW);
  13. gpio.write(pk4,gpio.LOW);
  14. uart.setup(0,9600,8,0,1)
  15. --==========================================
  16. print("Teraz skanuje adresy IP:")
  17.  
  18.  
  19.  
  20. AP_CFG={}
  21.  
  22. AP_CFG.ssid="misiumisiu1"
  23. AP_CFG.pwd="123456789"
  24.  
  25. AP_CFG.hidden = 0
  26.  
  27. AP_CFG.max=4
  28.  
  29. AP_CFG.beacon=100
  30.  
  31.  
  32. AP_IP_CFG={}
  33. AP_IP_CFG.ip="192.168.4.1"
  34. AP_IP_CFG.netmask="255.255.255.0"
  35. AP_IP_CFG.gateway="192.168.4.1"
  36.  
  37. AP_DHCP_CFG ={}
  38. AP_DHCP_CFG.start = "192.168.4.2"
  39.  
  40. wifi.setmode(wifi.SOFTAP)
  41.  
  42. wifi.ap.config(AP_CFG)
  43.  
  44. wifi.ap.setip(AP_IP_CFG)
  45.  
  46. wifi.ap.dhcp.config(AP_DHCP_CFG)
  47.  
  48. wifi.ap.dhcp.start();
  49. print(wifi.ap.getip());
  50. tmr.delay(1000000)
  51.  
  52. tmr.alarm(0, 2000, tmr.ALARM_AUTO, function()
  53. for mac,ip in pairs(wifi.ap.getclient()) do
  54. print(mac,ip)
  55. if (ip=="192.168.4.2") then
  56. print("Pilot ok "..ip);
  57. tmr.stop(0);
  58. end
  59. end
  60. end)
  61.  
  62. sv = net.createServer(net.TCP, 30)
  63.  
  64. function receiver(sck, data)
  65.  
  66. str = string.sub(data,string.find(data,"GET /")
  67. +5,string.find(data,"HTTP/")-2)
  68.  
  69. print(str)
  70. if (str=="led1") then print("led1")
  71. gpio.write(pk1,gpio.LOW) end
  72. if (str=="led2") then print("led2")
  73. gpio.write(pk1,gpio.HIGH) end
  74. if (str=="led3") then print("led3")
  75. gpio.write(pk2,gpio.LOW) end
  76. if (str=="led4") then print("led4")
  77. gpio.write(pk2,gpio.HIGH) end
  78. if (str=="led5") then print("led5")end
  79. if (str=="led6") then print("led6")end
  80. if (str=="led7") then print("led7")end
  81. if (str=="led7") then print("led7")end
  82.  
  83. if (str=="exit") then file.remove("init.lua") end
  84. sck:close()
  85. end
  86.  
  87. if sv then
  88. sv:listen(80, function(conn)
  89. conn:on("receive", receiver)
  90. conn:send("Witaj przybyszu")
  91. end)
  92. end
  93.  
  94. uart.on("data", "\r",
  95. function(data)
  96. print(recvdata)
  97. end, 0)
  98.  
  99. function sciemnianie(szybkosc)
  100. if(szybkosc==1)then
  101. if(val<500)then val=val+20 end
  102. pwm.setduty(pwm2, val)
  103. end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement