极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17888|回复: 12

请教w5100的问题

[复制链接]
发表于 2012-11-15 19:20:53 | 显示全部楼层 |阅读模式

请教一下w5100的问题
1
用w5100 发送数据,已经把print的参数组成了一个字符串,串口打印证明组的没问题。用client.print ,去服务器抓包一看,一个字符串被分成了N多个tcp 报文发出去了,有的就一两个字节。这效率有点低啊,请问有啥办法设置w5100的输入字符个数。
2

看介绍说w5100 支持做多4条连接,请问怎么可以同时建立两条链接。

我建立了两个client1 client2,针对不同的端口。但是发现一条建立以后,另一条就建立不起来了。


回复

使用道具 举报

 楼主| 发表于 2012-11-16 09:26:06 | 显示全部楼层
只能顶起来了。
回复 支持 反对

使用道具 举报

发表于 2012-11-16 09:42:49 | 显示全部楼层
业余帮顶
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-17 10:27:49 | 显示全部楼层
再顶一下吧
回复 支持 反对

使用道具 举报

发表于 2012-12-7 09:47:19 | 显示全部楼层
弱弱地问一下,MEGA8的Arduino板子有没有基于W5100的以太网库?
回复 支持 反对

使用道具 举报

发表于 2012-12-21 12:00:09 | 显示全部楼层
Veiko 发表于 2012-12-7 09:47
弱弱地问一下,MEGA8的Arduino板子有没有基于W5100的以太网库?

w5100的库是最全的。Arduino的开发软件安装后即可使用。
回复 支持 反对

使用道具 举报

发表于 2012-12-21 12:05:32 | 显示全部楼层
第一个问题:
不知道楼主是不是把串口数据透传到以太网上?如果是的话,需要把接收到的串口数据打一下包。因为串口数据是按字节传送的,如果收到串口数据就send的话,就会出现楼主所说的现象。我以前也遇到过。

第二个问题:
楼主说的很对。要想用多个口的话,要区分一下socket号就可以了。比如:connect(0,ipaddress, port number); connect(1, ipaddress, port number);
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-21 20:54:59 | 显示全部楼层
终于有人搭理我了,
请教:
问题1: arduino 确实是通过串口与w5100通信的吧,怎么打包一起送过去呢?
问题2:我实验建立一个连接以后,第二条是建立不起来的,明天我再试一下。

感谢回复。
回复 支持 反对

使用道具 举报

发表于 2012-12-21 22:51:04 | 显示全部楼层
我用w5100+Mega2560的,遇到这个问题不得求解
回复 支持 反对

使用道具 举报

发表于 2012-12-25 09:01:52 | 显示全部楼层
laoliu1982 发表于 2012-12-21 20:54
终于有人搭理我了,
请教:
问题1: arduino 确实是通过串口与w5100通信的吧,怎么打包一起送过去呢?

问题1:Arduino是通过SPI和W5100通信的,并非UART串口。如果想把串口数据打包的话,你可以定义一个定长缓存,缓存满后,发送即可。
问题2:请确认W5100的socket号。
回复 支持 反对

使用道具 举报

发表于 2012-12-25 09:02:31 | 显示全部楼层
流泉漫舞 发表于 2012-12-21 22:51
我用w5100+Mega2560的,遇到这个问题不得求解

Mega2560也是一样的,多看一下Arduino提供的库,他们的库写的很好。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-26 10:56:34 | 显示全部楼层
皮皮 发表于 2012-12-25 09:02
Mega2560也是一样的,多看一下Arduino提供的库,他们的库写的很好。

不好意思没看懂:这个是arduino cosm client 的例子

    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.println("Host: api.cosm.com");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = 8 + getLength(thisData);
    client.println(thisLength);

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.print("sensor1,");
    client.println(thisData);

我尝试把 client.print的内容组成一个字符串一起 cient.print  ,还是一个字节一个字节发出去的,能仔细解释一下怎么开一个缓冲么? 是要改写库函数么?
回复 支持 反对

使用道具 举报

发表于 2012-12-27 10:06:15 | 显示全部楼层
刚才去arduino网站看了一下你说的例子,上面你说的程序应该是这个函数里面的:
// this method makes a HTTP connection to the server:
void sendData(int thisData) {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.println("Host: api.pachube.com");
    client.print("X-PachubeApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = 8 + getLength(thisData);
    client.println(thisLength);

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.print("sensor1,");
    client.println(thisData);
  
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
   // note the time that the connection was made or attempted:
  lastConnectionTime = millis();
}
sendData()这个函数应该是发送数据的,由于arduino上的AVR单片机内存有限,没法一下子发送过多的数据,例如超过128字节。但是W5100有2K的发送缓存,除了W5100自带协议栈,这也是arduino选用W5100的一个原因,同时也是W5100最大的特点,可以当单片机的外设,对单片机的性能没什么要求。

据我理解,正确的方法应该是利用client.print是把数据写入W5100的缓存,待全部数据写入后,给W5100一个发送命令,这样所有的数据就会按照一个包发送出去。
如果想你说的那样client.print就直接把数据送出去的话,我想应该是arduino库的bug吧。
以前用过arduino。目前手头没有arduino板子,不能帮你测一下了^^
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-20 02:46 , Processed in 0.043565 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表