Tater 发表于 2013-7-8 13:11:28

解决Arduino联网问题

很多时候不能访问互联网,是因为DNS失败,或者DNS错误.

所以,可以人工修改DNS,方法是.

memset(ether.dnsip,8,4);

但是不一定能解决,这时候可以人工解决问题,电脑先解释IP,静态绑定.还能节省代码空间.

第一步,打开命令行提示符.

C:\Users\Tater>nslookup xxx.sinaapp.com //查自己域名
服务器:cache-b.guangzhou.gd.cn
Address:202.96.128.166

非权威应答:
名称:    sinaapp.com
Addresses:220.181.136.37
          220.181.136.36
Aliases:xxx.sinaapp.com

C:\Users\Tater>nslookup -qt=ns xxx.sinaapp.com//如果没有权威回答,查自己域名的DNS
服务器:cache-b.guangzhou.gd.cn
Address:202.96.128.166

非权威应答:
xxx.sinaapp.com      canonical name = sinaapp.com
sinaapp.com   nameserver = ns4.sinaapp.com
sinaapp.com   nameserver = ns1.sinaapp.com
sinaapp.com   nameserver = ns2.sinaapp.com
sinaapp.com   nameserver = ns3.sinaapp.com

C:\Users\Tater>nslookup -qt=a xxx.sinaapp.com ns4.sinaapp.com //查自己域名的权威解答,后面ns是上面的结果任意一个
服务器:UnKnown
Address:220.181.129.90

名称:    sinaapp.com
Addresses:220.181.136.36
          220.181.136.37
Aliases:xxx.sinaapp.com

在代码中定义:

static byte remoteIp[] = {220,181,136,36};

在代码中执行.

ether.copyIp(ether.hisip,remoteIp);

完整代码:

#include <EtherCard.h>

static byte mymac[] = {0x74, 0x69, 0x69, 0x3D, 0x37, 0x31};
static byte remoteIp[] = {220,181,136,36};
byte Ethernet::buffer;


char website[] PROGMEM = "xxx.sinaapp.com";

unsigned long previousMillis = 0;
unsigned long currentMillis;
static byte session_id;
byte actual_status;

void setup ()
{
    Serial.begin(38400);
   
    Serial.println("Initializing...");
   
    ether.begin(sizeof Ethernet::buffer, mymac, 10);
    ether.dhcpSetup();
    ether.copyIp(ether.hisip,remoteIp);
   
    ether.printIp("IP Address:\t", ether.myip);
    ether.printIp("Netmask:\t", ether.mymask);
    ether.printIp("Gateway:\t", ether.gwip);
    ether.printIp("DNS Server:\t", ether.dnsip);
    ether.printIp("Internet Gate:\t", ether.hisip);
       
}
页: [1]
查看完整版本: 解决Arduino联网问题