|
|
|
@ -21,7 +21,7 @@ namespace RobotLib |
|
|
|
// test if IP valid |
|
|
|
// test if IP valid |
|
|
|
if (IPAddress.TryParse(brokerIp, out _)) |
|
|
|
if (IPAddress.TryParse(brokerIp, out _)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"mqtt setIp {brokerIp}"); |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"@esp:mqtt setIp {brokerIp}!"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -39,7 +39,7 @@ namespace RobotLib |
|
|
|
// test if mode is valid |
|
|
|
// test if mode is valid |
|
|
|
if (mode == "stationary" || mode == "s" || mode == "mobile" || mode == "m") |
|
|
|
if (mode == "stationary" || mode == "s" || mode == "mobile" || mode == "m") |
|
|
|
{ |
|
|
|
{ |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"challenge setMode {mode}"); |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"@esp:challenge setMode {mode}!"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -54,14 +54,22 @@ namespace RobotLib |
|
|
|
/// <param name="hostnameRobot">hostname or IP address of the robot</param> |
|
|
|
/// <param name="hostnameRobot">hostname or IP address of the robot</param> |
|
|
|
public static void RebootEsp32(string hostnameRobot) |
|
|
|
public static void RebootEsp32(string hostnameRobot) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"challenge reboot"); |
|
|
|
SendMessageUdp(hostnameRobot, udpPortRobot, $"@esp:challenge reboot!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void SendMessageUdp(string hostname, int port, string message) |
|
|
|
private static void SendMessageUdp(string hostname, int port, string message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var udpClient = new UdpClient(); |
|
|
|
var udpClient = new UdpClient(); |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
udpClient.Connect(hostname, port); |
|
|
|
udpClient.Connect(hostname, port); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (System.Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
log.Error($"Failed to send UDP message: {ex.Message}"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
byte[] data = Encoding.ASCII.GetBytes(message); |
|
|
|
byte[] data = Encoding.ASCII.GetBytes(message); |
|
|
|
udpClient.Send(data, data.Length); |
|
|
|
udpClient.Send(data, data.Length); |
|
|
|
|