I'm currently working on Arduino. I'm working for Lamp using Atmega1284. I saw an example code, ModbusIP_ENC28J60 -> Lamp. I first compiled it without adding anything, it compiled properly. Now, I'm adding WebSocketServer, since I want this to work on websocket too. I added few necessary lines, but I ended up with this error:
error: 'EthernetClass Ethernet' redeclared as different kind of symbol
I don't understand what's wrong with the code or what I should change. Can someone help me with this?
I'm pasting my code here for reference:
#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>
#include <WebSocketsServer.h>
WebSocketsServer webSocketServer = WebSocketsServer(8080);
//Modbus Registers Offsets (0-9999)
const int LAMP1_COIL = 100;
//Used Pins
const int ledPin = 9;
//ModbusIP object
ModbusIP mb;
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
switch(type) {
case WStype_DISCONNECTED:
Serial.println("[%u] Disconnected!\n");
break;
case WStype_CONNECTED:
{
//IPAddress ip = webSocket.remoteIP(num);
Serial.println("[%u] Disconnected!\n");
// send message to client
//webSocket.sendTXT(num, "Connected");
}
break;
case WStype_TEXT:
Serial.println("[%u] got text!\n");
// send message to client
// webSocket.sendTXT(num, "message here");
// send data to all connected clients
// webSocket.broadcastTXT("message here");
break;
case WStype_BIN:
Serial.println("[%u] get binary ");
//hexdump(payload, lenght);
// send message to client
// webSocket.sendBIN(num, payload, lenght);
break;
}
}
void setup() {
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address for the shield
byte ip[] = { 192, 168, 0, 120 };
//Config Modbus IP
mb.config(mac, ip);
//Set ledPin mode
pinMode(ledPin, OUTPUT);
// Add LAMP1_COIL register - Use addCoil() for digital outputs
mb.addCoil(LAMP1_COIL);
webSocketServer.begin();
webSocketServer.onEvent(webSocketEvent);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
//Attach ledPin to LAMP1_COIL register
digitalWrite(ledPin, mb.Coil(LAMP1_COIL));
webSocketServer.loop();
}
Help me to make it work.