![](/img/trans.png)
[英]ENC28J60 (EtherCard) and SD card (SdFat) at the same time on Arduino Mega
[英]Arduino - ENC28J60 - EtherCard.h - Compile Error - 'word homePage()' was declared 'extern' and later 'static' [-fpermissive]
我试图编译并运行此示例。 但是我得到这个错误。
“退出状态1'word homePage()'被声明为'extern',随后被声明为'static'[-fpermissive]”
#include <EtherCard.h>
static byte mymac[] = {0x65,0x77,0x33,0x2D,0x30,0x66};
static byte myip[] = {192,168,0,99};
byte Ethernet::buffer[500];
BufferFiller bfill;
static word homePage() {
bfill = ether.tcpOffset();
bfill.emit_p( PSTR (
"HTTP/1.0 503 test page\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Arduino test page"
"</title></head>"
"<body>"
"<h3>Test</h3>"
"<p>Test</p>"
"</body>"
"</html>"
)) ;
return bfill.position();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial.println("TEST");
Serial.println();
Serial.print("Status: ");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) {
Serial.println( "Failed to access Ethernet controller");
}
else {
Serial.println( "Ethernet controller OK!");
ether.staticSetup(myip);
ether.dhcpSetup();
}
Serial.println();
ether.printIp("My IP: ", ether.myip);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
}
void loop() {
// put your main code here, to run repeatedly:
word pos = ether.packetLoop(ether.packetReceive());
if (pos){
for (int i=pos;Ethernet::buffer[i]; i++) {
Serial.print((char)Ethernet::buffer[i]);
Serial.println();
ether.httpServerReply(homePage());
}
}
}
代码或库有问题吗? 该示例是从网上复制的。 库已更新。
您能帮我解决这个问题吗? 如何解决?
看来homePage
函数是在标头中声明的,而没有storafe类说明符static
。
但是,然后使用存储类说明符static
定义它
static word homePage() {
//...
编译器会报告这种不一致的情况。
我认为您可以在函数定义中删除static
的存储类说明符。
另一种方法是将一个函数声明与存储类的static
的头之前。 在这种情况下,功能将具有内部链接。
arduino gui使用的工具中的更改可能容忍度低于以前,并且库已更新。
看来您的图书馆已经过时,在github存储库中搜索主页只会显示3个文件,所有这些都是示例。
https://github.com/jcw/ethercard/search?utf8=%E2%9C%93&q=homepage
请检查我提供的代码。 它与让·克劳德·维珀 ( Jean-Claude Wipper)的Github页面提供的草图相同,除了我始终必须为“ ether.begin ”功能提供片选引脚 ,否则我的ENC28J60无法响应。
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
// Connection Diagram: http://i.stack.imgur.com/SvG7J.jpg
#include <EtherCard.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#define CS_PIN 10
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Service Temporarily Unavailable"
"</title></head>"
"<body>"
"<h3>This service is currently unavailable</h3>"
"<p><em>"
"The main server is currently off-line.<br />"
"Please try again later."
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(9600);
Serial.println("\n[backSoon]");
if (ether.begin(sizeof Ethernet::buffer, mymac, CS_PIN) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
基本任务
上传草图之前,首先需要使用LAN电缆将ENC28J60模块连接到PC,或者也可以连接到路由器。 现在主要部分来了。 变量“ gwip ”必须与您的网关IP地址匹配。
获得网关IP后,将其写入“ gwip”变量并上传您的草图:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.