Could someone please explain what changed recently to start giving me errors in code which I have previously compiled and uploaded to an Arduino Etherten? Was using Arduino 1.0.1 but after the errors I have tried 1.0.5.
The errors seem to relate to time, I did update libraries but these were EthernetUDP.h and a few others not time.h.
Sample of error message:
code:38: error: 'time_t' does not name a type
code.ino: In function 'void loop()':
code:83: error: 'now' was not declared in this scope
code:117: error: 'prevDisplay' was not declared in this scope
code.ino: In function 'int updatePVoutput()':
code:172: error: 'year' was not declared in this scope
Sample of relevant code:
/*
Xantrex GT Inverter Logger with PVoutput.org integration
v0.01d - 08.01.2013
- inital development code
- 0.01c added leading zero for month and day output
- 0.01d removed leading zero for day
This sketch will ultimately use DHCP to obtain an IP address,
get the current time from an NTP server, poll a Xantrex GT inverter
via serial port and log the relevant statistics to PVoutput.org
Circuit:
originally by Isaac Hauser (izy@zooked.com.au)
now by michael ward
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Time.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
//int led = 13; for red LED on board
// set the MAC address for our controller below.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // must be unique on local network
IPAddress timeServer (203, 14, 0, 250); // changed to telstra to fault find no updates since 31.12.2012, was internode
const long timeZoneOffset = +36000L; // time offset in seconds
unsigned int ntpSyncTime = 3600; // how often to sync to NTP server in seconds
// NTP variables, don't modify
unsigned int localPort = 8888;
const int NTP_PACKET_SIZE= 48;
byte packetBuffer[NTP_PACKET_SIZE];
EthernetUDP Udp;
unsigned long ntpLastUpdate = 0;
time_t prevDisplay = 0;
// PVoutput variables, please set your API key and System ID
char serverName[] = "www.pvoutput.org";
char apiKey[] = "2769fa08ce8a84eec1f15"; // insert your own apiKey here
char sid[] = "80"; // insert your own system ID here
unsigned long PVoutputLastUpdate = 0;
unsigned int PVoutputUpdateTime = 300; // how oftern to send updates to PVoutput in seconds
// initialise the Ethernet client library
EthernetClient client;
// initialise our software serial connection
#define rxPin 0
#define txPin 1
SoftwareSerial xantrexSerial(rxPin,txPin);
// set max number of times to try getting a useful value from the inverter
int MAXTRIES = 20;
// SETUP
void setup() {
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
xantrexSerial.begin(9600);
// Serial.begin(9600);
welcomeBanner();
startEthernet();
// pinMode(led, OUTPUT); for LED on board
// try to get and set the date and time
int trys = 0;
while(!getTimeAndDate() && trys < 10) {
trys++;
} if (trys < 10) {
Serial.println("ntp server update success");
} else {
Serial.println("ntp server updated failed");
}
}
// LOOP
void loop() {
// check if time needs to be synced to NTP server
if(now()-ntpLastUpdate >= ntpSyncTime) {
int trys = 0;
while(!getTimeAndDate() && trys < 10){
trys++;
} if(trys < 10) {
Serial.println("ntp server update success");
} else {
Serial.println("ntp server update failed");
}
}
// check if it's time to update PVoutput
if(now()-PVoutputLastUpdate >= PVoutputUpdateTime) {
// if inverter is online, then do pvoutput update, else no update needed
//if (1) {
if (get_status() == 1) {
PVoutputUpdateTime = 300; // if the inverter is online we go back to 300 seconds checks
int trys = 0;
while(!updatePVoutput() && trys < 10) {
trys++;
} if(trys < 10) {
Serial.println("PVoutput update success");
} else {
Serial.println("PVoutput update failed");
}
} else {
Serial.println("Inverter offline, update not required getstatus = 0");
PVoutputUpdateTime = 60; // if the inverter isn't online, we check again in 60 seconds
PVoutputLastUpdate = now();
}
}
// Display the time if it has changed by more than a minute.
if(now()-60 >= prevDisplay) {
//if(now() != prevDisplay) {
prevDisplay = now();
clockDisplay();
}
}
// FUNCTIONS
// display welcome banner
void welcomeBanner() {
Serial.println("Xantrex Logger - v0.1d");
Serial.println("By Michael Ward");
Serial.println();
}
// start ethernet communications
void startEthernet() {
client.stop();
Serial.println("Connecting to network...");
// Connect to network and obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0) {
Serial.println("DHCP Failed, reset Arduino to try again");
// no point in carrying on, so do nothing forevermore
for(;;)
;
} else {
Serial.println("Connected to network using DHCP");
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask: ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway Address: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server Address: ");
Serial.println(Ethernet.dnsServerIP());
Serial.println();
delay(1000);
}
}
// function for sending inverter info to PVoutput.org
int updatePVoutput() {
int flag = 0;
if(client.connect(serverName, 80))
{
client.print("GET /service/r2/addstatus.jsp?key=");
client.print(apiKey);
client.print("&sid=");
client.print(sid);
// send date
client.print("&d=");
client.print(year());
client.print("0");
client.print(month());
// client.print("0");
client.print(day());
// send time
client.print("&t=");
client.print(hour());
client.print(":");
client.print(minute());
}
}