极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9964|回复: 0

解决Arduino联网问题

[复制链接]
发表于 2013-7-8 13:11:28 | 显示全部楼层 |阅读模式
很多时候不能访问互联网,是因为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);

完整代码:

  1. #include <EtherCard.h>

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


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

  6. unsigned long previousMillis = 0;
  7. unsigned long currentMillis;
  8. static byte session_id;
  9. byte actual_status;

  10. void setup ()
  11. {
  12.     Serial.begin(38400);
  13.    
  14.     Serial.println("Initializing...");
  15.    
  16.     ether.begin(sizeof Ethernet::buffer, mymac, 10);
  17.     ether.dhcpSetup();
  18.     ether.copyIp(ether.hisip,remoteIp);
  19.      
  20.     ether.printIp("IP Address:\t", ether.myip);
  21.     ether.printIp("Netmask:\t", ether.mymask);
  22.     ether.printIp("Gateway:\t", ether.gwip);
  23.     ether.printIp("DNS Server:\t", ether.dnsip);
  24.     ether.printIp("Internet Gate:\t", ether.hisip);
  25.        
  26. }
复制代码
回复

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 14:25 , Processed in 0.048565 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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