Go Down

Topic: Compiling error: 'bye dns[]' declared as different kind of symbol (Read 4716 times) previous topic - next topic

0bl1vion

Jan 14, 2013, 11:34 pm Last Edit: Jan 14, 2013, 11:36 pm by 0bl1vion Reason: 1
I am trying to build an automated watering system for my lucky bamboo plant. I am playing around with the original source code and have ran into a peculiar error. I have done quite a bit of googling and have come across a few discussions that suggest it may be an IDE related error.
Syntax reads:
Code: [Select]

sketch:51: error: 'byte dns[]' redeclared as different kind of symbol
\arduino-1.0.2-windows\arduino-1.0.2\libraries\Ethernet/Dhcp.h:64: error: previous decleration of '<anonymous enum> dns'

I tried running this code in IDE versions 1.0, 1.0.1, and 1.0.2 - the two earlier versions come out with a different kind of error. I've tried replacing the Ethernet library on 1.0.2 with an earlier version but that did not work. So I am sure there's gotta be something wrong with the code. Any ideas?

Code: [Select]

#include <Ethernet.h>
#include <SPI.h>
#include <aJSON.h>
#include <SimpleTimer.h>

/*

 Pin configuration
*/
int moistureInputPin = 0;
int moistureOutputPinTop = 2;
int moistureOutputPinBottom = 3;
int valveOutputPin = 9;

/*
 How often to check the plant needs watering
 and to send readings to the server
*/
unsigned long pollMillis = 60000; // 1 min


/*
 How dry the soil should get before watering.
 (Max) 1023 = Drier than the Atacama Desert
       400  = Damp
 (Min) 0    = Have you used copper instead of soil?
*/
// Watered value = 75-76

int waterAtMoisture = 1023 - 400;

/*
 When the soil gets dry enough to warrant a watering,
 how many millis to open the valve for.
*/
int waterForMillis = 3500;

/*
 Cube Server IP
*/
byte server[] = { 23, 21, 244, 111 };

/*
 Local IP settings
*/
byte mac[] = { 0x6E, 0x58, 0xB8, 0x2F, 0xF7, 0x89 };
byte ip[] = { 192, 168, 2, 20 };
byte subnet[] = { 255, 255, 255, 0 };
byte gateway[] = { 192, 168, 2, 1 };
byte dns[] = { 8, 8, 8, 8 };

EthernetClient client;
SimpleTimer timer;

void setup() {
 pinMode(moistureOutputPinTop,OUTPUT);
 pinMode(moistureOutputPinBottom,OUTPUT);
 pinMode(valveOutputPin, OUTPUT);

 Serial.begin(9600);

 Ethernet.begin(mac, ip, dns, gateway, subnet);

 Serial.print("My IP address: ");
 Serial.println(Ethernet.localIP());

 timer.setInterval(pollMillis, poll);
}

void loop() {  
 timer.run();
}

/*
 Main function that is run once per poll
*/
void poll() {
 Serial.print("Polling... ");

 //Using int for watered rather than boolean
 //as the cube server doesn't report metrics
 //on booleans very well
 int moisture = getSoilMoisture();
 int watered = 0;

 Serial.println(moisture);

 if(moisture > waterAtMoisture) {
   waterThePlant();
   watered = 1;
 }

 postToServer(moisture, watered);
}

/*
 Drives a current though two digital pins
 and reads the resistance through the
 analogue pin
*/
int getSoilMoisture(){
 //Drive a current through the divider in one direction
 digitalWrite(moistureOutputPinTop,HIGH);
 digitalWrite(moistureOutputPinBottom,LOW);
 delay(1000);

 //Take a reading
 int reading = analogRead(moistureInputPin);

 //Reverse the current
 digitalWrite(moistureOutputPinTop,LOW);
 digitalWrite(moistureOutputPinBottom,HIGH);
 delay(1000);

 //Stop the current
 digitalWrite(moistureOutputPinBottom,LOW);

 return reading;
}

/*
 Gives the plant a two second blast of water
*/
void waterThePlant() {
 digitalWrite(valveOutputPin, HIGH);
 delay(waterForMillis);
 digitalWrite(valveOutputPin, LOW);
}

/*
 Posts a JSON document to the cube server
 (see http://square.github.com/cube/)

 The JSON document describes the soil
 moisture and whether the plant was
 watered.

 [{
   "data": {
     "moisture": 600,
     "watered": 0
   }
 }]

 Using int rather than boolean for 'watered'
 as cube metric querying is limited with booleans
*/
void postToServer(int moisture, int watered) {
 while(!client.connected()) {
   client.stop();
   Serial.println("Connecting...");
   if (client.connect(server, 80)) {
     Serial.println("Connected");
   } else {
     Serial.println("Connection failed");
     delay(5000);
   }
 }

 aJsonObject* rootJson = aJson.createArray();

 aJsonObject* event = aJson.createObject();
 aJson.addItemToArray(rootJson, event);
 aJson.addStringToObject(event, "type", "moisture");
 aJsonObject* data = aJson.createObject();
 aJson.addItemToObject(event, "data", data);
 aJson.addNumberToObject(data, "moisture", moisture);
 aJson.addNumberToObject(data, "watered", watered);

 char* moistureJsonStr = aJson.print(rootJson);

 client.println("POST /1.0/event/put HTTP/1.0");
 client.println("Content-Length: " + String(strlen(moistureJsonStr)));
 client.println("Connection: keep-alive");
 client.println();
 client.println(moistureJsonStr);
}


0bl1vion

I should also mention that I tried changing 'dns' to another name, but the (aJson) library I am using starts generating multiple other errors.

DVDdoug

I would assume dns is delcared already in <Ethernet.h>, and it may not be a type byte.  You should research that and check some examples rather than randomly "hacking" or guessing/assuming.  ;)  

I've forgotten the exact syntax for initializing an already declared array, but you might be able to simply drop "byte" from that statement.  i.e. dns[] = { 8, 8, 8, 8 };


0bl1vion

Thank you for your input!

I am a complete newbie when it comes to programming..so this is pretty difficult at this stage of the game hehe

What do I need to look for to tell if dns is defined in the Ethernet.h file? If I change or remove 'byte,' IDE gives the declaration of array error.



This is my Ethernet.h
Code: [Select]

#ifndef ethernet_h
#define ethernet_h

#include <inttypes.h>
//#include "w5100.h"
#include "IPAddress.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
#include "Dhcp.h"

#define MAX_SOCK_NUM 4

class EthernetClass {
private:
  IPAddress _dnsServerAddress;
  DhcpClass* _dhcp;
public:
  static uint8_t _state[MAX_SOCK_NUM];
  static uint16_t _server_port[MAX_SOCK_NUM];
  // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
  // configuration through DHCP.
  // Returns 0 if the DHCP configuration failed, and 1 if it succeeded
  int begin(uint8_t *mac_address);
  void begin(uint8_t *mac_address, IPAddress local_ip);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
  int maintain();

  IPAddress localIP();
  IPAddress subnetMask();
  IPAddress gatewayIP();
  IPAddress dnsServerIP();

  friend class EthernetClient;
  friend class EthernetServer;
};

extern EthernetClass Ethernet;

#endif

PaulS

Quote
I should also mention that I tried changing 'dns' to another name, but the (aJson) library I am using starts generating multiple other errors.

What other name? What other errors? The name "dns" is local to your sketch. You should be able to change it to anything you want.
The art of getting good answers lies in asking good questions.

Go Up