The function setwifi ()
Wifi. Setmode (wifi. SOFTAP)
MAC=wifi. Ap. Getmac ()
The local CFG={}
CFG. Ssid="car_".. MAC
CFG. PWD="0123456789"
Wifi. Ap. Config (CFG)
End
The function setpwm ()
,50,0 PWM. The setup (1)
PWM. The setup (2,50,0)
PWM. The setup (4,50,0)
PWM. The setup (6,50,0)
PWM. The setup (7,50,0)
PWM. Start (1)
PWM. Start (2)
PWM. Start (4)
PWM. Start (6)
PWM. Start (7)
End
The function motorpwm (value) index,
If the value then
- print (value) index,
PWM. Setduty (value) index,
End
End
The function setTcpServer ()
Sv=net. CreateServer (net. TCP)
Sv: listen (8000,
The function (c)
C: on (" receive ", function (c, pl)
- print (pl)
The local t=sjson. Decode (pl)
- for a, b in pairs (t) do
- print (a, b)
- end
Motorpwm (1, t [" p1 "])
Motorpwm (2, t [" p2 "])
Motorpwm (4, t [" p3 "])
Motorpwm (6, t [" p4 "])
Motorpwm (7, t [" p5 "])
C: the send (" data received ")
End)
C: the send (" hello car controler \ n ")
End
)
End
flag=0;
Wifi. Eventmon. Register (wifi. Eventmon. AP_STACONNECTED, function (T)
Print (" \ n \ tAP - STATION CONNECTED "). "\ n \ tMAC:".. T.M AC.. "\ n \ tAID:".. T.A ID)
If (flag==0) then
SetTcpServer ()
flag=1;
End
End)
Setpwm ()
Setwifi ()
CodePudding user response:
Lua code, behind softap that understand, look not to understand