Hi guys, i'm fairly new at programming and i'm getting some errors with my code.
can't figure out what's wrong with it and why i'm getting compiler errors and also i'd appreciate if you find other problems with it to let me know so i can correct them...
Cheers ![]()
dadada.ino
#include "NTPTime.h"
#define SECONDS_IN_DAY 86400
#define START_YEAR 1900
#define TIME_ZONE +1
//static int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
PROGMEM const static char website[] = "time.google.com";
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
//uint32_t timeStamp;
//boolean requestSent;
//byte Ethernet::buffer[700];
//BufferFiller bfill;
void setup () {
Serial.begin(57600);
Serial.println("NTP Demo");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
else
Serial.println("DHCP configuration done");
ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.netmask);
ether.printIp("Gateway:\t", ether.gwip);
if(ether.dnsLookup (website, false)){
Serial.println( "dnsLookup ok");
}else{
Serial.println( "dnsLookup faild");
}
ether.printIp("SRV: ", ether.hisip);
//ether.printIp("Old: ",ntpServer);
//ether.copyIp(ntpServer, ether.hisip );
//ether.printIp("New: ",ntpServer);
Serial.println();
}
void loop() {
}
NTPTime.cpp
#include "NTPTime.h"
void NTPTime::initialSetup (EtherCard ether) {
this->_ether = ðer;
if (ether.dnsLookup (ntpServerAddress, false)) {
Serial.println( "dnsLookup ok");
} else {
Serial.println( "dnsLookup faild");
}
requestSent = false;
}
String NTPTime::printDate(uint32_t timeStamp) {
String fullFormatedDate = "";
unsigned int year = START_YEAR;
while (1) {
uint32_t seconds;
if (isLeapYear(year)) seconds = SECONDS_IN_DAY * 366;
else seconds = SECONDS_IN_DAY * 365;
if (timeStamp >= seconds) {
timeStamp -= seconds;
year++;
} else break;
}
unsigned int month = 0;
while (1) {
uint32_t seconds = SECONDS_IN_DAY * days_in_month[month];
if (isLeapYear(year) && month == 1) seconds = SECONDS_IN_DAY * 29;
if (timeStamp >= seconds) {
timeStamp -= seconds;
month++;
} else break;
}
month++;
unsigned int day = 1;
while (1) {
if (timeStamp >= SECONDS_IN_DAY) {
timeStamp -= SECONDS_IN_DAY;
day++;
} else break;
}
unsigned int hour = timeStamp / 3600;
unsigned int minute = (timeStamp - (uint32_t)hour * 3600) / 60;
unsigned int second = (timeStamp - (uint32_t)hour * 3600) - minute * 60;
hour = hour + 2;
fullFormatedDate = String(year) + "" + String(month) + "" + String(day) + "" + String(hour) + "" + String(minute);
return fullFormatedDate;
}
boolean NTPTime::isLeapYear(unsigned int year) {
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
String NTPTime::getfullformatedtime() {
NTPTime ntp;
String fullTime = "";
ether.ntpRequest(ether.hisip, srcPort);
delay(100);
ether.packetLoop(ether.packetReceive());
ether.ntpProcessAnswer(this->timeStamp, srcPort);
fullTime = ntp.printDate(timeStamp);
return fullTime;
}
NTPTime.h
#pragma once
#include "Arduino.h"
#include <EtherCard.h>
#define SECONDS_IN_DAY 86400
#define START_YEAR 1900
#define TIME_ZONE +1
#define INTERVAL 10000
class NTPTime {
private:
EtherCard* _ether;
BufferFiller bfill;
unsigned long lastTime = 0;
uint32_t timeStamp;
boolean requestSent;
public:
void initialSetup (EtherCard ether);
String printDate(uint32_t timeStamp);
boolean isLeapYear(unsigned int year);
String getfullformatedtime();
};
static int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
PROGMEM const static char ntpServerAddress[] = "time.google.com";
static byte ntpServer[] = {193, 204, 114, 232};
static byte srcPort = 0;
byte Ethernet::buffer[700];
Error
sketch\dadasadsa.ino.cpp.o (symbol from plugin): In function `setup':
(.text+0x0): multiple definition of `ENC28J60::buffer'
sketch\NTPTime.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "EtherCard.h"
Used: C:\Users\Eli\Documents\Arduino\libraries\EtherCard
exit status 1
Error compiling for board Arduino Nano.