Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用AsyncUdpSocket通过UDP向Arduino发送UISlider值_Objective C_Udp_Arduino - Fatal编程技术网

Objective c 使用AsyncUdpSocket通过UDP向Arduino发送UISlider值

Objective c 使用AsyncUdpSocket通过UDP向Arduino发送UISlider值,objective-c,udp,arduino,Objective C,Udp,Arduino,我试图将UISlide值发送到Arduino Uno(带有wifi屏蔽)以控制连接的伺服 下面是我制作的Xcode。我使用的是AsyncUdpSocket类,也尝试了GCDAsyncUdpSocket。好的,我通过在收到每个值后清除缓冲区来让它工作。现在的问题是滞后:( -(无效)viewDidLoad { [超级视图下载]; mySocket=[[AsyncUdpSocket alloc]initWithDelegate:self]; gcdSocket=[[GCDAsyncUdpSocket

我试图将UISlide值发送到Arduino Uno(带有wifi屏蔽)以控制连接的伺服

下面是我制作的Xcode。我使用的是AsyncUdpSocket类,也尝试了GCDAsyncUdpSocket。好的,我通过在收到每个值后清除缓冲区来让它工作。现在的问题是滞后:(

-(无效)viewDidLoad { [超级视图下载];
mySocket=[[AsyncUdpSocket alloc]initWithDelegate:self]; gcdSocket=[[GCDAsyncUdpSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; mySlide.minimumValue=0; mySlide.maximumValue=180; //加载视图后,通常从nib执行任何其他设置。 }

-(iAction)slideValueChange:(UISlider*)发送方{
NSInteger值=lround(sender.value); myLabel.text=[NSString stringWithFormat:@“%d”,值]; NSString*地址=@“192.168.1.7”; UInt16端口=8888; NSData*myData=[myLabel.text dataUsingEncoding:NSUTF8StringEncoding]

-(无效)未收到记忆警告 { [超级记忆警告]; //处置所有可以重新创建的资源。 }

-(iAction)sendMessage:(id)发件人{

}

-(void)onUdpSocket:(AsyncUdpSocket*)sock didSendDataWithTag:(长)标记{

下面是我的arduino代码

伺服;
int状态=WL\U空闲\U状态;
char ssid[]=“Allcad”;//您的网络ssid(名称)
char pass[]=“gauravsoni”;
无符号int localPort=8888;
char PacketBuffer[UDP_TX_PACKET_MAX_SIZE];
WiFiUDP-Udp;
无效设置(){
Serial.begin(9600);
//检查是否存在屏蔽:
如果(WiFi.status()=无线无屏蔽){
Serial.println(“不存在WiFi屏蔽”);
//不要继续:
虽然(正确);
} 
//尝试连接到Wifi网络:
当(状态!=WL_已连接){
Serial.print(“试图连接到SSID:”);
序列号println(ssid);
//连接到WPA/WPA2网络。如果使用open或WEP网络,请更改此行:
状态=WiFi.begin(ssid,通过);
//等待10秒钟以进行连接:
延迟(10 000);
} 
Serial.println(“连接到wifi”);
printWifiStatus();
Serial.println(“\n正在启动与服务器的连接…”);
开始(localPort);
伺服装置(6);
}
void printWifiStatus(){
//打印您连接到的网络的SSID:
序列号。打印(“SSID:”);
Serial.println(WiFi.SSID());
//打印您的WiFi屏蔽的IP地址:
ip地址ip=WiFi.localIP();
串行打印(“IP地址:”);
序列号println(ip);
//打印接收到的信号强度:
长rssi=WiFi.rssi();
串行打印(“信号强度(RSSI):”;
串行打印(rssi);
Serial.println(“dBm”);
}
空循环(){
int packetSize=Udp.parsePacket();
if(包装尺寸)
{ 
Udp.read(PacketBuffer、Udp\u TX\u PACKET\u MAX\u SIZE);
int num=0;
num=atoi(PacketBuffer);
Serial.print(“新的num值为:”);
Serial.println(num);
servo.write(num);

对于(int i=0;i官方Arduino Wifi屏蔽上的UDP支持已知存在相当多的bug。在尝试任何其他操作之前,请确保通过简单的测试使其一致工作。您可以在此处找到有关我如何使其工作的更多信息:

请发布您的Arduinocode@Sr.Richie我已经发布了代码,我得到了arduino来接收mes智者,但有一个滞后的问题,大约一秒钟,虽然不多。你能即兴编写代码吗?谢谢
//[gcdSocket sendData:myData toHost:address port:port withTimeout:-1 tag:2];
  [mySocket  sendData:myData toHost:address port:port withTimeout:-1 tag:2];  
}
NSString *message = [[NSString alloc]init];
NSString * address = @"192.168.1.7";
message = @"test";

UInt16 port = 8888;

NSData * data = [message dataUsingEncoding: NSUTF8StringEncoding];


[mySocket  sendData:data toHost:address port:port withTimeout:-1 tag:1];
if (tag == 1){

    NSLog(@"something is happening !!");
}

else if (tag == 2){

NSLog(@"received message from slider");}}
Servo servo ;


int status = WL_IDLE_STATUS;
char ssid[] = "Allcad"; //  your network SSID (name) 
char pass[] = "gauravsoni"; 

unsigned  int localPort =  8888 ;

char PacketBuffer [ UDP_TX_PACKET_MAX_SIZE ] ;

WiFiUDP Udp;

void setup ()  { 

  Serial.begin(9600); 

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid,pass);

    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");

  Udp.begin(localPort);  

  servo.attach ( 6 ) ; 
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void loop ( )  {

  int packetSize = Udp.parsePacket() ; 
  if ( packetSize ) 
  { 
    Udp.read ( PacketBuffer , UDP_TX_PACKET_MAX_SIZE ) ;
    int num = 0; 

    num = atoi ( PacketBuffer ) ;

    Serial.print("New num value is: ");
    Serial.println(num);
    servo.write (num) ; 

     for(int i=0;i<3;i++)
    {
      Serial.println(i);
      PacketBuffer[i] = 0;
    }
  } 
  delay ( 5 ) ; 
}