Arduino + web+ MySql


I’m working on a personal project, basically I’d like to have a web that can get and push data to a MySql database, while the arduino device does the same thing. I’d use the database for store and communication between the web and the device.

I won’t ask how to do that, because that’s my job to do the research and so. The thing is, I am not able to make the ethernet work.
I have an ENC28J60 Ethernet Controller, connected to an arduino mega 2560. I’ve seen some tutorials, connected the ethernet module in the correct arduino mega’s pins.

I’ve tried several libraries, UIPEthernet, ETHER_28j60 and Ethercard. And any example work for me. I don’t have a router, I’m using a switch with ethernet cable from the arduino to the switch, and from the computer to the switch. I’ve set the ip manually on my computer. I’ve set the same network type, subnet mask, dns… and nothing seem to work.

Here is the code, sorry but I don’t know the tool that gives a good looking format of the pasted code on forums.

#include <EtherCard.h>

//VARS_BEGIN => Ethernet
static uint32_t blockReq = 0;
byte Ethernet::buffer[2048];
static uint32_t timer = 0;
static uint32_t timer_lcd;
static byte mymac = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip = {
192,168,2,122 };
static byte gwip = {
192,168,2,1 };
static byte dnsip = {
8,8,8,8 };
//VARS_END => Ethernet

char page PROGMEM =
“HTTP/1.0 503 Service Unavailable\r\n”
“Content-Type: text/html\r\n”
“Retry-After: 600\r\n”
“Service Temporarily Unavailable”

This service is currently unavailable

"The main server is currently off-line.
“Please try again later.”


void setup () {

//INIT_BEGIN Ethernet
if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
Serial.println(“Failed to access Ethernet controller”);
Serial.println(“Ethernet is fine and up”);

Serial.println("\nAfter IF");

// if (!ether.dhcpSetup())
// Serial.println(“DHCP failed”);
ether.staticSetup(myip, gwip, dnsip);
ether.hisip[0] = 192;
ether.hisip[1] = 168;
ether.hisip[2] = 2;
ether.hisip[3] = 1;
//INIT_END Ethernet

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);

I’ve been doing some tests, and when the “if” of the red code es executed, everything seems to stop, it never starts the loop, it doesn’t print the “Serial.println(”\nAfter IF");" order.

I’ll attack a photo of the ethernet module. I’ve been searching about the meaning of the leds but without success, I don’t know if the red light is just the power, or maybe something is wrong.

Any help would be great.


I'm not familiar with the EtherCard library. In that situation I'd look at the implementation of ether::begin() to make sure the arguments being passed are correct, and then review the code to understand what it does and look for places where it might get stuck in an infinite loop. If it isn't obvious from a code review where the problem is, I'd hack the library to print out trace messages to show what code is executing when it stops.

Also, look at the connections used by that card and double check that the corresponding pins on your Arduino have the same function that the card expects - if you're following a wiring diagram for a different model of Arduino it may not be correct for your Mega.

uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, uint8_t csPin) { using_dhcp = false; Stash::initMap(56); copyMac(mymac, macaddr); return initialize(size, mymac, csPin); }

I dont know what is the initMap thing, how could I do prints from a library? I can't compile with serial prints in the library.

I don’t know what the size parameter is for so I can’t tell whether you’re using it correctly.

In order to use Serial.println() in a source file that is not a .ino file, the source file needs to include a declaration for the Serial class. The easiest way to do that is to #include <Arduino.h>.