#include <Servo.h>
#include <SPI.h>
#include <Ethernet.h>
Servo myservo1;
int pos1 = 90;
int rssi=0,rssi1=0,lastrssi=0;
String comdata = "";
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,10);
IPAddress server(192,168,1,23);
EthernetClient client;
void setup()
{
myservo1.attach(9);
myservo1.write(pos1);
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.print("My ip : ");
Serial.println(Ethernet.localIP());
client.connect(server,23);
if (client.connect(server,23))
Serial.println("connected");
delay(1000);
client.println("ubnt");
delay(1000);
client.println("ubnt");
delay(1000);
}
void loop()
{
client.println("mca-status | grep signal=");
while(client.available())
{
comdata+=char(client.read());
delay(1);
}
int sIndex = comdata.indexOf("signal=-");
if(sIndex==-1)
{
return;
}
String charRssi=comdata.substring(sIndex+8,sIndex+10);
int rssi1=charRssi.toInt();
rssi=rssi1;
Serial.println(rssi);
Serial.println(lastrssi);
//delay(1000);
comdata = "";
if(lastrssi!=0)
{
if(rssi>lastrssi)myservo1.write(pos1=pos1-10);
if(rssi<lastrssi)myservo1.write(pos1=pos1+10);
Serial.println(pos1);
}
lastrssi=rssi;
delay(1000);
}
你好,这是我提取信号强度并通过一次比较控制舵机左右转,可以接着这个进行PID 么?
|